1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 13:03:11 +01:00

Add API for getting the current game mode

This commit is contained in:
Ted John
2022-02-20 18:25:54 +00:00
parent 84fdd44e6a
commit 13d261d115
2 changed files with 30 additions and 2 deletions

View File

@@ -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" |

View File

@@ -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");