1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 14:54:30 +01:00

Refactor ObjectJsonHelpers

Move functions in ObjectJsonHelpers to their relevant namespaces and classes
- Move ParseColour to Colour::FromString
- Move ParseCursor to Cursor::FromString
- Move LoadStrings to StringTable::ReadJson
- Move LoadImages to ImageTable::ReadJson
- Move ParseObjectEntry to Object::ParseObjectEntry
- Move GetString, etc. to Json::GetString, etc.
- Delete ObjectJsonHelpers .cpp and .h files
This commit is contained in:
Simon Jarrett
2020-08-12 19:44:59 +01:00
parent 1b821c1059
commit 5f17554c25
13 changed files with 537 additions and 619 deletions

View File

@@ -78,6 +78,45 @@ void StringTable::Read(IReadObjectContext* context, OpenRCT2::IStream* stream, O
Sort();
}
ObjectStringID StringTable::ParseStringId(const std::string& s)
{
if (s == "name")
return ObjectStringID::NAME;
if (s == "description")
return ObjectStringID::DESCRIPTION;
if (s == "capacity")
return ObjectStringID::CAPACITY;
if (s == "vehicleName")
return ObjectStringID::VEHICLE_NAME;
return ObjectStringID::UNKNOWN;
}
void StringTable::ReadJson(json_t& root)
{
Guard::Assert(root.is_object(), "StringTable::ReadJson expects parameter root to be object");
// We trust the JSON type of root is object
auto jsonStrings = root["strings"];
for (auto& [key, jsonLanguages] : jsonStrings.items())
{
auto stringId = ParseStringId(key);
if (stringId != ObjectStringID::UNKNOWN)
{
for (auto& [locale, jsonString] : jsonLanguages.items())
{
auto langId = language_get_id_from_locale(locale.c_str());
if (langId != LANGUAGE_UNDEFINED)
{
auto string = Json::GetString(jsonString);
SetString(stringId, langId, string);
}
}
}
}
Sort();
}
std::string StringTable::GetString(ObjectStringID id) const
{
for (auto& string : _strings)