#include "../headers/AudioManager.h"
#include <iostream>

//Dodalem dla zabawy audio tez jako potencjalny dodatek, jbc mozna wywalic

bool AudioManager::loadBackgroundMusic(const std::string& filePath) {
    if (!backgroundMusic.openFromFile(filePath)) {
        std::cerr << "Muzyka tla sie nie zaladowala!!! " << filePath << "\n";
        return false;
    }

    return true;
}

void AudioManager::playBackgroundMusic(float volume, bool loop) {
    backgroundMusic.setVolume(volume);
    backgroundMusic.setLoop(loop);
    backgroundMusic.play();
}

void AudioManager::stopBackgroundMusic() {
    backgroundMusic.stop();
}

bool AudioManager::loadSoundEffect(const std::string& name, const std::string& filePath) {
    sf::SoundBuffer buffer;
    if (!buffer.loadFromFile(filePath)) {
        std::cerr << "Plik z efektem sie nie zaladowal " << filePath << "\n";
        return false;
    }
  //  std::cout << "Zaladowano " << name << " z " << filePath << "\n";
    soundBuffers[name] = buffer;
    sounds[name].setBuffer(soundBuffers[name]);
    return true;
}

void AudioManager::playSoundEffect(const std::string& name, float volume) {
    if (sounds.find(name) != sounds.end()) {
        sounds[name].setVolume(volume);
        sounds[name].play();
    } else {
        std::cerr << "Pliku z efektem " << name << " nie znaleziono!\n";
    }
}
