From bcdac632a4ce9e96e3ea96694058c528dc830f6c Mon Sep 17 00:00:00 2001 From: Stephan Spengler Date: Sat, 6 Jun 2026 21:31:03 +0200 Subject: [PATCH] Add footpath object flags to API (#26322) * add footpath object flags to API * Add changelog --------- Co-authored-by: Tulio Leao --- distribution/changelog.txt | 1 + distribution/scripting/openrct2.d.ts | 6 ++++ src/openrct2/scripting/ScriptEngine.h | 2 +- .../scripting/bindings/object/ScObject.hpp | 33 +++++++++++++++++++ .../bindings/object/ScObjectManager.cpp | 4 +++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f19f8ad30d..17cda94f16 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.5.2 (in development) ------------------------------------------------------------------------ +- Improved: [#26322] Add footpath flags to FootpathSurfaceObject in the plugin API. - Improved: [#26566] Improve the performance of sorting sprites. - Fix: [#26350] ListViews altered by plugins post their creation are not invalidated. - Fix: [#26565] Game crashes when switching to another tab in the guest window. diff --git a/distribution/scripting/openrct2.d.ts b/distribution/scripting/openrct2.d.ts index 3254036ec1..e0846fa5c2 100644 --- a/distribution/scripting/openrct2.d.ts +++ b/distribution/scripting/openrct2.d.ts @@ -2263,6 +2263,10 @@ declare global { } + interface FootpathSurfaceObject extends LoadedImageObject { + readonly flags: number; + } + interface FootpathAdditionObject extends SceneryObject { } @@ -5775,6 +5779,7 @@ declare global { getObject(type: "small_scenery", index: number): SmallSceneryObject; getObject(type: "large_scenery", index: number): LargeSceneryObject; getObject(type: "wall", index: number): WallObject; + getObject(type: "footpath_surface", index: number): FootpathSurfaceObject; getObject(type: "footpath_addition", index: number): FootpathAdditionObject; getObject(type: "banner", index: number): BannerObject; getObject(type: "scenery_group", index: number): SceneryGroupObject; @@ -5788,6 +5793,7 @@ declare global { getAllObjects(type: "small_scenery"): SmallSceneryObject[]; getAllObjects(type: "large_scenery"): LargeSceneryObject[]; getAllObjects(type: "wall"): WallObject[]; + getAllObjects(type: "footpath_surface"): FootpathSurfaceObject[]; getAllObjects(type: "footpath_addition"): FootpathAdditionObject[]; getAllObjects(type: "banner"): BannerObject[]; getAllObjects(type: "scenery_group"): SceneryGroupObject[]; diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index f51f3a8c61..0042ccf60d 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -43,7 +43,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { // Grepped from CI (.github/workflows/publish-plugin-types.yml); keep the format `kPluginApiVersion = N`. - static constexpr int32_t kPluginApiVersion = 113; + static constexpr int32_t kPluginApiVersion = 114; // Versions marking breaking changes. static constexpr int32_t kApiVersionPeepDeprecation = 33; diff --git a/src/openrct2/scripting/bindings/object/ScObject.hpp b/src/openrct2/scripting/bindings/object/ScObject.hpp index 6a73890d7c..9f3d5defd4 100644 --- a/src/openrct2/scripting/bindings/object/ScObject.hpp +++ b/src/openrct2/scripting/bindings/object/ScObject.hpp @@ -12,6 +12,7 @@ #ifdef ENABLE_SCRIPTING #include "../../../Context.h" + #include "../../../object/FootpathSurfaceObject.h" #include "../../../object/LargeSceneryObject.h" #include "../../../object/ObjectManager.h" #include "../../../object/RideObject.h" @@ -899,6 +900,38 @@ namespace OpenRCT2::Scripting } }; + class ScFootpathSurfaceObject final : public ScObject + { + public: + static JSValue New(JSContext* ctx, ObjectType type, int32_t index) + { + JSValue obj = ScObject::New(ctx, type, index); + AddFuncs(ctx, obj); + return obj; + } + + private: + static void AddFuncs(JSContext* ctx, JSValue obj) + { + static constexpr JSCFunctionListEntry funcs[] = { + JS_CGETSET_DEF("flags", ScFootpathSurfaceObject::flags_get, nullptr), + }; + JS_SetPropertyFunctionList(ctx, obj, funcs, std::size(funcs)); + } + + static JSValue flags_get(JSContext* ctx, JSValue thisVal) + { + auto footpathObject = GetFootpathSurfaceObject(thisVal); + return JS_NewUint32(ctx, footpathObject != nullptr ? footpathObject->Flags : 0); + } + + protected: + static FootpathSurfaceObject* GetFootpathSurfaceObject(JSValue thisVal) + { + return static_cast(GetObject(thisVal)); + } + }; + class ScSceneryGroupObject final : public ScObject { public: diff --git a/src/openrct2/scripting/bindings/object/ScObjectManager.cpp b/src/openrct2/scripting/bindings/object/ScObjectManager.cpp index 7c344a5ec4..d4a02c1c24 100644 --- a/src/openrct2/scripting/bindings/object/ScObjectManager.cpp +++ b/src/openrct2/scripting/bindings/object/ScObjectManager.cpp @@ -306,6 +306,10 @@ JSValue ScObjectManager::CreateScObject(JSContext* ctx, ObjectType type, int32_t { return ScBannerObject::New(ctx, type, index); } + case ObjectType::footpathSurface: + { + return ScFootpathSurfaceObject::New(ctx, type, index); + } case ObjectType::sceneryGroup: { return ScSceneryGroupObject::New(ctx, type, index);