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

Do not output error if the sourceGame parameter is omitted (#13079)

Since >90% of objects in the wild are custom objects, it make sense if this
parameter can be safely omitted. Only warn if this field contains garbage.
This commit is contained in:
Michael Steenbeek
2020-10-03 19:41:52 +02:00
committed by GitHub
parent 7f963c4901
commit 8e60ecc022

View File

@@ -408,6 +408,38 @@ namespace ObjectFactory
return result;
}
static void ExtractSourceGames(const std::string& id, json_t& jRoot, Object* result)
{
auto sourceGames = jRoot["sourceGame"];
if (sourceGames.is_array() || sourceGames.is_string())
{
std::vector<uint8_t> sourceGameVector;
for (const auto& jSourceGame : sourceGames)
{
sourceGameVector.push_back(ParseSourceGame(Json::GetString(jSourceGame)));
}
if (!sourceGameVector.empty())
{
result->SetSourceGames(sourceGameVector);
}
else
{
log_error("Object %s has an incorrect sourceGame parameter.", id.c_str());
result->SetSourceGames({ OBJECT_SOURCE_CUSTOM });
}
}
// >90% of objects are custom, so allow omitting the parameter without displaying an error.
else if (sourceGames.is_null())
{
result->SetSourceGames({ OBJECT_SOURCE_CUSTOM });
}
else
{
log_error("Object %s has an incorrect sourceGame parameter.", id.c_str());
result->SetSourceGames({ OBJECT_SOURCE_CUSTOM });
}
}
Object* CreateObjectFromJson(IObjectRepository& objectRepository, json_t& jRoot, const IFileDataRetriever* fileRetriever)
{
Guard::Assert(jRoot.is_object(), "ObjectFactory::CreateObjectFromJson expects parameter jRoot to be object");
@@ -454,21 +486,7 @@ namespace ObjectFactory
}
result->SetAuthors(std::move(authorVector));
auto sourceGames = jRoot["sourceGame"];
if (sourceGames.is_array() || sourceGames.is_string())
{
std::vector<uint8_t> sourceGameVector;
for (const auto& jSourceGame : sourceGames)
{
sourceGameVector.push_back(ParseSourceGame(Json::GetString(jSourceGame)));
}
result->SetSourceGames(sourceGameVector);
}
else
{
log_error("Object %s has an incorrect sourceGame parameter.", id.c_str());
result->SetSourceGames({ OBJECT_SOURCE_CUSTOM });
}
ExtractSourceGames(id, jRoot, result);
}
return result;
}