mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Read JSON for park entrance objects
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
#include "../core/IStream.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "EntranceObject.h"
|
||||
|
||||
#include "../drawing/Drawing.h"
|
||||
#include "../localisation/Localisation.h"
|
||||
#include "EntranceObject.h"
|
||||
#include "ObjectJsonHelpers.h"
|
||||
|
||||
void EntranceObject::ReadLegacy(IReadObjectContext * context, IStream * stream)
|
||||
{
|
||||
@@ -65,3 +65,19 @@ void EntranceObject::DrawPreview(rct_drawpixelinfo * dpi, sint32 width, sint32 h
|
||||
gfx_draw_sprite(dpi, imageId + 0, x + 0, y + 28, 0);
|
||||
gfx_draw_sprite(dpi, imageId + 2, x + 32, y + 44, 0);
|
||||
}
|
||||
|
||||
void EntranceObject::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.scrolling_mode = json_integer_value(json_object_get(properties, "scrollingMode"));
|
||||
_legacyType.text_height = json_integer_value(json_object_get(properties, "textHeight"));
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -205,6 +205,19 @@ namespace ObjectFactory
|
||||
return result;
|
||||
}
|
||||
|
||||
static uint8 ParseObjectType(const std::string &s)
|
||||
{
|
||||
if (s == "ride")
|
||||
{
|
||||
return OBJECT_TYPE_RIDE;
|
||||
}
|
||||
else if (s == "park_entrance")
|
||||
{
|
||||
return OBJECT_TYPE_PARK_ENTRANCE;
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
Object * CreateObjectFromJsonFile(const std::string &path)
|
||||
{
|
||||
log_verbose("CreateObjectFromJsonFile(\"%s\")", path.c_str());
|
||||
@@ -216,8 +229,8 @@ namespace ObjectFactory
|
||||
auto jObjectType = json_object_get(jRoot, "objectType");
|
||||
if (json_is_string(jObjectType))
|
||||
{
|
||||
auto objectType = std::string(json_string_value(jObjectType));
|
||||
if (objectType == "ride")
|
||||
auto objectType = ParseObjectType(json_string_value(jObjectType));
|
||||
if (objectType != 0xFF)
|
||||
{
|
||||
auto id = json_string_value(json_object_get(jRoot, "id"));
|
||||
|
||||
@@ -233,7 +246,7 @@ namespace ObjectFactory
|
||||
auto minLength = std::min<size_t>(8, originalName.length());
|
||||
memcpy(entry.name, originalName.c_str(), minLength);
|
||||
|
||||
result = new RideObject(entry);
|
||||
result = CreateObject(entry);
|
||||
auto readContext = ReadObjectContext(id);
|
||||
result->ReadJson(&readContext, jRoot);
|
||||
if (readContext.WasError())
|
||||
|
||||
Reference in New Issue
Block a user