From af5c31d5d094b02afde469cfc7150405e0207e2c Mon Sep 17 00:00:00 2001 From: Modnark <66146584+Modnark@users.noreply.github.com> Date: Tue, 11 Oct 2022 21:28:19 -0400 Subject: [PATCH] Add dynamic_cast for playSound makes it so developers don't need to dynamic_cast any time they want to play sound --- src/include/DataModelV2/SoundService.h | 2 +- src/source/DataModelV2/PartInstance.cpp | 4 ++-- src/source/DataModelV2/SoundService.cpp | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/include/DataModelV2/SoundService.h b/src/include/DataModelV2/SoundService.h index 62b1ae5..9063438 100644 --- a/src/include/DataModelV2/SoundService.h +++ b/src/include/DataModelV2/SoundService.h @@ -10,7 +10,7 @@ public: ~SoundService(void); float getMusicVolume(); - void playSound(SoundInstance* sound); + void playSound(Instance* sound); private: float musicVolume; }; diff --git a/src/source/DataModelV2/PartInstance.cpp b/src/source/DataModelV2/PartInstance.cpp index a38bbec..8fb5837 100644 --- a/src/source/DataModelV2/PartInstance.cpp +++ b/src/source/DataModelV2/PartInstance.cpp @@ -525,10 +525,10 @@ void PartInstance::onTouch() case Enum::Sound::NoSound: break; case Enum::Sound::Victory: - sndService->playSound(dynamic_cast(sndService->findFirstChild("Victory"))); + sndService->playSound(sndService->findFirstChild("Victory")); break; case Enum::Sound::Boing: - sndService->playSound(dynamic_cast(sndService->findFirstChild("Boing"))); + sndService->playSound(sndService->findFirstChild("Boing")); break; } } diff --git a/src/source/DataModelV2/SoundService.cpp b/src/source/DataModelV2/SoundService.cpp index 17c9ffd..46662d4 100644 --- a/src/source/DataModelV2/SoundService.cpp +++ b/src/source/DataModelV2/SoundService.cpp @@ -71,10 +71,15 @@ SoundService::~SoundService(void) { } -void SoundService::playSound(SoundInstance* sound) +void SoundService::playSound(Instance* sound) { - std::string soundId = sound->getSoundId(); - AudioPlayer::playSound(GetFileInPath(soundId)); + // Try to dynamic_cast it to SoundInstance + SoundInstance* sndInst = dynamic_cast(sound); + if(sndInst != NULL) + { + std::string soundId = sndInst->getSoundId(); + AudioPlayer::playSound(GetFileInPath(soundId)); + } } float SoundService::getMusicVolume()