From 72480bc57610069f572291f34680bba9cb15a341 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 28 May 2013 02:54:23 +0000 Subject: [PATCH] added ability to reference sound and videos in lua using variables: {TECHTREEPATH}, {SCENARIOPATH}, {TUTORIALPATH} example: playStreamingSound('{SCENARIOPATH}/music/myambient.ogg') --- source/glest_game/types/tech_tree.cpp | 3 + source/glest_game/world/scenario.cpp | 18 ++++++ source/glest_game/world/world.cpp | 56 +++++++++++++------ source/shared_lib/include/util/properties.h | 11 ++++ source/shared_lib/sources/util/properties.cpp | 24 ++++++++ 5 files changed, 96 insertions(+), 16 deletions(-) diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 3f48d0e4..d84b7625 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -140,6 +140,9 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(currentPath,currentPath)); + Properties::setTechtreePath(currentPath); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("==> Set techtree path to [%s]\n",currentPath.c_str()); + const XmlNode *techTreeNode= xmlTree.getRootNode(); //attack types diff --git a/source/glest_game/world/scenario.cpp b/source/glest_game/world/scenario.cpp index 7d7f2a0d..206fc051 100644 --- a/source/glest_game/world/scenario.cpp +++ b/source/glest_game/world/scenario.cpp @@ -55,6 +55,24 @@ Checksum Scenario::load(const string &path) { Logger::getInstance().add(szBuf, true); bool isTutorial = Scenario::isGameTutorial(path); + + //Properties::setTechtreePath(); + + string scenarioFolder = cutLastFile(formatPath(path)); + scenarioFolder = cutLastFile(scenarioFolder); + endPathWithSlash(scenarioFolder); + + if(isTutorial == false) { + Properties::setScenarioPath(scenarioFolder); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("==> Set scenario path to [%s]\n",scenarioFolder.c_str()); + } + else { + Properties::setTutorialPath(scenarioFolder); + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("==> Set tutorial path to [%s]\n",scenarioFolder.c_str()); + } + Scenario::loadScenarioInfo(path, &info, isTutorial); //parse xml diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index b26844de..dcfc7bb6 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1496,38 +1496,50 @@ void World::giveAttackStoppedCommand(int unitId, const string &itemName, bool ig void World::playStaticSound(const string &playSound) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",__FILE__,__FUNCTION__,__LINE__,playSound.c_str()); - SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + string calculatedFilePath = playSound; + bool changed = Properties::applyTagsToValue(calculatedFilePath); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nPlay static sound changed: %d [%s] [%s]\n\n",changed, playSound.c_str(),calculatedFilePath.c_str()); - if(staticSoundList.find(playSound) == staticSoundList.end()) { + if(staticSoundList.find(calculatedFilePath) == staticSoundList.end()) { StaticSound *sound = new StaticSound(); - sound->load(playSound); - staticSoundList[playSound] = sound; + sound->load(calculatedFilePath); + staticSoundList[calculatedFilePath] = sound; } - StaticSound *playSoundItem = staticSoundList[playSound]; + StaticSound *playSoundItem = staticSoundList[calculatedFilePath]; + + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); soundRenderer.playFx(playSoundItem); } void World::playStreamingSound(const string &playSound) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",__FILE__,__FUNCTION__,__LINE__,playSound.c_str()); - SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + string calculatedFilePath = playSound; + bool changed = Properties::applyTagsToValue(calculatedFilePath); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nPlay streaming sound changed: %d [%s] [%s]\n\n",changed, playSound.c_str(),calculatedFilePath.c_str()); - if(streamSoundList.find(playSound) == streamSoundList.end()) { + if(streamSoundList.find(calculatedFilePath) == streamSoundList.end()) { StrSound *sound = new StrSound(); - sound->open(playSound); + sound->open(calculatedFilePath); sound->setNext(sound); - streamSoundList[playSound] = sound; + streamSoundList[calculatedFilePath] = sound; } - StrSound *playSoundItem = streamSoundList[playSound]; + StrSound *playSoundItem = streamSoundList[calculatedFilePath]; + + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); soundRenderer.playMusic(playSoundItem); } void World::stopStreamingSound(const string &playSound) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] playSound [%s]\n",__FILE__,__FUNCTION__,__LINE__,playSound.c_str()); - SoundRenderer &soundRenderer= SoundRenderer::getInstance(); - if(streamSoundList.find(playSound) != streamSoundList.end()) { - StrSound *playSoundItem = streamSoundList[playSound]; + string calculatedFilePath = playSound; + bool changed = Properties::applyTagsToValue(calculatedFilePath); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nStop streaming sound changed: %d [%s] [%s]\n\n",changed, playSound.c_str(),calculatedFilePath.c_str()); + + if(streamSoundList.find(calculatedFilePath) != streamSoundList.end()) { + StrSound *playSoundItem = streamSoundList[calculatedFilePath]; + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); soundRenderer.stopMusic(playSoundItem); } } @@ -2545,15 +2557,27 @@ int World::getNextCommandGroupId() { } void World::playStaticVideo(const string &playVideo) { - this->game->playStaticVideo(playVideo); + string calculatedFilePath = playVideo; + bool changed = Properties::applyTagsToValue(calculatedFilePath); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nPlay static video changed: %d [%s] [%s]\n\n",changed, playVideo.c_str(),calculatedFilePath.c_str()); + + this->game->playStaticVideo(calculatedFilePath); } void World::playStreamingVideo(const string &playVideo) { - this->game->playStreamingVideo(playVideo); + string calculatedFilePath = playVideo; + bool changed = Properties::applyTagsToValue(calculatedFilePath); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nPlay streaming video changed: %d [%s] [%s]\n\n",changed, playVideo.c_str(),calculatedFilePath.c_str()); + + this->game->playStreamingVideo(calculatedFilePath); } void World::stopStreamingVideo(const string &playVideo) { - this->game->stopStreamingVideo(playVideo); + string calculatedFilePath = playVideo; + bool changed = Properties::applyTagsToValue(calculatedFilePath); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n\nStop streaming video changed: %d [%s] [%s]\n\n",changed, playVideo.c_str(),calculatedFilePath.c_str()); + + this->game->stopStreamingVideo(calculatedFilePath); } void World::stopAllVideo() { diff --git a/source/shared_lib/include/util/properties.h b/source/shared_lib/include/util/properties.h index 90035f45..51d5358b 100644 --- a/source/shared_lib/include/util/properties.h +++ b/source/shared_lib/include/util/properties.h @@ -49,6 +49,10 @@ private: static string applicationPath; static string gameVersion; + static string techtreePath; + static string scenarioPath; + static string tutorialPath; + public: static void setApplicationPath(string value) { applicationPath=value; } static string getApplicationPath() { return applicationPath; } @@ -56,6 +60,13 @@ public: static void setGameVersion(string value) { gameVersion=value; } static string getGameVersion() { return gameVersion; } + static void setTechtreePath(string value) { techtreePath=value; } + static string getTechtreePath() { return techtreePath; } + static void setScenarioPath(string value) { scenarioPath=value; } + static string getScenarioPath() { return scenarioPath; } + static void setTutorialPath(string value) { tutorialPath=value; } + static string getTutorialPath() { return tutorialPath; } + void clear(); void load(const string &path,bool clearCurrentProperties=true); void save(const string &path); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 9a315620..e067892d 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -43,6 +43,10 @@ namespace Shared{ namespace Util{ string Properties::applicationPath = ""; string Properties::gameVersion = ""; +string Properties::techtreePath = ""; +string Properties::scenarioPath = ""; +string Properties::tutorialPath = ""; + // ===================================================== // class Properties // ===================================================== @@ -232,6 +236,10 @@ std::map Properties::getTagReplacementValues(std::map * if(mapTagReplacementValues != NULL) { for(std::map::const_iterator iterMap = mapTagReplacementValues->begin(); iterMap != mapTagReplacementValues->end(); ++iterMap) { + +// if(value.find("{SCENARIOPATH}") != string::npos) { +// printf("\n\n** WILL REPLACE [%s]\n",value.c_str()); +// replaceAll(value, "{SCENARIOPATH}", Properties::scenarioPath); +// printf("** REPLACED [%s]\n\n",value.c_str()); +// } +// else { replaceAll(value, iterMap->first, iterMap->second); +// } } } else { @@ -319,6 +335,14 @@ bool Properties::applyTagsToValue(string &value, const std::map * #endif + replaceAll(value, "{TECHTREEPATH}", Properties::techtreePath); +// if(value.find("{SCENARIOPATH}") != string::npos) { +// printf("\n\n** WILL REPLACE [%s]\n",value.c_str()); + replaceAll(value, "{SCENARIOPATH}", Properties::scenarioPath); +// printf("** REPLACED [%s]\n\n",value.c_str()); +// } + replaceAll(value, "{TUTORIALPATH}", Properties::tutorialPath); + replaceAll(value, "$GAMEVERSION", Properties::gameVersion); }