Skip to content

Commit

Permalink
improve load_park command
Browse files Browse the repository at this point in the history
allow to specify park via absolute path
make .sv6 filename extension optional
support .sc6 filename extension, but default to .sv6
  • Loading branch information
quadratrund committed Apr 5, 2020
1 parent a1a5bc5 commit 6bfdd90
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/openrct2/interface/InteractiveConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,14 +1319,28 @@ static int32_t cc_for_date([[maybe_unused]] InteractiveConsole& console, [[maybe

static int32_t cc_load_park([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
if (argv.size() > 0)
if (argv.size() < 1)
{
console.WriteFormatLine("Parameters required <filename>");
return 0;
}

char savePath[MAX_PATH];
if (String::IndexOf(argv[0].c_str(), '/') == SIZE_MAX && String::IndexOf(argv[0].c_str(), '\\') == SIZE_MAX)
{
char savePath[MAX_PATH];
// 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));

This comment has been minimized.

Copy link
@janisozaur

janisozaur Apr 5, 2020

Member

No reason to copy, add a pointer and set it either at savePath or at argv[0].c_str()

This comment has been minimized.

Copy link
@quadratrund

quadratrund Apr 5, 2020

Author Contributor

Maybe the filename extension is added later. In this case the pointer to argv[0].c_str() would not work. So you suggest to not look at the extension in this case?

This comment has been minimized.

Copy link
@janisozaur

janisozaur Apr 5, 2020

Member

ok then, good argument. Leave it as it.

}
if (!String::EndsWith(savePath, ".sv6", true) && !String::EndsWith(savePath, ".sc6", true))
{
path_append_extension(savePath, ".sv6", sizeof(savePath));
context_load_park_from_file(savePath);
}
context_load_park_from_file(savePath);

This comment has been minimized.

Copy link
@janisozaur

janisozaur Apr 5, 2020

Member

What happens when there is no file of the file is corrupt and can't be loaded? It would be best to report the error back to the user. At least it should report full path used.

This comment has been minimized.

Copy link
@quadratrund

quadratrund Apr 5, 2020

Author Contributor

The function context_load_park_from_file does error reporting. I tried it. For example load_park kkk says something like Unable to open '/home/quad/.config/OpenRCT2/save/kkk.sv6', if the file doesn't exist.

This comment has been minimized.

Copy link
@janisozaur

janisozaur Apr 5, 2020

Member

But it doesn't do so in the console.

return 1;
}

Expand Down Expand Up @@ -1701,7 +1715,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 <objectfilenodat>" },
{ "load_park", cc_load_park, "Load park from save directory with load_park parkname", "load_park <name>" },
{ "load_park", cc_load_park, "Load park from save directory or by absolute path", "load_park <filename>" },
{ "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 <window>." },
{ "quit", cc_close, "Closes the console.", "quit" },
Expand Down

0 comments on commit 6bfdd90

Please sign in to comment.