diff --git a/sources/Component/Music/MusicComponent.cpp b/sources/Component/Music/MusicComponent.cpp index e1aaca5e..339e040d 100644 --- a/sources/Component/Music/MusicComponent.cpp +++ b/sources/Component/Music/MusicComponent.cpp @@ -7,20 +7,16 @@ namespace BBM { - MusicComponent::MusicComponent(WAL::Entity &entity, std::string &musicPath) + MusicComponent::MusicComponent(WAL::Entity &entity, const std::string &musicPath) : WAL::Component(entity), + _musicPath(musicPath), _music(RAY::Audio::Music(musicPath)) { } - MusicComponent::MusicComponent(WAL::Entity &entity) - : Component(entity), - _music() - {} - WAL::Component *MusicComponent::clone(WAL::Entity &entity) const { - return new MusicComponent(entity); + return new MusicComponent(entity, this->_musicPath); } void MusicComponent::loadMusic(void) diff --git a/sources/Component/Music/MusicComponent.hpp b/sources/Component/Music/MusicComponent.hpp index 132179f2..835a8e5c 100644 --- a/sources/Component/Music/MusicComponent.hpp +++ b/sources/Component/Music/MusicComponent.hpp @@ -35,20 +35,19 @@ namespace BBM //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; //! @brief Create a new MusicComponent at a certain Music - MusicComponent(WAL::Entity &entity, std::string &musicPath); + explicit MusicComponent(WAL::Entity &entity, const std::string &musicPath); //! @brief A Music component is copy constructable MusicComponent(const MusicComponent &) = default; //! @brief A default destructor ~MusicComponent() override = default; //! @brief A Music component is not assignable MusicComponent &operator=(const MusicComponent &) = delete; + private: //! @brief music of this entity RAY::Audio::Music _music; - //! @brief Create a new MusicComponent linked to a specific entity - explicit MusicComponent(WAL::Entity &entity); - - + //! @brief patht to the music assets + const std::string _musicPath; }; } // namespace BBM \ No newline at end of file diff --git a/sources/Component/Sound/SoundComponent.cpp b/sources/Component/Sound/SoundComponent.cpp index d4ab53b1..3265d724 100644 --- a/sources/Component/Sound/SoundComponent.cpp +++ b/sources/Component/Sound/SoundComponent.cpp @@ -19,7 +19,7 @@ std::map &soundPath) this->_isLoad[static_cast(i)] = false; } else { this->_isLoad[static_cast(i)] = true; - this->_soundList[static_cast(i)] = std::unique_ptr(new RAY::Audio::Sound(soundPath.at(static_cast(i)))); + this->_soundList[static_cast(i)] = std::make_unique(soundPath.at(static_cast(i))); } } } @@ -35,7 +35,7 @@ std::map &soundPath) return new SoundComponent(entity); } - void SoundComponent::playSound(void) + void SoundComponent::playSound() { if (!this->_isLoad.at(this->_soundIndex)) return; @@ -43,7 +43,7 @@ std::map &soundPath) this->_soundList[this->_soundIndex].get()->play(); } - void SoundComponent::stopSound(void) + void SoundComponent::stopSound() { if (!this->_isLoad.at(this->_soundIndex)) return; @@ -51,7 +51,7 @@ std::map &soundPath) this->_soundList[this->_soundIndex].get()->stop(); } - void SoundComponent::pauseSound(void) + void SoundComponent::pauseSound() { if (!this->_isLoad.at(this->_soundIndex)) return; @@ -73,7 +73,7 @@ std::map &soundPath) this->_soundList[this->_soundIndex].get()->setPitch(pitch); } - bool SoundComponent::isPlaying(void) + bool SoundComponent::isPlaying() { if (!this->_isLoad.at(this->_soundIndex)) return (false); @@ -85,7 +85,7 @@ std::map &soundPath) this->_soundIndex = index; } - SoundComponent::soundIndex SoundComponent::getIndex(void) + SoundComponent::soundIndex SoundComponent::getIndex() { return (this->_soundIndex); } diff --git a/sources/Component/Sound/SoundComponent.hpp b/sources/Component/Sound/SoundComponent.hpp index e4b7ed5e..6c35d197 100644 --- a/sources/Component/Sound/SoundComponent.hpp +++ b/sources/Component/Sound/SoundComponent.hpp @@ -45,7 +45,7 @@ namespace BBM void setPitch(float &); //! @brief is Sound playing - bool isPlaying(void); + bool isPlaying(); //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/System/Sound/PlayerSoundManagerSystem.cpp b/sources/System/Sound/PlayerSoundManagerSystem.cpp index 187f55e3..6b50f31f 100644 --- a/sources/System/Sound/PlayerSoundManagerSystem.cpp +++ b/sources/System/Sound/PlayerSoundManagerSystem.cpp @@ -3,33 +3,30 @@ // #include "PlayerSoundManagerSystem.hpp" +#include namespace BBM { - - SoundManagerSystem::SoundManagerSystem() - : WAL::System({ - typeid(SoundComponent), - typeid(HealthComponent) - }) + SoundManagerSystem::SoundManagerSystem(WAL::Wal &wal) + : System(wal) {} - void SoundManagerSystem::onFixedUpdate(WAL::Entity &entity) - { - if (!entity.hasComponent()) - return; - const auto &controllable = entity.getComponent(); - auto &sound = entity.getComponent(); - auto &health = entity.getComponent(); + void SoundManagerSystem::onFixedUpdate(WAL::ViewEntity &entity) + { + const auto &controllable = entity.get(); + auto &sound = entity.get(); + auto &health = entity.get(); - sound.setIndex(SoundComponent::BOMB); - if (controllable.bomb) - sound.playSound(); - sound.setIndex(SoundComponent::JUMP); - if (controllable.jump) - sound.playSound(); - sound.setIndex(SoundComponent::MOVE); - if (controllable.move.x != 0 || controllable.move.y != 0) - sound.playSound(); - } + std::map soundIndex = { + {controllable.bomb, SoundComponent::BOMB}, + {controllable.jump, SoundComponent::JUMP}, + {controllable.move.x != 0 || controllable.move.y != 0, SoundComponent::MOVE} + }; + for (auto &a : soundIndex) { + if (a.first) { + sound.setIndex(a.second); + sound.playSound(); + } + } + } } \ No newline at end of file diff --git a/sources/System/Sound/PlayerSoundManagerSystem.hpp b/sources/System/Sound/PlayerSoundManagerSystem.hpp index 38cd4bfa..2f1967ff 100644 --- a/sources/System/Sound/PlayerSoundManagerSystem.hpp +++ b/sources/System/Sound/PlayerSoundManagerSystem.hpp @@ -13,14 +13,14 @@ namespace BBM { - class SoundManagerSystem : public WAL::System + class SoundManagerSystem : public WAL::System { public: //! @inherit - void onFixedUpdate(WAL::Entity &entity) override; + void onFixedUpdate(WAL::ViewEntity &entity) override; //! @brief ctor - SoundManagerSystem(); + SoundManagerSystem(WAL::Wal &wal); //! @brief Default copy ctor SoundManagerSystem(const SoundManagerSystem &) = default; //! @brief Default dtor