From d190f97a45e9484c73573741775de0956cd663b2 Mon Sep 17 00:00:00 2001 From: chimort Date: Tue, 19 Mar 2024 17:09:51 +0300 Subject: [PATCH] make code better --- res/{sound => sounds}/chime.wav | Bin res/{sound => sounds}/walking-sound.wav | Bin src/gui_controller/game/states/cell_movement.h | 4 ++-- src/sound_manager/sound_manager.h | 9 ++++----- src/static_data/game_config.h | 1 + 5 files changed, 7 insertions(+), 7 deletions(-) rename res/{sound => sounds}/chime.wav (100%) rename res/{sound => sounds}/walking-sound.wav (100%) diff --git a/res/sound/chime.wav b/res/sounds/chime.wav similarity index 100% rename from res/sound/chime.wav rename to res/sounds/chime.wav diff --git a/res/sound/walking-sound.wav b/res/sounds/walking-sound.wav similarity index 100% rename from res/sound/walking-sound.wav rename to res/sounds/walking-sound.wav diff --git a/src/gui_controller/game/states/cell_movement.h b/src/gui_controller/game/states/cell_movement.h index e1239017..76c7bf7f 100644 --- a/src/gui_controller/game/states/cell_movement.h +++ b/src/gui_controller/game/states/cell_movement.h @@ -76,7 +76,7 @@ class CellMovement : public GameState { d->setNextCell(d->getPrevOnPath().lock()); gm->changeState(GUIGameState::kMoveTransition); } - sound::playSound("res/sound/walking-sound.wav", 80); + sound::playSound("walking-sound", 80); return; } @@ -89,7 +89,7 @@ class CellMovement : public GameState { } else if (clicked_left && !neighbours[3].expired()) { r_selected = 3; } else if (clicked_enter) { - sound::playSound("res/sound/chime.wav"); + sound::playSound("chime"); d->setNextCell(d->getNextOnPath().lock()); gm->changeState(GUIGameState::kMoveTransition); } diff --git a/src/sound_manager/sound_manager.h b/src/sound_manager/sound_manager.h index 8d60700c..c28b9c95 100644 --- a/src/sound_manager/sound_manager.h +++ b/src/sound_manager/sound_manager.h @@ -9,11 +9,10 @@ class SoundManager { static SoundManager instance; return instance; } - void playSound(const std::string& sound_path, const float volume) { + void playSound(const std::string& sound_name, const float volume) { sound_buffer = std::make_unique(); sound = std::make_unique(); - - if (sound_buffer->loadFromFile(sound_path)) { + if (sound_buffer->loadFromFile(cfg::SOUNDS_PATH + sound_name + ".wav")) { sound->setBuffer(*sound_buffer); sound->setVolume(volume); sound->play(); @@ -26,7 +25,7 @@ class SoundManager { std::unique_ptr sound; }; -static void playSound(const std::string& sound_path, float volume = 100.f) { - sound::SoundManager::getInstance().playSound(sound_path, volume); +static void playSound(const std::string& sound_name, float volume = 100.f) { + sound::SoundManager::getInstance().playSound(sound_name, volume); } } diff --git a/src/static_data/game_config.h b/src/static_data/game_config.h index 45f7bf5a..2bf42760 100644 --- a/src/static_data/game_config.h +++ b/src/static_data/game_config.h @@ -11,6 +11,7 @@ const unsigned CELL_SIZE = 20; const std::string WINDOW_NAME = "*EPIC DUNGEONS*"; const std::string FONTS_PATH = "res/fonts/"; const std::string SPRITES_PATH = "res/sprites/"; +const std::string SOUNDS_PATH = "res/sounds/"; const keyboard::Key CONTROLS_MOVE_RIGHT = keyboard::Key::KEY_RIGHT; const keyboard::Key CONTROLS_MOVE_DOWN = keyboard::Key::KEY_DOWN;