1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Add JSON loading for footpath banners

This commit is contained in:
Ted John
2017-12-11 22:01:56 +00:00
committed by Gymnasiast
parent ec446ac9d6
commit 12d2523752
5 changed files with 30 additions and 9 deletions

View File

@@ -15,11 +15,11 @@
#pragma endregion
#include "../core/IStream.hpp"
#include "BannerObject.h"
#include "../drawing/Drawing.h"
#include "../localisation/Language.h"
#include "../object/Object.h"
#include "BannerObject.h"
#include "ObjectJsonHelpers.h"
#include "ObjectList.h"
void BannerObject::ReadLegacy(IReadObjectContext * context, IStream * stream)
@@ -84,3 +84,18 @@ void BannerObject::DrawPreview(rct_drawpixelinfo * dpi, sint32 width, sint32 hei
gfx_draw_sprite(dpi, imageId + 0, x - 12, y + 8, 0);
gfx_draw_sprite(dpi, imageId + 1, x - 12, y + 8, 0);
}
void BannerObject::ReadJson(IReadObjectContext * context, const json_t * root)
{
auto properties = json_object_get(root, "properties");
_legacyType.banner.scrolling_mode = json_integer_value(json_object_get(properties, "scrollingMode"));
_legacyType.banner.price = json_integer_value(json_object_get(properties, "price"));
_legacyType.banner.flags = ObjectJsonHelpers::GetFlags<uint8>(properties, {
{ "hasPrimaryColour", BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR }});
SetPrimarySceneryGroup(ObjectJsonHelpers::GetString(json_object_get(properties, "sceneryGroup")));
ObjectJsonHelpers::LoadStrings(root, GetStringTable());
ObjectJsonHelpers::LoadImages(root, GetImageTable());
}

View File

@@ -31,6 +31,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;

View File

@@ -142,13 +142,7 @@ void FootpathItemObject::ReadJson(IReadObjectContext * context, const json_t * r
_legacyType.path_bit.tool_id = ParseCursor(ObjectJsonHelpers::GetString(json_object_get(properties, "cursor")));
_legacyType.path_bit.price = json_integer_value(json_object_get(properties, "price"));
auto scg = ObjectJsonHelpers::GetString(json_object_get(properties, "sceneryGroup"));
if (!scg.empty())
{
rct_object_entry sgEntry = { 0 };
strncpy(sgEntry.name, scg.c_str(), 8);
SetPrimarySceneryGroup(&sgEntry);
}
SetPrimarySceneryGroup(ObjectJsonHelpers::GetString(json_object_get(properties, "sceneryGroup")));
// Flags
_legacyType.path_bit.flags = ObjectJsonHelpers::GetFlags<uint16>(properties, {

View File

@@ -209,6 +209,7 @@ namespace ObjectFactory
{
if (s == "ride") return OBJECT_TYPE_RIDE;
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 == "park_entrance") return OBJECT_TYPE_PARK_ENTRANCE;
return 0xFF;

View File

@@ -16,6 +16,7 @@
#pragma once
#include <cstring>
#include "Object.h"
class SceneryObject : public Object
@@ -31,4 +32,13 @@ public:
protected:
void SetPrimarySceneryGroup(const rct_object_entry * entry) { _primarySceneryGroupEntry = *entry; }
void SetPrimarySceneryGroup(const std::string &s)
{
if (!s.empty())
{
rct_object_entry sgEntry = { 0 };
std::strncpy(sgEntry.name, s.c_str(), 8);
SetPrimarySceneryGroup(&sgEntry);
}
}
};