mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Implement footpath JSON reading
This commit is contained in:
@@ -15,11 +15,11 @@
|
||||
#pragma endregion
|
||||
|
||||
#include "../core/IStream.hpp"
|
||||
#include "FootpathObject.h"
|
||||
|
||||
#include "../drawing/Drawing.h"
|
||||
#include "../localisation/Language.h"
|
||||
#include "../world/Footpath.h"
|
||||
#include "FootpathObject.h"
|
||||
#include "ObjectJsonHelpers.h"
|
||||
|
||||
void FootpathObject::ReadLegacy(IReadObjectContext * context, IStream * stream)
|
||||
{
|
||||
@@ -63,3 +63,40 @@ void FootpathObject::DrawPreview(rct_drawpixelinfo * dpi, sint32 width, sint32 h
|
||||
gfx_draw_sprite(dpi, _legacyType.image + 71, x - 49, y - 17, 0);
|
||||
gfx_draw_sprite(dpi, _legacyType.image + 72, x + 4, y - 17, 0);
|
||||
}
|
||||
|
||||
static uint8 ParseSupportType(const std::string &s)
|
||||
{
|
||||
if (s == "pole") return FOOTPATH_ENTRY_SUPPORT_TYPE_POLE;
|
||||
else /* if (s == "box") */ return FOOTPATH_ENTRY_SUPPORT_TYPE_BOX;
|
||||
}
|
||||
|
||||
void FootpathObject::ReadJson(IReadObjectContext * context, const json_t * root)
|
||||
{
|
||||
// Strings
|
||||
auto stringTable = GetStringTable();
|
||||
auto jsonStrings = json_object_get(root, "strings");
|
||||
auto jsonName = json_object_get(jsonStrings, "name");
|
||||
stringTable->SetString(0, 0, json_string_value(json_object_get(jsonName, "en-GB")));
|
||||
|
||||
auto properties = json_object_get(root, "properties");
|
||||
_legacyType.support_type = ParseSupportType(ObjectJsonHelpers::GetString(json_object_get(properties, "supportType")));
|
||||
_legacyType.scrolling_mode = json_integer_value(json_object_get(properties, "scrollingMode"));
|
||||
|
||||
// Flags
|
||||
_legacyType.flags = 0;
|
||||
if (json_boolean_value(json_object_get(properties, "hasSupportImages")))
|
||||
{
|
||||
_legacyType.flags |= FOOTPATH_ENTRY_FLAG_HAS_SUPPORT_BASE_SPRITE;
|
||||
}
|
||||
if (json_boolean_value(json_object_get(properties, "hasElevatedPathImages")))
|
||||
{
|
||||
_legacyType.flags |= FOOTPATH_ENTRY_FLAG_HAS_PATH_BASE_SPRITE;
|
||||
}
|
||||
if (json_boolean_value(json_object_get(properties, "editorOnly")))
|
||||
{
|
||||
_legacyType.flags |= FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR;
|
||||
}
|
||||
|
||||
auto imageTable = GetImageTable();
|
||||
ObjectJsonHelpers::LoadImages(root, *imageTable);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -211,6 +211,10 @@ namespace ObjectFactory
|
||||
{
|
||||
return OBJECT_TYPE_RIDE;
|
||||
}
|
||||
else if (s == "footpath")
|
||||
{
|
||||
return OBJECT_TYPE_PATHS;
|
||||
}
|
||||
else if (s == "park_entrance")
|
||||
{
|
||||
return OBJECT_TYPE_PARK_ENTRANCE;
|
||||
|
||||
@@ -28,6 +28,13 @@ using namespace OpenRCT2;
|
||||
|
||||
namespace ObjectJsonHelpers
|
||||
{
|
||||
std::string GetString(const json_t * value)
|
||||
{
|
||||
return json_is_string(value) ?
|
||||
std::string(json_string_value(value)) :
|
||||
std::string();
|
||||
}
|
||||
|
||||
std::vector<std::string> GetJsonStringArray(const json_t * arr)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
namespace ObjectJsonHelpers
|
||||
{
|
||||
std::string GetString(const json_t * value);
|
||||
std::vector<std::string> GetJsonStringArray(const json_t * arr);
|
||||
void LoadImages(const json_t * root, ImageTable &imageTable);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user