diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index 88916dc30b..550f5e969d 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -2229,6 +2229,11 @@ declare global { * Deletes this park from the title sequence. */ delete(): void; + + /** + * Loads this park. + */ + load(): void; } type TitleSequenceCommandType = diff --git a/src/openrct2-ui/scripting/ScTitleSequence.hpp b/src/openrct2-ui/scripting/ScTitleSequence.hpp index b67f10c73c..cb8e4413e6 100644 --- a/src/openrct2-ui/scripting/ScTitleSequence.hpp +++ b/src/openrct2-ui/scripting/ScTitleSequence.hpp @@ -12,7 +12,11 @@ #ifdef ENABLE_SCRIPTING # include +# include +# include # include +# include +# include # include # include # include @@ -184,11 +188,47 @@ namespace OpenRCT2::Scripting } } + void load() + { + auto seq = LoadTitleSequence(_titleSequencePath); + if (seq != nullptr) + { + auto index = GetIndex(*seq, _fileName); + if (index) + { + auto handle = TitleSequenceGetParkHandle(*seq, *index); + auto isScenario = ParkImporter::ExtensionIsScenario(handle->HintPath); + try + { + auto& objectMgr = OpenRCT2::GetContext()->GetObjectManager(); + auto parkImporter = std::unique_ptr(ParkImporter::Create(handle->HintPath)); + auto result = parkImporter->LoadFromStream(handle->Stream.get(), isScenario); + objectMgr.LoadObjects(result.RequiredObjects.data(), result.RequiredObjects.size()); + parkImporter->Import(); + + auto old = gLoadKeepWindowsOpen; + gLoadKeepWindowsOpen = true; + if (isScenario) + scenario_begin(); + else + game_load_init(); + gLoadKeepWindowsOpen = old; + } + catch (const std::exception&) + { + auto ctx = GetContext()->GetScriptEngine().GetContext(); + duk_error(ctx, DUK_ERR_ERROR, "Unable to load park."); + } + } + } + } + public: static void Register(duk_context* ctx) { dukglue_register_property(ctx, &ScTitleSequencePark::fileName_get, &ScTitleSequencePark::fileName_set, "fileName"); dukglue_register_method(ctx, &ScTitleSequencePark::delete_, "delete"); + dukglue_register_method(ctx, &ScTitleSequencePark::load, "load"); } private: