diff --git a/targets/app/common/DLC/DLCLocalisationFile.cpp b/targets/app/common/DLC/DLCLocalisationFile.cpp index 2a66aaafd..343faad53 100644 --- a/targets/app/common/DLC/DLCLocalisationFile.cpp +++ b/targets/app/common/DLC/DLCLocalisationFile.cpp @@ -2,6 +2,7 @@ #include "DLCManager.h" #include "app/common/DLC/DLCFile.h" +#include "app/linux/LinuxGame.h" #include "minecraft/locale/StringTable.h" DLCLocalisationFile::DLCLocalisationFile(const std::string& path) @@ -11,5 +12,7 @@ DLCLocalisationFile::DLCLocalisationFile(const std::string& path) void DLCLocalisationFile::addData(std::uint8_t* pbData, std::uint32_t dataBytes) { - m_strings = new StringTable(pbData, dataBytes); + std::vector locales; + app.getLocale(locales); + m_strings = new StringTable(pbData, dataBytes, locales); } diff --git a/targets/app/common/DLC/DLCPack.cpp b/targets/app/common/DLC/DLCPack.cpp index d0f78b64d..20bef9ed6 100644 --- a/targets/app/common/DLC/DLCPack.cpp +++ b/targets/app/common/DLC/DLCPack.cpp @@ -351,6 +351,8 @@ void DLCPack::UpdateLanguage() { DLCLocalisationFile* localisationFile = (DLCLocalisationFile*)getFile( DLCManager::e_DLCType_LocalisationData, "languages.loc"); StringTable* strTable = localisationFile->getStringTable(); - strTable->ReloadStringTable(); + std::vector locales; + app.getLocale(locales); + strTable->ReloadStringTable(locales); } } diff --git a/targets/app/common/GameRules/GameRuleManager.cpp b/targets/app/common/GameRules/GameRuleManager.cpp index af49ff1c6..39fb980e0 100644 --- a/targets/app/common/GameRules/GameRuleManager.cpp +++ b/targets/app/common/GameRules/GameRuleManager.cpp @@ -223,8 +223,10 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn, unsigned int bStringTableSize = dis2.readInt(); std::vector bStringTable(bStringTableSize); dis2.read(bStringTable); + std::vector locales; + app.getLocale(locales); StringTable* strings = - new StringTable(bStringTable.data(), bStringTable.size()); + new StringTable(bStringTable.data(), bStringTable.size(), locales); // Read RuleFile. std::vector bRuleFile(content.size() - bStringTable.size()); diff --git a/targets/app/common/LocalizationManager.cpp b/targets/app/common/LocalizationManager.cpp index 1e78ed248..7048b8fc1 100644 --- a/targets/app/common/LocalizationManager.cpp +++ b/targets/app/common/LocalizationManager.cpp @@ -77,7 +77,10 @@ void LocalizationManager::loadStringTable(ArchiveFile* mediaArchive) { std::string localisationFile = "languages.loc"; if (mediaArchive->hasFile(localisationFile)) { std::vector locFile = mediaArchive->getFile(localisationFile); - m_stringTable = new StringTable(locFile.data(), locFile.size()); + std::vector locales; + getLocale(locales); + m_stringTable = + new StringTable(locFile.data(), locFile.size(), locales); } else { m_stringTable = nullptr; assert(false); diff --git a/targets/app/common/UI/Scenes/Frontend Menu screens/IUIScene_StartGame.cpp b/targets/app/common/UI/Scenes/Frontend Menu screens/IUIScene_StartGame.cpp index b1d4ad79d..499e9ca4a 100644 --- a/targets/app/common/UI/Scenes/Frontend Menu screens/IUIScene_StartGame.cpp +++ b/targets/app/common/UI/Scenes/Frontend Menu screens/IUIScene_StartGame.cpp @@ -145,8 +145,10 @@ void IUIScene_StartGame::UpdateTexturePackDescription(int index) { app.GetFileFromTPD(eTPDFileType_Loc, pbData, dwBytes, &pbFileData, &dwFileBytes); if (dwFileBytes > 0 && pbFileData) { + std::vector locales; + app.getLocale(locales); StringTable* pStringTable = - new StringTable(pbFileData, dwFileBytes); + new StringTable(pbFileData, dwFileBytes, locales); m_texturePackTitle.SetText( pStringTable->getString("IDS_DISPLAY_NAME")); m_texturePackDescription.SetText( diff --git a/targets/app/common_sources.txt b/targets/app/common_sources.txt index c16c39958..cab1ba816 100644 --- a/targets/app/common_sources.txt +++ b/targets/app/common_sources.txt @@ -49,7 +49,6 @@ common/GameSettingsManager.cpp common/Game_XuiActions.cpp common/Leaderboards/LeaderboardInterface.cpp common/Leaderboards/LeaderboardManager.cpp -common/Localisation/StringTable.cpp common/LocalizationManager.cpp common/MenuController.cpp common/Network/GameNetworkManager.cpp diff --git a/targets/app/common/Localisation/StringTable.cpp b/targets/minecraft/locale/StringTable.cpp similarity index 80% rename from targets/app/common/Localisation/StringTable.cpp rename to targets/minecraft/locale/StringTable.cpp index 90789035f..e19c49d63 100644 --- a/targets/app/common/Localisation/StringTable.cpp +++ b/targets/minecraft/locale/StringTable.cpp @@ -3,28 +3,32 @@ #include #include -#include "app/linux/LinuxGame.h" #include "java/InputOutputStream/ByteArrayInputStream.h" #include "java/InputOutputStream/DataInputStream.h" +#include "minecraft/util/Log.h" StringTable::StringTable(void) {} // Load string table from a binary blob, filling out with the current -// localisation data only -StringTable::StringTable(std::uint8_t* pbData, unsigned int dataSize) { +// localisation data only. The caller passes the locale list it wants +// matched (typically obtained from the LocalizationManager) so that +// StringTable does not have to know about app-side singletons. +StringTable::StringTable(std::uint8_t* pbData, unsigned int dataSize, + const std::vector& locales) { src = std::vector(pbData, pbData + dataSize); - ProcessStringTableData(); + ProcessStringTableData(locales); } -void StringTable::ReloadStringTable() { +void StringTable::ReloadStringTable(const std::vector& locales) { m_stringsMap.clear(); m_stringsVec.clear(); - ProcessStringTableData(); + ProcessStringTableData(locales); } -void StringTable::ProcessStringTableData(void) { +void StringTable::ProcessStringTableData( + const std::vector& locales) { ByteArrayInputStream bais(src); DataInputStream dis(&bais); @@ -41,9 +45,6 @@ void StringTable::ProcessStringTableData(void) { langSize)); } - std::vector locales; - app.getLocale(locales); - bool foundLang = false; int64_t bytesToSkip = 0; int dataSize = 0; @@ -55,8 +56,8 @@ void StringTable::ProcessStringTableData(void) { for (auto it = langSizeMap.begin(); it != langSizeMap.end(); ++it) { if (it->first.compare(*it_locales) == 0) { - app.DebugPrintf("StringTable:: Found language '%s'.\n", - it_locales->c_str()); + Log::info("StringTable:: Found language '%s'.\n", + it_locales->c_str()); dataSize = it->second; foundLang = true; break; @@ -66,8 +67,8 @@ void StringTable::ProcessStringTableData(void) { } if (!foundLang) - app.DebugPrintf("StringTable:: Can't find language '%s'.\n", - it_locales->c_str()); + Log::info("StringTable:: Can't find language '%s'.\n", + it_locales->c_str()); } if (foundLang) { @@ -91,8 +92,8 @@ void StringTable::ProcessStringTableData(void) { std::string langId = dis2.readUTF(); int totalStrings = dis2.readInt(); - app.DebugPrintf("IsStatic=%d totalStrings = %d\n", isStatic ? 1 : 0, - totalStrings); + Log::info("IsStatic=%d totalStrings = %d\n", isStatic ? 1 : 0, + totalStrings); if (!isStatic) { for (int i = 0; i < totalStrings; ++i) { @@ -112,7 +113,7 @@ void StringTable::ProcessStringTableData(void) { // We can't delete this data in the dtor, so clear the reference bais2.reset(); } else { - app.DebugPrintf("Failed to get language\n"); + Log::info("Failed to get language\n"); #ifdef _DEBUG assert(0); #endif diff --git a/targets/minecraft/locale/StringTable.h b/targets/minecraft/locale/StringTable.h index 52b6ea04d..aef23eca1 100644 --- a/targets/minecraft/locale/StringTable.h +++ b/targets/minecraft/locale/StringTable.h @@ -54,9 +54,10 @@ public: // }; StringTable(void); - StringTable(std::uint8_t* pbData, unsigned int dataSize); + StringTable(std::uint8_t* pbData, unsigned int dataSize, + const std::vector& locales); ~StringTable(void); - void ReloadStringTable(); + void ReloadStringTable(const std::vector& locales); void getData(std::uint8_t** ppData, unsigned int* pSize); @@ -67,5 +68,5 @@ public: private: // std::string getLangId(uint32_t dwLanguage=0); - void ProcessStringTableData(void); + void ProcessStringTableData(const std::vector& locales); }; diff --git a/targets/minecraft/sources.txt b/targets/minecraft/sources.txt index aefd496ad..75324ed89 100644 --- a/targets/minecraft/sources.txt +++ b/targets/minecraft/sources.txt @@ -284,6 +284,7 @@ core/FacingEnum.cpp core/ItemDispenseBehaviors.cpp locale/I18n.cpp locale/Language.cpp +locale/StringTable.cpp network/Connection.cpp network/packet/AddEntityPacket.cpp network/packet/AddExperienceOrbPacket.cpp