From a03b58501bba8486a7fee351e389e6bd4fa9804c Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 19 Dec 2017 15:08:48 +0000 Subject: [PATCH] Add JSON loading for small scenery --- src/openrct2/object/ObjectFactory.cpp | 1 + src/openrct2/object/SmallSceneryObject.cpp | 74 +++++++++++++++++++++- src/openrct2/object/SmallSceneryObject.h | 2 + 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index 412f82c283..a399fe5b1b 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -211,6 +211,7 @@ namespace ObjectFactory if (s == "footpath") return OBJECT_TYPE_PATHS; if (s == "footpath_banner") return OBJECT_TYPE_BANNERS; if (s == "footpath_item") return OBJECT_TYPE_PATH_BITS; + if (s == "scenery_small") return OBJECT_TYPE_SMALL_SCENERY; if (s == "scenery_large") return OBJECT_TYPE_LARGE_SCENERY; if (s == "scenery_wall") return OBJECT_TYPE_WALLS; if (s == "scenery_group") return OBJECT_TYPE_SCENERY_GROUP; diff --git a/src/openrct2/object/SmallSceneryObject.cpp b/src/openrct2/object/SmallSceneryObject.cpp index 24a2e43bec..ed60b7c1c0 100644 --- a/src/openrct2/object/SmallSceneryObject.cpp +++ b/src/openrct2/object/SmallSceneryObject.cpp @@ -14,16 +14,19 @@ *****************************************************************************/ #pragma endregion +#pragma warning(disable : 4706) // assignment within conditional expression + #include "../core/IStream.hpp" #include "../core/Math.hpp" #include "../core/Memory.hpp" #include "../core/String.hpp" -#include "SmallSceneryObject.h" - #include "../drawing/Drawing.h" +#include "../interface/Cursors.h" #include "../localisation/Language.h" #include "../world/Scenery.h" #include "../world/SmallScenery.h" +#include "SmallSceneryObject.h" +#include "ObjectJsonHelpers.h" void SmallSceneryObject::ReadLegacy(IReadObjectContext * context, IStream * stream) { @@ -231,3 +234,70 @@ rct_object_entry SmallSceneryObject::GetScgAbstrHeader() { return Object::CreateHeader("SCGABSTR", 207140231, 932253451); } + +void SmallSceneryObject::ReadJson(IReadObjectContext * context, const json_t * root) +{ + auto properties = json_object_get(root, "properties"); + + _legacyType.small_scenery.height = json_integer_value(json_object_get(properties, "height")); + _legacyType.small_scenery.tool_id = ObjectJsonHelpers::ParseCursor(ObjectJsonHelpers::GetString(properties, "cursor"), CURSOR_STATUE_DOWN); + _legacyType.small_scenery.price = json_integer_value(json_object_get(properties, "price")); + _legacyType.small_scenery.removal_price = json_integer_value(json_object_get(properties, "removalPrice")); + _legacyType.small_scenery.animation_delay = json_integer_value(json_object_get(properties, "animationDelay")); + _legacyType.small_scenery.animation_mask = json_integer_value(json_object_get(properties, "animationMask")); + _legacyType.small_scenery.num_frames = json_integer_value(json_object_get(properties, "numFrames")); + + // Flags + _legacyType.small_scenery.flags = ObjectJsonHelpers::GetFlags(properties, { + { "isFullTile", SMALL_SCENERY_FLAG_FULL_TILE }, + { "SMALL_SCENERY_FLAG_VOFFSET_CENTRE", SMALL_SCENERY_FLAG_VOFFSET_CENTRE }, + { "requiresFlatSurface", SMALL_SCENERY_FLAG_REQUIRE_FLAT_SURFACE }, + { "isRotatable", SMALL_SCENERY_FLAG_ROTATABLE }, + { "isAnimated", SMALL_SCENERY_FLAG_ANIMATED }, + { "canWither", SMALL_SCENERY_FLAG_CAN_WITHER }, + { "canBeWatered", SMALL_SCENERY_FLAG_CAN_BE_WATERED }, + { "hasOverlayImage", SMALL_SCENERY_FLAG_ANIMATED_FG }, + { "SMALL_SCENERY_FLAG_DIAGONAL", SMALL_SCENERY_FLAG_DIAGONAL }, + { "hasGlass", SMALL_SCENERY_FLAG_HAS_GLASS }, + { "hasPrimaryColour", SMALL_SCENERY_FLAG_HAS_PRIMARY_COLOUR }, + { "SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_1", SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_1 }, + { "SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_4", SMALL_SCENERY_FLAG_FOUNTAIN_SPRAY_4 }, + { "isClock", SMALL_SCENERY_FLAG_IS_CLOCK }, + { "SMALL_SCENERY_FLAG_SWAMP_GOO", SMALL_SCENERY_FLAG_SWAMP_GOO }, + { "SMALL_SCENERY_FLAG17", SMALL_SCENERY_FLAG17 }, + { "isStackable", SMALL_SCENERY_FLAG_STACKABLE }, + { "prohibitWalls", SMALL_SCENERY_FLAG_NO_WALLS }, + { "hasSecondaryColour", SMALL_SCENERY_FLAG_HAS_SECONDARY_COLOUR }, + { "hasNoSupports", SMALL_SCENERY_FLAG_NO_SUPPORTS }, + { "SMALL_SCENERY_FLAG_VISIBLE_WHEN_ZOOMED", SMALL_SCENERY_FLAG_VISIBLE_WHEN_ZOOMED }, + { "SMALL_SCENERY_FLAG_COG", SMALL_SCENERY_FLAG_COG }, + { "allowSupportsAbove", SMALL_SCENERY_FLAG_BUILD_DIRECTLY_ONTOP }, + { "SMALL_SCENERY_FLAG_HALF_SPACE", SMALL_SCENERY_FLAG_HALF_SPACE }, + { "SMALL_SCENERY_FLAG_THREE_QUARTERS", SMALL_SCENERY_FLAG_THREE_QUARTERS }, + { "supportsHavePrimaryColour", SMALL_SCENERY_FLAG_PAINT_SUPPORTS }, + { "SMALL_SCENERY_FLAG27", SMALL_SCENERY_FLAG27 } }); + + auto jFrameOffsets = json_object_get(properties, "frameOffsets"); + if (jFrameOffsets != nullptr) + { + _frameOffsets = ReadJsonFrameOffsets(jFrameOffsets); + _legacyType.small_scenery.flags |= SMALL_SCENERY_FLAG_HAS_FRAME_OFFSETS; + } + + SetPrimarySceneryGroup(ObjectJsonHelpers::GetString(json_object_get(properties, "sceneryGroup"))); + + ObjectJsonHelpers::LoadStrings(root, GetStringTable()); + ObjectJsonHelpers::LoadImages(root, GetImageTable()); +} + +std::vector SmallSceneryObject::ReadJsonFrameOffsets(const json_t * jFrameOffsets) +{ + std::vector offsets; + size_t index; + const json_t * jOffset; + json_array_foreach(jFrameOffsets, index, jOffset) + { + offsets.push_back(json_integer_value(jOffset)); + } + return offsets; +} diff --git a/src/openrct2/object/SmallSceneryObject.h b/src/openrct2/object/SmallSceneryObject.h index d7cbe04031..15043e6e9c 100644 --- a/src/openrct2/object/SmallSceneryObject.h +++ b/src/openrct2/object/SmallSceneryObject.h @@ -32,6 +32,7 @@ public: void * GetLegacyData() override { return &_legacyType; } void ReadLegacy(IReadObjectContext * context, IStream * stream) override; + void ReadJson(IReadObjectContext * context, const json_t * root) override; void Load() override; void Unload() override; @@ -39,6 +40,7 @@ public: private: static std::vector ReadFrameOffsets(IStream * stream); + static std::vector ReadJsonFrameOffsets(const json_t * jFrameOffsets); void PerformFixes(); rct_object_entry GetScgPiratHeader(); rct_object_entry GetScgMineHeader();