2018-12-05 20:33:45 +00:00
|
|
|
/*****************************************************************************
|
2024-12-31 20:30:04 +01:00
|
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
2018-12-05 20:33:45 +00:00
|
|
|
*
|
|
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
|
*
|
|
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "TerrainEdgeObject.h"
|
|
|
|
|
|
2021-03-27 13:48:27 +01:00
|
|
|
#include "../Context.h"
|
2024-10-15 17:39:54 +02:00
|
|
|
#include "../core/Guard.hpp"
|
2018-12-05 20:33:45 +00:00
|
|
|
#include "../core/IStream.hpp"
|
2020-10-02 11:31:20 +01:00
|
|
|
#include "../core/Json.hpp"
|
2018-12-05 20:33:45 +00:00
|
|
|
#include "../core/String.hpp"
|
|
|
|
|
#include "../drawing/Drawing.h"
|
2021-03-27 13:48:27 +01:00
|
|
|
#include "ObjectManager.h"
|
2018-12-05 20:33:45 +00:00
|
|
|
|
2024-07-26 09:59:58 +02:00
|
|
|
using namespace OpenRCT2;
|
|
|
|
|
|
2018-12-05 20:33:45 +00:00
|
|
|
void TerrainEdgeObject::Load()
|
|
|
|
|
{
|
|
|
|
|
GetStringTable().Sort();
|
2023-01-17 00:12:35 +01:00
|
|
|
NameStringId = LanguageAllocateObjectString(GetName());
|
2023-04-13 15:09:15 -04:00
|
|
|
IconImageId = LoadImages();
|
2018-12-05 20:33:45 +00:00
|
|
|
|
|
|
|
|
// First image is icon followed by edge images
|
|
|
|
|
BaseImageId = IconImageId + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TerrainEdgeObject::Unload()
|
|
|
|
|
{
|
2023-01-17 00:12:35 +01:00
|
|
|
LanguageFreeObjectString(NameStringId);
|
2023-04-13 15:09:15 -04:00
|
|
|
UnloadImages();
|
2018-12-05 20:33:45 +00:00
|
|
|
|
|
|
|
|
NameStringId = 0;
|
|
|
|
|
IconImageId = 0;
|
|
|
|
|
BaseImageId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 01:06:46 +03:00
|
|
|
void TerrainEdgeObject::DrawPreview(RenderTarget& rt, int32_t width, int32_t height) const
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2020-06-23 23:32:34 +02:00
|
|
|
auto screenCoords = ScreenCoordsXY{ width / 2, height / 2 };
|
2018-12-05 20:33:45 +00:00
|
|
|
|
2021-12-16 20:39:10 +00:00
|
|
|
auto imageId = ImageId(BaseImageId + 5);
|
2025-05-05 01:06:46 +03:00
|
|
|
GfxDrawSprite(rt, imageId, screenCoords + ScreenCoordsXY{ 8, -8 });
|
|
|
|
|
GfxDrawSprite(rt, imageId, screenCoords + ScreenCoordsXY{ 8, 8 });
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
void TerrainEdgeObject::ReadJson(IReadObjectContext* context, json_t& root)
|
2018-12-05 20:33:45 +00:00
|
|
|
{
|
2020-08-12 23:05:23 +01:00
|
|
|
Guard::Assert(root.is_object(), "TerrainEdgeObject::ReadJson expects parameter root to be object");
|
2018-12-05 20:33:45 +00:00
|
|
|
|
2020-08-12 23:05:23 +01:00
|
|
|
auto properties = root["properties"];
|
|
|
|
|
|
|
|
|
|
if (properties.is_object())
|
|
|
|
|
{
|
|
|
|
|
HasDoors = Json::GetBoolean(properties["hasDoors"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PopulateTablesFromJson(context, root);
|
2018-12-05 20:33:45 +00:00
|
|
|
}
|
2021-03-27 13:48:27 +01:00
|
|
|
|
|
|
|
|
TerrainEdgeObject* TerrainEdgeObject::GetById(ObjectEntryIndex entryIndex)
|
|
|
|
|
{
|
|
|
|
|
auto& objMgr = OpenRCT2::GetContext()->GetObjectManager();
|
2025-03-25 08:51:44 +01:00
|
|
|
return objMgr.GetLoadedObject<TerrainEdgeObject>(entryIndex);
|
2021-03-27 13:48:27 +01:00
|
|
|
}
|