diff --git a/src/openrct2/object/FootpathItemObject.cpp b/src/openrct2/object/FootpathItemObject.cpp index 0586a6354c..8d5b0e87eb 100644 --- a/src/openrct2/object/FootpathItemObject.cpp +++ b/src/openrct2/object/FootpathItemObject.cpp @@ -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(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()); diff --git a/src/openrct2/object/FootpathObject.cpp b/src/openrct2/object/FootpathObject.cpp index 4d5befd9b7..da8e1ec398 100644 --- a/src/openrct2/object/FootpathObject.cpp +++ b/src/openrct2/object/FootpathObject.cpp @@ -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(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()); diff --git a/src/openrct2/object/ObjectJsonHelpers.h b/src/openrct2/object/ObjectJsonHelpers.h index 866fada431..c2edea2741 100644 --- a/src/openrct2/object/ObjectJsonHelpers.h +++ b/src/openrct2/object/ObjectJsonHelpers.h @@ -16,7 +16,9 @@ #pragma once +#include #include +#include #include #include "../common.h" #include "../core/Json.hpp" @@ -31,4 +33,18 @@ namespace ObjectJsonHelpers std::vector GetJsonStringArray(const json_t * arr); void LoadStrings(const json_t * root, StringTable &stringTable); void LoadImages(const json_t * root, ImageTable &imageTable); + + template + T GetFlags(const json_t * obj, std::initializer_list> list) + { + T flags = 0; + for (const auto &item : list) + { + if (GetBoolean(obj, item.first)) + { + flags |= item.second; + } + } + return flags; + } };