#include "audio.h" Audio::Audio(const std::string &background_path, std::array &&sounds_paths) { std::unique_ptr music = std::make_unique(); if (music->openFromFile(background_path)) music->setLoop(true); else music = nullptr; background_music = std::move(music); std::unique_ptr effect; for (int i = 0; i < N_SOUNDS; ++i) { effect = std::make_unique(); if (effect->buffer.loadFromFile(sounds_paths[i])) { effect->sound.setBuffer(effect->buffer); array_sounds[i] = std::move(effect); } else { array_sounds[i] = nullptr; } } } bool Audio::setSound(const SOUND_TYPE &type, const std::string &sound_file_path) { std::unique_ptr effect = std::make_unique(); if (!effect->buffer.loadFromFile(sound_file_path)) return false; effect->sound.setBuffer(effect->buffer); array_sounds[type] = std::move(effect); return true; } void Audio::playSound(const SOUND_TYPE &type) { if (array_sounds[type]) array_sounds[type]->sound.play(); } bool Audio::setBackground(const std::string &music_file_path) { std::unique_ptr music = std::make_unique(); if (!music->openFromFile(music_file_path)) return false; background_music = std::move(music); return true; } void Audio::playBackground() { if (background_music) background_music->play(); } void Audio::stopBackground() { if (background_music) background_music->stop(); } void Audio::pauseBackground() { if (background_music) background_music->pause(); } void Audio::setBackgroundVolume(const float &volume) { if (background_music) background_music->setVolume(volume); }