mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2024-11-15 11:33:24 +01:00
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
//
|
|
// Created by Syméon on 24/03/2019.
|
|
//
|
|
|
|
#include <imgui/imgui.h>
|
|
#include "SoundEffect.h"
|
|
#include "Toolbox.h"
|
|
|
|
SoundEffect::SoundEffect(std::string filename): buffer(), volume(10), shouldPlay(false) {
|
|
|
|
auto soundPath = std::filesystem::path("assets/sounds") / filename;
|
|
|
|
if (!buffer.loadFromFile(soundPath.string())) {
|
|
std::cerr << "Unable to load sound : " << filename;
|
|
throw std::runtime_error("Unable to load sound : " + filename);
|
|
}
|
|
|
|
sound = sf::Sound(buffer);
|
|
}
|
|
|
|
void SoundEffect::play() {
|
|
sound.play();
|
|
}
|
|
|
|
void SoundEffect::setVolume(int newVolume) {
|
|
volume = std::clamp(newVolume,0,10);
|
|
Toolbox::updateVolume(sound,volume);
|
|
}
|
|
|
|
int SoundEffect::getVolume() const {
|
|
return volume;
|
|
}
|
|
|
|
void SoundEffect::displayControls() {
|
|
ImGui::PushID(&shouldPlay);
|
|
ImGui::Checkbox("Toggle",&shouldPlay); ImGui::SameLine();
|
|
ImGui::PopID();
|
|
|
|
ImGui::PushID(&volume);
|
|
if (ImGui::SliderInt("Volume",&volume,0,10)) {
|
|
setVolume(volume);
|
|
}
|
|
ImGui::PopID();
|
|
}
|