1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Use correct language for scan-objects

This commit is contained in:
Ted John
2018-04-27 18:23:39 +01:00
parent 238079ef7f
commit 7075f6ca25
8 changed files with 38 additions and 9 deletions

View File

@@ -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<bool, TItem> Create(const std::string &path) const abstract;
virtual std::tuple<bool, TItem> 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<TItem>& 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<TItem>::BuildRange,
this,
language,
std::cref(scanResult),
rangeStart,
rangeStart + stepSize,

View File

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

View File

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

View File

@@ -101,7 +101,7 @@ public:
}
public:
std::tuple<bool, ObjectRepositoryItem> Create(const std::string &path) const override
std::tuple<bool, ObjectRepositoryItem> 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);

View File

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

View File

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

View File

@@ -81,7 +81,7 @@ public:
}
public:
std::tuple<bool, TrackRepositoryItem> Create(const std::string &path) const override
std::tuple<bool, TrackRepositoryItem> 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));

View File

@@ -143,7 +143,7 @@ public:
}
protected:
std::tuple<bool, scenario_index_entry> Create(const std::string &path) const override
std::tuple<bool, scenario_index_entry> Create(sint32, const std::string &path) const override
{
scenario_index_entry entry;
auto timestamp = File::GetLastModified(path);