diff --git a/src/openrct2/core/FileIndex.hpp b/src/openrct2/core/FileIndex.hpp index 99adbf1bbf..eb4ee05725 100644 --- a/src/openrct2/core/FileIndex.hpp +++ b/src/openrct2/core/FileIndex.hpp @@ -137,7 +137,7 @@ protected: * Loads the given file and creates the item representing the data to store in the index. * TODO Use std::optional when C++17 is available. */ - virtual std::tuple Create(const std::string &path) const abstract; + virtual std::tuple Create(sint32 language, const std::string &path) const abstract; /** * Serialises an index item to the given stream. @@ -180,7 +180,8 @@ private: return ScanResult(stats, files); } - void BuildRange(const ScanResult &scanResult, + void BuildRange(sint32 language, + const ScanResult &scanResult, size_t rangeStart, size_t rangeEnd, std::vector& items, @@ -198,7 +199,7 @@ private: log_verbose("FileIndex:Indexing '%s'", filePath.c_str()); } - auto item = Create(filePath); + auto item = Create(language, filePath); if (std::get<0>(item)) { items.push_back(std::get<1>(item)); @@ -245,6 +246,7 @@ private: jobPool.AddTask(std::bind(&FileIndex::BuildRange, this, + language, std::cref(scanResult), rangeStart, rangeStart + stepSize, diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index fa83f26d0a..d5a664a491 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -76,6 +76,11 @@ std::string Object::GetString(uint8 index) const return sz; } +std::string Object::GetString(sint32 language, uint8 index) const +{ + return GetStringTable().GetString(language, index); +} + rct_object_entry Object::GetScgWallsHeader() { return Object::CreateHeader("SCGWALLS", 207140231, 3518650219); @@ -711,6 +716,11 @@ std::string Object::GetName() const return GetString(OBJ_STRING_ID_NAME); } +std::string Object::GetName(sint32 language) const +{ + return GetString(language, OBJ_STRING_ID_NAME); +} + #ifdef __WARN_SUGGEST_FINAL_METHODS__ #pragma GCC diagnostic pop #endif diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 43c78a6c16..69b279660d 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -147,6 +147,7 @@ protected: std::string GetOverrideString(uint8 index) const; std::string GetString(uint8 index) const; + std::string GetString(sint32 language, uint8 index) const; void SetSourceGame(const uint8 sourceGame); bool IsRCT1Object(); @@ -172,6 +173,7 @@ public: virtual uint8 GetObjectType() const final { return _objectEntry.flags & 0x0F; } virtual std::string GetName() const; + virtual std::string GetName(sint32 language) const; virtual void SetRepositoryItem(ObjectRepositoryItem * item) const { } diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 95eb256f63..5a38ea66d7 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -101,7 +101,7 @@ public: } public: - std::tuple Create(const std::string &path) const override + std::tuple Create(sint32 language, const std::string &path) const override { auto extension = Path::GetExtension(path); if (String::Equals(extension, ".json", true)) @@ -112,7 +112,7 @@ public: ObjectRepositoryItem item = { 0 }; item.ObjectEntry = *object->GetObjectEntry(); item.Path = String::Duplicate(path); - item.Name = String::Duplicate(object->GetName()); + item.Name = String::Duplicate(object->GetName(language)); object->SetRepositoryItem(&item); delete object; return std::make_tuple(true, item); @@ -446,7 +446,8 @@ private: void ScanObject(const std::string &path) { - auto result = _fileIndex.Create(path); + auto language = LocalisationService_GetCurrentLanguage(); + auto result = _fileIndex.Create(language, path); if (std::get<0>(result)) { auto ori = std::get<1>(result); diff --git a/src/openrct2/object/StringTable.cpp b/src/openrct2/object/StringTable.cpp index 33d0ae26e7..7139b377c1 100644 --- a/src/openrct2/object/StringTable.cpp +++ b/src/openrct2/object/StringTable.cpp @@ -101,6 +101,18 @@ std::string StringTable::GetString(uint8 id) const return std::string(); } +std::string StringTable::GetString(uint8 language, uint8 id) const +{ + for (auto &string : _strings) + { + if (string.LanguageId == language && string.Id == id) + { + return string.Text; + } + } + return std::string(); +} + void StringTable::SetString(uint8 id, uint8 language, const std::string &text) { StringTableEntry entry; diff --git a/src/openrct2/object/StringTable.h b/src/openrct2/object/StringTable.h index 34fa8de21a..0dd9c148be 100644 --- a/src/openrct2/object/StringTable.h +++ b/src/openrct2/object/StringTable.h @@ -56,5 +56,6 @@ public: void Read(IReadObjectContext * context, IStream * stream, uint8 id); void Sort(); std::string GetString(uint8 id) const; + std::string GetString(uint8 language, uint8 id) const; void SetString(uint8 id, uint8 language, const std::string &text); }; diff --git a/src/openrct2/ride/TrackDesignRepository.cpp b/src/openrct2/ride/TrackDesignRepository.cpp index c105e1a478..97bf9d756f 100644 --- a/src/openrct2/ride/TrackDesignRepository.cpp +++ b/src/openrct2/ride/TrackDesignRepository.cpp @@ -81,7 +81,7 @@ public: } public: - std::tuple Create(const std::string &path) const override + std::tuple Create(sint32, const std::string &path) const override { auto td6 = track_design_open(path.c_str()); if (td6 != nullptr) @@ -348,7 +348,8 @@ public: std::string newPath = Path::Combine(installDir, fileName); if (File::Copy(path, newPath, false)) { - auto td = _fileIndex.Create(path); + auto language = LocalisationService_GetCurrentLanguage(); + auto td = _fileIndex.Create(language, path); if (std::get<0>(td)) { _items.push_back(std::get<1>(td)); diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index b02cddbcad..a7ab09d2b2 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -143,7 +143,7 @@ public: } protected: - std::tuple Create(const std::string &path) const override + std::tuple Create(sint32, const std::string &path) const override { scenario_index_entry entry; auto timestamp = File::GetLastModified(path);