From c0006da18ac61537c7cbde8e54d6818fa62de74f Mon Sep 17 00:00:00 2001 From: andy5995 Date: Wed, 21 Feb 2018 09:10:15 -0600 Subject: [PATCH] core_data.cpp: add function to play sounds This function can be used to pass different arguments to it, so the other play sfx functions (below it) can be removed. (#63) --- source/glest_game/global/core_data.cpp | 26 ++++++++++++++++++++++++++ source/glest_game/global/core_data.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 9e21538b6..62e70fbcf 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -722,6 +722,32 @@ namespace Glest return &clickSoundC; } + + StaticSound *CoreData::getSound (const std::string& iniPlaySoundVal) + { + int loadAttemptLookupKey = tsyst_COUNT + 6; + if (itemLoadAttempted.find (loadAttemptLookupKey) == + itemLoadAttempted.end ()) + { + + itemLoadAttempted[loadAttemptLookupKey] = true; + + try + { + static Config & config = Config::getInstance (); + iniPlaySound.load (config.getString (iniPlaySoundVal, "")); + } + catch (const megaglest_runtime_error & ex) + { + message (ex.what (), + GlobalStaticFlags::getIsNonGraphicalModeEnabled (), + tempDataLocation); + } + } + + return &iniPlaySound; + } + StaticSound *CoreData::getAttentionSound () { int loadAttemptLookupKey = tsyst_COUNT + 6; diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index d96ce880b..65eb729c6 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -66,6 +66,7 @@ namespace Glest StaticSound clickSoundA; StaticSound clickSoundB; StaticSound clickSoundC; + StaticSound iniPlaySound; StaticSound attentionSound; StaticSound newServerSound; StaticSound highlightSound; @@ -212,6 +213,7 @@ namespace Glest StaticSound *getClickSoundA (); StaticSound *getClickSoundB (); StaticSound *getClickSoundC (); + StaticSound *getSound (const std::string& iniPlaySoundVal); StaticSound *getAttentionSound (); StaticSound *getNewServerSound (); StaticSound *getHighlightSound ();