added ability to reference sound and videos in lua using variables: {TECHTREEPATH}, {SCENARIOPATH}, {TUTORIALPATH} example:

playStreamingSound('{SCENARIOPATH}/music/myambient.ogg')
This commit is contained in:
Mark Vejvoda 2013-05-28 02:54:23 +00:00
parent 7ee5d2b300
commit 72480bc576
5 changed files with 96 additions and 16 deletions

View File

@ -140,6 +140,9 @@ void TechTree::load(const string &dir, set<string> &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

View File

@ -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

View File

@ -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() {

View File

@ -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);

View File

@ -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<string,string> Properties::getTagReplacementValues(std::map<string,stri
#endif
mapTagReplacementValues["{TECHTREEPATH}"] = Properties::techtreePath;
mapTagReplacementValues["{SCENARIOPATH}"] = Properties::scenarioPath;
mapTagReplacementValues["{TUTORIALPATH}"] = Properties::tutorialPath;
mapTagReplacementValues["$GAMEVERSION"] = Properties::gameVersion;
//
@ -258,7 +266,15 @@ bool Properties::applyTagsToValue(string &value, const std::map<string,string> *
if(mapTagReplacementValues != NULL) {
for(std::map<string,string>::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<string,string> *
#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);
}