mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-19 13:03:11 +01:00
Refactor objects to use new JSON library
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "../object/Object.h"
|
||||
#include "../object/ObjectRepository.h"
|
||||
#include "ObjectJsonHelpers.h"
|
||||
#include "ObjectList.h"
|
||||
|
||||
#include <unordered_map>
|
||||
@@ -98,40 +97,36 @@ static uint8_t ParseDrawType(const std::string& s)
|
||||
return PATH_BIT_DRAW_TYPE_LIGHTS;
|
||||
}
|
||||
|
||||
void FootpathItemObject::ReadJson(IReadObjectContext* context, const json_t* root)
|
||||
void FootpathItemObject::ReadJson(IReadObjectContext* context, json_t& root)
|
||||
{
|
||||
auto properties = json_object_get(root, "properties");
|
||||
_legacyType.path_bit.draw_type = ParseDrawType(ObjectJsonHelpers::GetString(properties, "renderAs"));
|
||||
_legacyType.path_bit.tool_id = ObjectJsonHelpers::ParseCursor(
|
||||
ObjectJsonHelpers::GetString(properties, "cursor"), CURSOR_LAMPPOST_DOWN);
|
||||
_legacyType.path_bit.price = json_integer_value(json_object_get(properties, "price"));
|
||||
Guard::Assert(root.is_object(), "FootpathItemObject::ReadJson expects parameter root to be object");
|
||||
|
||||
SetPrimarySceneryGroup(ObjectJsonHelpers::GetString(json_object_get(properties, "sceneryGroup")));
|
||||
json_t properties = root["properties"];
|
||||
|
||||
// Flags
|
||||
_legacyType.path_bit.flags = ObjectJsonHelpers::GetFlags<uint16_t>(
|
||||
properties,
|
||||
{
|
||||
{ "isBin", PATH_BIT_FLAG_IS_BIN },
|
||||
{ "isBench", PATH_BIT_FLAG_IS_BENCH },
|
||||
{ "isBreakable", PATH_BIT_FLAG_BREAKABLE },
|
||||
{ "isLamp", PATH_BIT_FLAG_LAMP },
|
||||
{ "isJumpingFountainWater", PATH_BIT_FLAG_JUMPING_FOUNTAIN_WATER },
|
||||
{ "isJumpingFountainSnow", PATH_BIT_FLAG_JUMPING_FOUNTAIN_SNOW },
|
||||
{ "isTelevision", PATH_BIT_FLAG_IS_QUEUE_SCREEN },
|
||||
});
|
||||
|
||||
// HACK To avoid 'negated' properties in JSON, handle these separately until
|
||||
// flags are inverted in this code base.
|
||||
if (!ObjectJsonHelpers::GetBoolean(properties, "isAllowedOnQueue", false))
|
||||
if (properties.is_object())
|
||||
{
|
||||
_legacyType.path_bit.flags |= PATH_BIT_FLAG_DONT_ALLOW_ON_QUEUE;
|
||||
}
|
||||
if (!ObjectJsonHelpers::GetBoolean(properties, "isAllowedOnSlope", false))
|
||||
{
|
||||
_legacyType.path_bit.flags |= PATH_BIT_FLAG_DONT_ALLOW_ON_SLOPE;
|
||||
_legacyType.path_bit.draw_type = ParseDrawType(Json::GetString(properties["renderAs"]));
|
||||
_legacyType.path_bit.tool_id = Cursor::FromString(Json::GetString(properties["cursor"]), CURSOR_LAMPPOST_DOWN);
|
||||
_legacyType.path_bit.price = Json::GetNumber<int16_t>(properties["price"]);
|
||||
|
||||
SetPrimarySceneryGroup(Json::GetString(properties["sceneryGroup"]));
|
||||
|
||||
// clang-format off
|
||||
_legacyType.path_bit.flags = Json::GetFlags<uint16_t>(
|
||||
properties,
|
||||
{
|
||||
{ "isBin", PATH_BIT_FLAG_IS_BIN, Json::FlagType::Normal },
|
||||
{ "isBench", PATH_BIT_FLAG_IS_BENCH, Json::FlagType::Normal },
|
||||
{ "isBreakable", PATH_BIT_FLAG_BREAKABLE, Json::FlagType::Normal },
|
||||
{ "isLamp", PATH_BIT_FLAG_LAMP, Json::FlagType::Normal },
|
||||
{ "isJumpingFountainWater", PATH_BIT_FLAG_JUMPING_FOUNTAIN_WATER, Json::FlagType::Normal },
|
||||
{ "isJumpingFountainSnow", PATH_BIT_FLAG_JUMPING_FOUNTAIN_SNOW, Json::FlagType::Normal },
|
||||
{ "isAllowedOnQueue", PATH_BIT_FLAG_DONT_ALLOW_ON_QUEUE, Json::FlagType::Inverted },
|
||||
{ "isAllowedOnSlope", PATH_BIT_FLAG_DONT_ALLOW_ON_SLOPE, Json::FlagType::Inverted },
|
||||
{ "isTelevision", PATH_BIT_FLAG_IS_QUEUE_SCREEN, Json::FlagType::Normal },
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
ObjectJsonHelpers::LoadStrings(root, GetStringTable());
|
||||
ObjectJsonHelpers::LoadImages(context, root, GetImageTable());
|
||||
PopulateTablesFromJson(context, root);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user