From 9b2ed0d641c60bae758eab82a3179a355e008ac0 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sun, 12 Aug 2018 23:08:39 +0200 Subject: [PATCH] Expose properties for path scenery --- distribution/openrct2.d.ts | 31 ++++- src/openrct2/scripting/ScTile.hpp | 182 ++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+), 3 deletions(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 9ed132bba7..da2171d8e0 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -58,18 +58,19 @@ export interface IDisposable { } export type TileElementType = - "surface" | "footpath-item"; + "surface" | "footpath"; export interface TileElement { type: TileElementType; - zBase: number; - zClearance: number; + baseHeight: number; + clearanceHeight: number; broken: boolean; /** * Gets the element as a specific type to access its properties */ asSurface(): SurfaceElement; + asFootpath(): FootpathElement; asTrack(): TrackElement; asSmallScenery(): SmallSceneryElement; asEntrance(): EntranceElement; @@ -88,6 +89,30 @@ export interface SurfaceElement extends TileElement { parkFences: number; } +export interface FootpathAddition { + type: number; + isBin: boolean; + isBench: boolean; + isLamp: boolean; + isBreakable: boolean; + isJumpingFountainWater: boolean; + isJumpingFountainSnow: boolean; + allowedOnQueue: boolean; + allowedOnSlope: boolean; + isQueueScreen: boolean; + + /** + * Remove the path addition + */ + remove(): void; +} + +export interface FootpathElement extends TileElement { + type: number; + isSloped: boolean; + addition: FootpathAddition; +} + export interface TrackElement extends TileElement { } diff --git a/src/openrct2/scripting/ScTile.hpp b/src/openrct2/scripting/ScTile.hpp index 06404d4e29..af38b9afbe 100644 --- a/src/openrct2/scripting/ScTile.hpp +++ b/src/openrct2/scripting/ScTile.hpp @@ -10,6 +10,8 @@ #pragma once #include "../common.h" +#include "../world/Footpath.h" +#include "../world/Scenery.h" #include "../world/Sprite.h" #include "../world/Surface.h" @@ -177,10 +179,188 @@ namespace OpenRCT2::Scripting class ScFootpathElement final : public ScTileElement { + class ScFootpathAddition + { + protected: + rct_tile_element* _element; + bool VerifyPathAdditionExists() + { + if (!footpath_element_has_path_scenery(_element)) + { + // TODO: Show warning in console that the path addition has been removed + return false; + } + return true; + } + + public: + ScFootpathAddition(ScFootpathElement* path) + : _element(path->_element) + { + } + + void Remove() + { + footpath_element_set_path_scenery(_element, 0); + } + + uint8_t type_get() + { + if (!VerifyPathAdditionExists()) + return 0; + return footpath_element_get_path_scenery(_element); + } + void type_set(uint8_t value) + { + footpath_element_set_path_scenery(_element, value); + } + + bool isBin_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN; + } + bool isBench_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BENCH; + } + bool isLamp_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP; + } + bool isBreakable_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_BREAKABLE; + } + bool isJumpingFountainWater_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_JUMPING_FOUNTAIN_WATER; + } + bool isJumpingFountainSnow_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_JUMPING_FOUNTAIN_SNOW; + } + bool allowedOnQueue_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_DONT_ALLOW_ON_QUEUE; + } + bool allowedOnSlope_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_DONT_ALLOW_ON_SLOPE; + } + bool isQueueScreen_get() + { + if (!VerifyPathAdditionExists()) + return false; + + auto index = footpath_element_get_path_scenery_index(_element); + auto sceneryEntry = get_footpath_item_entry(index); + return sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_QUEUE_SCREEN; + } + + static void Register(duk_context* ctx) + { + dukglue_register_method(ctx, &ScFootpathAddition::Remove, "remove"); + + dukglue_register_property(ctx, &type_get, &type_set, "type"); + dukglue_register_property(ctx, &isBin_get, nullptr, "isBin"); + dukglue_register_property(ctx, &isBench_get, nullptr, "isBench"); + dukglue_register_property(ctx, &isLamp_get, nullptr, "isLamp"); + dukglue_register_property(ctx, &isBreakable_get, nullptr, "isBreakable"); + dukglue_register_property(ctx, &isJumpingFountainWater_get, nullptr, "isJumpingFountainWater"); + dukglue_register_property(ctx, &isJumpingFountainSnow_get, nullptr, "isJumpingFountainSnow"); + dukglue_register_property(ctx, &allowedOnQueue_get, nullptr, "allowedOnQueue"); + dukglue_register_property(ctx, &allowedOnSlope_get, nullptr, "allowedOnSlope"); + dukglue_register_property(ctx, &isQueueScreen_get, nullptr, "isQueueScreen"); + } + }; + + uint8_t type_get() + { + return footpath_element_get_type(_element); + } + void type_set(uint8_t index) + { + auto entry = get_footpath_entry(index); + if (entry == nullptr) + { + // TODO: Give warning (most likely only happens when index > MAX_PATH_OBJECTS) + return; + } + footpath_element_set_type(_element, index); + } + + bool sloped_get() + { + return footpath_element_is_sloped(_element); + } + void slope_set(bool value) + { + footpath_element_set_sloped(_element, value); + } + + std::shared_ptr addition_get() + { + + if (!footpath_element_has_path_scenery(_element)) + return nullptr; + + return std::make_shared(this); + } + public: static void Register(duk_context* ctx) { + // Registe rshared properties (baseheight, clearance height, etc.) RegisterSharedProperties(ctx); + + // Register path addition properties (.addition.isBench, .addition.isLamp, etc.) + ScFootpathAddition::Register(ctx); + + // Specific properties + dukglue_register_property(ctx, &type_get, &type_set, "type"); + dukglue_register_property(ctx, &sloped_get, &slope_set, "isSloped"); + dukglue_register_property(ctx, &sloped_get, &slope_set, "isQueue"); + dukglue_register_property(ctx, &addition_get, nullptr, "addition"); } }; @@ -247,6 +427,7 @@ namespace OpenRCT2::Scripting void ScTileElement::Register(duk_context* ctx) { dukglue_register_method(ctx, &ScTileElement::getAs, "asSurface"); + dukglue_register_method(ctx, &ScTileElement::getAs, "asFootpath"); dukglue_register_method(ctx, &ScTileElement::getAs, "asTrack"); dukglue_register_method(ctx, &ScTileElement::getAs, "asSmallScenery"); dukglue_register_method(ctx, &ScTileElement::getAs, "asEntrance"); @@ -259,6 +440,7 @@ namespace OpenRCT2::Scripting // Register type specific properties ScSurfaceElement ::Register(ctx); + ScFootpathElement::Register(ctx); ScTrackElement ::Register(ctx); ScSmallSceneryElement ::Register(ctx); ScEntranceElement ::Register(ctx);