diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 1b0fdff98c..8af4dd3386 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -2327,11 +2327,11 @@ declare global { * The current tilt of the car in the X/Y axis. */ bankRotation: number; - - /** - * Whether the car sprite is reversed or not. - */ - isReversed: boolean; + + /** + * Whether the car sprite is reversed or not. + */ + isReversed: boolean; /** * The colour of the car. @@ -3511,8 +3511,9 @@ declare global { * Begins a new tool session. The cursor will change to the style specified by the * given tool descriptor and cursor events will be provided. * @param tool The properties and event handlers for the tool. + * @returns The tool that was activated. */ - activateTool(tool: ToolDesc): void; + activateTool(tool: ToolDesc): Tool; registerMenuItem(text: string, callback: () => void): void; diff --git a/src/openrct2-ui/scripting/CustomMenu.cpp b/src/openrct2-ui/scripting/CustomMenu.cpp index 73557bec04..b02d7e7cbb 100644 --- a/src/openrct2-ui/scripting/CustomMenu.cpp +++ b/src/openrct2-ui/scripting/CustomMenu.cpp @@ -221,7 +221,7 @@ namespace OpenRCT2::Scripting } } - void InitialiseCustomTool(ScriptEngine& scriptEngine, const DukValue& dukValue) + bool InitialiseCustomTool(ScriptEngine& scriptEngine, const DukValue& dukValue) { try { @@ -271,6 +271,7 @@ namespace OpenRCT2::Scripting ToolSet(*toolbarWindow, widgetIndex, static_cast(customTool.Cursor)); ActiveCustomTool = std::move(customTool); ActiveCustomTool->Start(); + return true; } } } @@ -278,6 +279,7 @@ namespace OpenRCT2::Scripting { duk_error(scriptEngine.GetContext(), DUK_ERR_ERROR, "Invalid parameters."); } + return false; } } // namespace OpenRCT2::Scripting diff --git a/src/openrct2-ui/scripting/CustomMenu.h b/src/openrct2-ui/scripting/CustomMenu.h index 0696344456..7708c5eb87 100644 --- a/src/openrct2-ui/scripting/CustomMenu.h +++ b/src/openrct2-ui/scripting/CustomMenu.h @@ -106,7 +106,7 @@ namespace OpenRCT2::Scripting extern std::vector> CustomShortcuts; void InitialiseCustomMenuItems(ScriptEngine& scriptEngine); - void InitialiseCustomTool(ScriptEngine& scriptEngine, const DukValue& dukValue); + bool InitialiseCustomTool(ScriptEngine& scriptEngine, const DukValue& dukValue); template<> DukValue ToDuk(duk_context* ctx, const CursorID& value); template<> CursorID FromDuk(const DukValue& s); diff --git a/src/openrct2-ui/scripting/ScUi.hpp b/src/openrct2-ui/scripting/ScUi.hpp index ec0386d134..e4b86ac5e1 100644 --- a/src/openrct2-ui/scripting/ScUi.hpp +++ b/src/openrct2-ui/scripting/ScUi.hpp @@ -312,9 +312,12 @@ namespace OpenRCT2::Scripting false); } - void activateTool(const DukValue& desc) + std::shared_ptr activateTool(const DukValue& desc) { - InitialiseCustomTool(_scriptEngine, desc); + if (InitialiseCustomTool(_scriptEngine, desc)) + return tool_get(); + else + return nullptr; } void registerMenuItem(std::string text, DukValue callback)