From a6684603d8858e77b1d1597ab5e2f93bd6168ff5 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 16 Apr 2020 16:36:00 +0200 Subject: [PATCH] Load_Park feature for headless server (#11218) * Load_Park feature New feature "load_park name" from "save" folder. * Fix codestyle - * Fix codestyle - * Fixed typo for load_park load_park is now instead of [name] * improve load_park command allow to specify park via absolute path make .sv6 filename extension optional support .sc6 filename extension, but default to .sv6 * report success or failure of load_park to console Co-authored-by: quadratrund <56112624+quadratrund@users.noreply.github.com> --- src/openrct2/interface/InteractiveConsole.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 26fbb81bf8..5074025b50 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -40,6 +40,7 @@ #include "../object/ObjectManager.h" #include "../object/ObjectRepository.h" #include "../peep/Staff.h" +#include "../platform/platform.h" #include "../ride/Ride.h" #include "../ride/RideData.h" #include "../util/Util.h" @@ -1317,6 +1318,40 @@ static int32_t cc_for_date([[maybe_unused]] InteractiveConsole& console, [[maybe return 1; } +static int32_t cc_load_park([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv) +{ + if (argv.size() < 1) + { + console.WriteLine("Parameters required "); + return 0; + } + + char savePath[MAX_PATH]; + if (String::IndexOf(argv[0].c_str(), '/') == SIZE_MAX && String::IndexOf(argv[0].c_str(), '\\') == SIZE_MAX) + { + // no / or \ was included. File should be in save dir. + platform_get_user_directory(savePath, "save", sizeof(savePath)); + safe_strcat_path(savePath, argv[0].c_str(), sizeof(savePath)); + } + else + { + safe_strcpy(savePath, argv[0].c_str(), sizeof(savePath)); + } + if (!String::EndsWith(savePath, ".sv6", true) && !String::EndsWith(savePath, ".sc6", true)) + { + path_append_extension(savePath, ".sv6", sizeof(savePath)); + } + if (context_load_park_from_file(savePath)) + { + console.WriteFormatLine("Park %s was loaded successfully", savePath); + } + else + { + console.WriteFormatLine("Loading Park %s failed", savePath); + } + return 1; +} + static int32_t cc_save_park([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv) { if (argv.size() < 1) @@ -1727,6 +1762,7 @@ static constexpr const console_command console_command_table[] = { "Loading a scenery group will not load its associated objects.\n" "This is a safer method opposed to \"open object_selection\".", "load_object " }, + { "load_park", cc_load_park, "Load park from save directory or by absolute path", "load_park " }, { "object_count", cc_object_count, "Shows the number of objects of each type in the scenario.", "object_count" }, { "open", cc_open, "Opens the window with the give name.", "open ." }, { "quit", cc_close, "Closes the console.", "quit" },