From 636c0694035e2004a3b91afcb127a675480b6e61 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Sat, 14 Jul 2012 15:00:37 +0200 Subject: [PATCH] _mods/x/locales/y/* now works --- Aquaria/Mod.cpp | 7 +++---- BBGE/Localization.cpp | 21 +++++++++++++++++++++ BBGE/Localization.h | 2 ++ BBGE/SoundManager.cpp | 4 ++-- BBGE/Texture.cpp | 2 +- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Aquaria/Mod.cpp b/Aquaria/Mod.cpp index c715bb3..85a0a91 100644 --- a/Aquaria/Mod.cpp +++ b/Aquaria/Mod.cpp @@ -98,6 +98,8 @@ void Mod::load(const std::string &p) name = p; path = baseModPath + p + "/"; + setLocalisationModPath(path); + setActive(true); TiXmlDocument d; @@ -138,11 +140,7 @@ void Mod::load(const std::string &p) } } -#if defined(BBGE_BUILD_UNIX) dsq->secondaryTexturePath = path + "graphics/"; -#else - dsq->secondaryTexturePath = "./" + path + "graphics/"; -#endif dsq->sound->audioPath2 = path + "audio/"; dsq->sound->setVoicePath2(path + "audio/"); @@ -250,6 +248,7 @@ void Mod::setActive(bool a) { if (!active) { + setLocalisationModPath(""); name = path = ""; dsq->secondaryTexturePath = ""; dsq->sound->audioPath2 = ""; diff --git a/BBGE/Localization.cpp b/BBGE/Localization.cpp index 0833905..e696e6e 100644 --- a/BBGE/Localization.cpp +++ b/BBGE/Localization.cpp @@ -26,6 +26,7 @@ static std::string _CFToStdString(CFStringRef cs) #endif static std::string s_locale; +static std::string s_modpath; void setUsedLocale(const std::string& s) { @@ -37,6 +38,26 @@ const char *getUsedLocale() return s_locale.c_str(); } +void setLocalisationModPath(const std::string& s) +{ + s_modpath = s; + stringToLower(s_modpath); +} + +// hackish +// intended to be used only for paths which are known to start with the mod path, +// but can deal with it if this is not the case +std::string localisePathInternalModpath(const std::string &path) +{ + std::string tmp = path; + stringToLower(tmp); + + if(!strncmp(tmp.c_str(), s_modpath.c_str(), s_modpath.length())) + return localisePath(path, s_modpath); + + return localisePath(path); +} + std::string localisePath(const std::string &path, const std::string& modpath /* = "" */) { if (s_locale.empty()) diff --git a/BBGE/Localization.h b/BBGE/Localization.h index 81adbc1..49df21f 100644 --- a/BBGE/Localization.h +++ b/BBGE/Localization.h @@ -5,7 +5,9 @@ void setUsedLocale(const std::string& s); const char *getUsedLocale(); +void setLocalisationModPath(const std::string& s); std::string localisePath(const std::string &path, const std::string& modpath = ""); +std::string localisePathInternalModpath(const std::string &path); std::string getSystemLocale(); #endif diff --git a/BBGE/SoundManager.cpp b/BBGE/SoundManager.cpp index 43c34d1..d9f5454 100644 --- a/BBGE/SoundManager.cpp +++ b/BBGE/SoundManager.cpp @@ -927,7 +927,7 @@ bool SoundManager::playVoice(const std::string &name, SoundVoiceType svt, float if (!voicePath2.empty()) { fn = voicePath2 + name + fileType; - fn = localisePath(fn); + fn = localisePathInternalModpath(fn); fn = core->adjustFilenameCase(fn); if (exists(fn)) checkOther = false; } @@ -1524,7 +1524,7 @@ Buffer SoundManager::loadSoundIntoBank(const std::string &filename, const std::s if (slt == SFXLOAD_LOCAL && !audioPath2.empty()) { f = audioPath2 + filename + format; - f = localisePath(f); + f = localisePathInternalModpath(f); f = core->adjustFilenameCase(f); if (!exists(f)) { diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index df609ec..a15e69c 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -318,7 +318,7 @@ void Texture::load(std::string file) if (found) { - file = localisePath(file); + file = localisePathInternalModpath(file); file = core->adjustFilenameCase(file); /*