From 13d261d115929d4dc1e26a1cdf269e1b3683f643 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 20 Feb 2022 18:25:54 +0000 Subject: [PATCH] Add API for getting the current game mode --- distribution/openrct2.d.ts | 17 +++++++++++++++-- .../scripting/bindings/game/ScContext.hpp | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index d935a75867..a372e15268 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -173,7 +173,7 @@ declare global { /** * The user's current configuration. */ - configuration: Configuration; + readonly configuration: Configuration; /** * Shared generic storage for all plugins. Data is persistent across instances @@ -183,7 +183,7 @@ declare global { * the `set` method, do not rely on the file being saved by modifying your own * objects. Functions and other internal structures will not be persisted. */ - sharedStorage: Configuration; + readonly sharedStorage: Configuration; /** * Gets the storage for the current plugin if no name is specified. @@ -199,6 +199,12 @@ declare global { */ getParkStorage(pluginName?: string): Configuration; + /** + * The current mode / screen the game is in. Can be used for example to check + * whether the game is currently on the title screen or in the scenario editor. + */ + readonly mode: GameMode; + /** * Render the current state of the map and save to disc. * Useful for server administration and timelapse creation. @@ -370,6 +376,13 @@ declare global { transparent?: boolean; } + type GameMode = + "normal" | + "title" | + "scenario_editor" | + "track_designer" | + "track_manager"; + type ObjectType = "ride" | "small_scenery" | diff --git a/src/openrct2/scripting/bindings/game/ScContext.hpp b/src/openrct2/scripting/bindings/game/ScContext.hpp index 2dc64f7a0c..e2d960ac12 100644 --- a/src/openrct2/scripting/bindings/game/ScContext.hpp +++ b/src/openrct2/scripting/bindings/game/ScContext.hpp @@ -11,6 +11,7 @@ #ifdef ENABLE_SCRIPTING +# include "../../../OpenRCT2.h" # include "../../../actions/GameAction.h" # include "../../../interface/Screenshot.h" # include "../../../localisation/Formatting.h" @@ -110,6 +111,19 @@ namespace OpenRCT2::Scripting return result; } + std::string mode_get() + { + if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) + return "title"; + else if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) + return "scenario_editor"; + else if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) + return "track_designer"; + else if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) + return "track_manager"; + return "normal"; + } + void captureImage(const DukValue& options) { auto ctx = GetContext()->GetScriptEngine().GetContext(); @@ -439,6 +453,7 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScContext::configuration_get, nullptr, "configuration"); dukglue_register_property(ctx, &ScContext::sharedStorage_get, nullptr, "sharedStorage"); dukglue_register_method(ctx, &ScContext::getParkStorage, "getParkStorage"); + dukglue_register_property(ctx, &ScContext::mode_get, nullptr, "mode"); dukglue_register_method(ctx, &ScContext::captureImage, "captureImage"); dukglue_register_method(ctx, &ScContext::getObject, "getObject"); dukglue_register_method(ctx, &ScContext::getAllObjects, "getAllObjects");