Files
OpenRCT2-Web/src/openrct2/object/FootpathObject.cpp
T

100 lines
3.8 KiB
C++
Raw Normal View History

2016-06-25 17:09:56 +01:00
/*****************************************************************************
2018-06-15 14:07:34 +02:00
* Copyright (c) 2014-2018 OpenRCT2 developers
2016-06-25 17:09:56 +01:00
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
2016-06-25 17:09:56 +01:00
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-06-25 17:09:56 +01:00
*****************************************************************************/
2018-06-22 23:03:20 +02:00
#include "FootpathObject.h"
2016-06-25 17:09:56 +01:00
#include "../core/IStream.hpp"
2018-01-05 21:17:33 +00:00
#include "../drawing/Drawing.h"
2018-01-06 18:32:25 +01:00
#include "../localisation/Language.h"
2018-01-11 10:59:26 +01:00
#include "../world/Footpath.h"
2017-12-08 18:27:30 +00:00
#include "ObjectJsonHelpers.h"
2016-06-25 17:09:56 +01:00
2018-06-22 23:03:20 +02:00
void FootpathObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
2016-06-25 17:09:56 +01:00
{
stream->Seek(10, STREAM_SEEK_CURRENT);
_legacyType.support_type = stream->ReadValue<uint8_t>();
_legacyType.flags = stream->ReadValue<uint8_t>();
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
2016-07-01 20:01:31 +01:00
stream->Seek(1, STREAM_SEEK_CURRENT);
2016-06-25 17:09:56 +01:00
2017-12-11 13:06:59 +00:00
GetStringTable().Read(context, stream, OBJ_STRING_ID_NAME);
GetImageTable().Read(context, stream);
2016-07-02 17:23:06 +01:00
// Validate properties
2017-01-29 10:15:29 +00:00
if (_legacyType.support_type >= FOOTPATH_ENTRY_SUPPORT_TYPE_COUNT)
2016-07-02 17:23:06 +01:00
{
2017-01-29 10:15:29 +00:00
context->LogError(OBJECT_ERROR_INVALID_PROPERTY, "SUPPORT_TYPE not supported.");
2016-07-02 17:23:06 +01:00
}
2016-06-25 17:09:56 +01:00
}
void FootpathObject::Load()
{
2017-12-11 13:06:59 +00:00
GetStringTable().Sort();
2016-06-25 17:09:56 +01:00
_legacyType.string_idx = language_allocate_object_string(GetName());
2017-12-11 13:06:59 +00:00
_legacyType.image = gfx_object_allocate_images(GetImageTable().GetImages(), GetImageTable().GetCount());
2016-06-25 17:09:56 +01:00
_legacyType.bridge_image = _legacyType.image + 109;
2019-01-20 21:38:38 +01:00
_pathSurfaceEntry.string_idx = _legacyType.string_idx;
_pathSurfaceEntry.image = _legacyType.image;
_pathSurfaceEntry.queue_image = _legacyType.image + 51;
_pathSurfaceEntry.preview = _legacyType.image + 71;
_pathSurfaceEntry.flags = _legacyType.flags;
_pathRailingsEntry.string_idx = _legacyType.string_idx;
_pathRailingsEntry.bridge_image = _legacyType.bridge_image;
_pathRailingsEntry.preview = _legacyType.image + 71;
_pathRailingsEntry.flags = _legacyType.flags;
_pathRailingsEntry.scrolling_mode = _legacyType.scrolling_mode;
_pathRailingsEntry.support_type = _legacyType.support_type;
_pathRailingsEntry.railings_image = _legacyType.image + 73;
2016-06-25 17:09:56 +01:00
}
void FootpathObject::Unload()
{
language_free_object_string(_legacyType.string_idx);
2017-12-11 13:06:59 +00:00
gfx_object_free_images(_legacyType.image, GetImageTable().GetCount());
_legacyType.string_idx = 0;
_legacyType.image = 0;
2016-06-25 17:09:56 +01:00
}
2018-06-22 23:03:20 +02:00
void FootpathObject::DrawPreview(rct_drawpixelinfo* dpi, int32_t width, int32_t height) const
2016-07-02 12:29:13 +01:00
{
int32_t x = width / 2;
int32_t y = height / 2;
2019-01-20 21:38:38 +01:00
gfx_draw_sprite(dpi, _pathSurfaceEntry.preview, x - 49, y - 17, 0);
gfx_draw_sprite(dpi, _pathSurfaceEntry.preview + 1, x + 4, y - 17, 0);
2016-07-02 12:29:13 +01:00
}
2017-12-08 18:27:30 +00:00
2018-06-22 23:03:20 +02:00
static uint8_t ParseSupportType(const std::string& s)
2017-12-08 18:27:30 +00:00
{
2018-06-22 23:03:20 +02:00
if (s == "pole")
return FOOTPATH_ENTRY_SUPPORT_TYPE_POLE;
else /* if (s == "box") */
return FOOTPATH_ENTRY_SUPPORT_TYPE_BOX;
2017-12-08 18:27:30 +00:00
}
2018-06-22 23:03:20 +02:00
void FootpathObject::ReadJson(IReadObjectContext* context, const json_t* root)
2017-12-08 18:27:30 +00:00
{
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
2018-06-22 23:03:20 +02:00
_legacyType.flags = ObjectJsonHelpers::GetFlags<uint8_t>(
properties,
{
2019-01-20 14:56:12 +01:00
{ "hasSupportImages", RAILING_ENTRY_FLAG_HAS_SUPPORT_BASE_SPRITE },
{ "hasElevatedPathImages", RAILING_ENTRY_FLAG_DRAW_PATH_OVER_SUPPORTS },
{ "editorOnly", FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR },
});
2017-12-08 18:27:30 +00:00
2017-12-11 13:06:59 +00:00
ObjectJsonHelpers::LoadStrings(root, GetStringTable());
2018-02-08 21:31:30 +00:00
ObjectJsonHelpers::LoadImages(context, root, GetImageTable());
2017-12-08 18:27:30 +00:00
}