From 4404415aecb0db3009c698b0f0ce6968c57f66e8 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 5 Oct 2024 06:35:21 -0300 Subject: [PATCH] Fix #22891: getInstalledObject API function not implemented --- distribution/changelog.txt | 1 + src/openrct2/scripting/ScriptEngine.h | 2 +- .../scripting/bindings/object/ScObjectManager.cpp | 9 +++++++++ src/openrct2/scripting/bindings/object/ScObjectManager.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 63f3773c4f..7430bb19ea 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -37,6 +37,7 @@ - Fix: [#22808] Incorrect support rotation on some Mini Roller Coaster track pieces. - Fix: [#22857] Side-Friction Roller Coaster train clips through slopes. - Fix: [#22880] macOS builds lack asset packs and scenario patches. +- Fix: [#22891] [Plugin] getInstalledObject API function not implemented. - Fix: [objects#346] Invalid refund price for Brick Base Block scenery item. 0.4.14 (2024-09-01) diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 9bab44c971..9993840364 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -46,7 +46,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { - static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 102; + static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 103; // Versions marking breaking changes. static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33; diff --git a/src/openrct2/scripting/bindings/object/ScObjectManager.cpp b/src/openrct2/scripting/bindings/object/ScObjectManager.cpp index 8d4d0fa6ef..39742f16e4 100644 --- a/src/openrct2/scripting/bindings/object/ScObjectManager.cpp +++ b/src/openrct2/scripting/bindings/object/ScObjectManager.cpp @@ -22,6 +22,7 @@ using namespace OpenRCT2::Scripting; void ScObjectManager::Register(duk_context* ctx) { dukglue_register_property(ctx, &ScObjectManager::installedObjects_get, nullptr, "installedObjects"); + dukglue_register_method(ctx, &ScObjectManager::installedObject_get, "getInstalledObject"); dukglue_register_method(ctx, &ScObjectManager::load, "load"); dukglue_register_method(ctx, &ScObjectManager::unload, "unload"); dukglue_register_method(ctx, &ScObjectManager::getObject, "getObject"); @@ -44,6 +45,14 @@ std::vector> ScObjectManager::installedObject return result; } +std::shared_ptr ScObjectManager::installedObject_get(const std::string& identifier) const +{ + auto context = GetContext(); + auto& objectRepository = context->GetObjectRepository(); + auto object = objectRepository.FindObject(identifier); + return object != nullptr ? std::make_shared(object->Id) : nullptr; +} + DukValue ScObjectManager::load(const DukValue& p1, const DukValue& p2) { auto context = GetContext(); diff --git a/src/openrct2/scripting/bindings/object/ScObjectManager.h b/src/openrct2/scripting/bindings/object/ScObjectManager.h index 83fc87f5bb..4a440c019c 100644 --- a/src/openrct2/scripting/bindings/object/ScObjectManager.h +++ b/src/openrct2/scripting/bindings/object/ScObjectManager.h @@ -26,6 +26,7 @@ namespace OpenRCT2::Scripting static void Register(duk_context* ctx); std::vector> installedObjects_get() const; + std::shared_ptr installedObject_get(const std::string& identifier) const; DukValue load(const DukValue& p1, const DukValue& p2); void unload(const DukValue& p1, const DukValue& p2);