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

106 lines
3.7 KiB
C++
Raw Normal View History

2016-06-25 23:43:30 +01:00
/*****************************************************************************
2023-01-01 04:58:01 -06:00
* Copyright (c) 2014-2023 OpenRCT2 developers
2016-06-25 23:43:30 +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 23:43:30 +01:00
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
2016-06-25 23:43:30 +01:00
*****************************************************************************/
2018-06-22 23:03:20 +02:00
#include "BannerObject.h"
2016-06-25 23:43:30 +01:00
#include "../core/IStream.hpp"
#include "../core/Json.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-02 20:36:42 +01:00
#include "../object/Object.h"
#include "../object/ObjectRepository.h"
2018-01-02 20:36:42 +01:00
#include "ObjectList.h"
2016-06-25 23:43:30 +01:00
void BannerObject::ReadLegacy(IReadObjectContext* context, OpenRCT2::IStream* stream)
2016-06-25 23:43:30 +01:00
{
stream->Seek(6, OpenRCT2::STREAM_SEEK_CURRENT);
2021-06-03 21:43:30 +01:00
_legacyType.scrolling_mode = stream->ReadValue<uint8_t>();
_legacyType.flags = stream->ReadValue<uint8_t>();
_legacyType.price = stream->ReadValue<money16>();
2021-06-03 21:43:30 +01:00
_legacyType.scenery_tab_id = OBJECT_ENTRY_INDEX_NULL;
stream->Seek(2, OpenRCT2::STREAM_SEEK_CURRENT);
2016-06-25 23:43:30 +01:00
GetStringTable().Read(context, stream, ObjectStringID::NAME);
2016-06-25 23:43:30 +01:00
RCTObjectEntry sgEntry = stream->ReadValue<RCTObjectEntry>();
2021-03-12 11:04:04 +01:00
SetPrimarySceneryGroup(ObjectEntryDescriptor(sgEntry));
2016-06-25 23:43:30 +01:00
2017-12-11 13:06:59 +00:00
GetImageTable().Read(context, stream);
2016-07-02 17:23:06 +01:00
// Validate properties
if (_legacyType.price <= 0.00_GBP)
2016-07-02 17:23:06 +01:00
{
context->LogError(ObjectError::InvalidProperty, "Price can not be free or negative.");
2016-07-02 17:23:06 +01:00
}
// Add banners to 'Signs and items for footpaths' group, rather than lumping them in the Miscellaneous tab.
// Since this is already done the other way round for original items, avoid adding those to prevent duplicates.
auto identifier = GetLegacyIdentifier();
auto& objectRepository = context->GetObjectRepository();
2020-11-05 21:19:43 +01:00
auto item = objectRepository.FindObjectLegacy(identifier);
if (item != nullptr)
{
2018-07-30 22:01:04 +02:00
auto sourceGame = item->GetFirstSourceGame();
if (sourceGame == ObjectSourceGame::WackyWorlds || sourceGame == ObjectSourceGame::TimeTwister
|| sourceGame == ObjectSourceGame::Custom)
{
auto scgPathX = Object::GetScgPathXHeader();
2021-03-12 11:04:04 +01:00
SetPrimarySceneryGroup(scgPathX);
}
}
2016-06-25 23:43:30 +01:00
}
void BannerObject::Load()
{
2017-12-11 13:06:59 +00:00
GetStringTable().Sort();
_legacyType.name = LanguageAllocateObjectString(GetName());
_legacyType.image = LoadImages();
2016-06-25 23:43:30 +01:00
}
void BannerObject::Unload()
{
LanguageFreeObjectString(_legacyType.name);
UnloadImages();
_legacyType.name = 0;
_legacyType.image = 0;
2016-06-25 23:43:30 +01:00
}
2023-03-13 16:52:49 +01:00
void BannerObject::DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const
2016-07-02 12:29:13 +01:00
{
auto screenCoords = ScreenCoordsXY{ width / 2, height / 2 };
2016-07-02 12:29:13 +01:00
2021-11-29 14:36:36 +01:00
auto image0 = ImageId(_legacyType.image, COLOUR_BORDEAUX_RED);
auto image1 = ImageId(_legacyType.image + 1, COLOUR_BORDEAUX_RED);
2023-04-03 20:38:28 +02:00
GfxDrawSprite(dpi, image0, screenCoords + ScreenCoordsXY{ -12, 8 });
GfxDrawSprite(dpi, image1, screenCoords + ScreenCoordsXY{ -12, 8 });
2016-07-02 12:29:13 +01:00
}
2017-12-11 22:01:56 +00:00
2020-08-12 23:05:23 +01:00
void BannerObject::ReadJson(IReadObjectContext* context, json_t& root)
2017-12-11 22:01:56 +00:00
{
2020-08-12 23:05:23 +01:00
Guard::Assert(root.is_object(), "BannerObject::ReadJson expects parameter root to be object");
json_t properties = root["properties"];
2017-12-11 22:01:56 +00:00
2020-08-12 23:05:23 +01:00
if (properties.is_object())
{
2021-06-03 21:43:30 +01:00
_legacyType.scrolling_mode = Json::GetNumber<uint8_t>(properties["scrollingMode"]);
_legacyType.price = Json::GetNumber<money64>(properties["price"]);
2021-06-03 21:43:30 +01:00
_legacyType.flags = Json::GetFlags<uint8_t>(
2020-08-12 23:05:23 +01:00
properties,
{
{ "hasPrimaryColour", BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR },
});
2017-12-11 22:01:56 +00:00
2021-03-12 11:04:04 +01:00
SetPrimarySceneryGroup(ObjectEntryDescriptor(Json::GetString(properties["sceneryGroup"])));
2020-08-12 23:05:23 +01:00
}
2017-12-11 22:01:56 +00:00
2020-08-12 23:05:23 +01:00
PopulateTablesFromJson(context, root);
2017-12-11 22:01:56 +00:00
}