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

Write helper method for parsing flags

This commit is contained in:
Ted John
2017-12-11 12:44:37 +00:00
committed by Gymnasiast
parent 900bc48efa
commit c3f075d18c
3 changed files with 22 additions and 32 deletions

View File

@@ -151,13 +151,7 @@ void FootpathItemObject::ReadJson(IReadObjectContext * context, const json_t * r
}
// Flags
struct Item
{
const char * Name;
uint16 Flag;
};
Item FlagDefs[] =
{
_legacyType.path_bit.flags = ObjectJsonHelpers::GetFlags<uint16>(properties, {
{ "isBin", PATH_BIT_FLAG_IS_BIN },
{ "isBench", PATH_BIT_FLAG_IS_BENCH },
{ "isBreakable", PATH_BIT_FLAG_BREAKABLE },
@@ -166,18 +160,7 @@ void FootpathItemObject::ReadJson(IReadObjectContext * context, const json_t * r
{ "isJumpingFountainSnow", PATH_BIT_FLAG_JUMPING_FOUNTAIN_SNOW },
{ "isAllowedOnQueue", PATH_BIT_FLAG_DONT_ALLOW_ON_QUEUE },
{ "isAllowedOnSlope", PATH_BIT_FLAG_DONT_ALLOW_ON_SLOPE },
{ "isTelevision", PATH_BIT_FLAG_IS_QUEUE_SCREEN },
};
uint16 flags = 0;
for (const auto &def : FlagDefs)
{
if (ObjectJsonHelpers::GetBoolean(properties, def.Name))
{
flags |= def.Flag;
}
}
_legacyType.path_bit.flags = flags;
{ "isTelevision", PATH_BIT_FLAG_IS_QUEUE_SCREEN }});
ObjectJsonHelpers::LoadStrings(root, *GetStringTable());
ObjectJsonHelpers::LoadImages(root, *GetImageTable());

View File

@@ -77,19 +77,10 @@ void FootpathObject::ReadJson(IReadObjectContext * context, const json_t * root)
_legacyType.scrolling_mode = json_integer_value(json_object_get(properties, "scrollingMode"));
// Flags
_legacyType.flags = 0;
if (ObjectJsonHelpers::GetBoolean(properties, "hasSupportImages"))
{
_legacyType.flags |= FOOTPATH_ENTRY_FLAG_HAS_SUPPORT_BASE_SPRITE;
}
if (ObjectJsonHelpers::GetBoolean(properties, "hasElevatedPathImages"))
{
_legacyType.flags |= FOOTPATH_ENTRY_FLAG_HAS_PATH_BASE_SPRITE;
}
if (ObjectJsonHelpers::GetBoolean(properties, "editorOnly"))
{
_legacyType.flags |= FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR;
}
_legacyType.flags = ObjectJsonHelpers::GetFlags<uint8>(properties, {
{ "hasSupportImages", FOOTPATH_ENTRY_FLAG_HAS_SUPPORT_BASE_SPRITE },
{ "hasElevatedPathImages", FOOTPATH_ENTRY_FLAG_HAS_PATH_BASE_SPRITE },
{ "editorOnly", FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR } });
ObjectJsonHelpers::LoadStrings(root, *GetStringTable());
ObjectJsonHelpers::LoadImages(root, *GetImageTable());

View File

@@ -16,7 +16,9 @@
#pragma once
#include <initializer_list>
#include <string>
#include <utility>
#include <vector>
#include "../common.h"
#include "../core/Json.hpp"
@@ -31,4 +33,18 @@ namespace ObjectJsonHelpers
std::vector<std::string> GetJsonStringArray(const json_t * arr);
void LoadStrings(const json_t * root, StringTable &stringTable);
void LoadImages(const json_t * root, ImageTable &imageTable);
template<typename T>
T GetFlags(const json_t * obj, std::initializer_list<std::pair<std::string, T>> list)
{
T flags = 0;
for (const auto &item : list)
{
if (GetBoolean(obj, item.first))
{
flags |= item.second;
}
}
return flags;
}
};