Skip to content

Commit

Permalink
Add --from-datadir command line option
Browse files Browse the repository at this point in the history
Only load from physfs path if --from-datadir is specified
  • Loading branch information
tobbi committed Mar 7, 2022
1 parent de704bd commit e0f5200
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/supertux/command_line_arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ CommandLineArguments::print_help(const char* arg0) const
<< _("Game Options:") << "\n"
<< _(" --edit-level Open given level in editor") << "\n"
<< _(" --resave Loads given level and saves it") << "\n"
<< _(" --from-datadir Indicates that the LEVELFILE path is relative to the data dir. Only used if --edit-level is specified") << "\n"
<< _(" --show-fps Display framerate in levels") << "\n"
<< _(" --no-show-fps Do not display framerate in levels") << "\n"
<< _(" --show-pos Display player's current position") << "\n"
Expand Down Expand Up @@ -396,6 +397,10 @@ CommandLineArguments::parse_args(int argc, char** argv)
{
editor = true;
}
else if (arg == "--from-datadir")
{
from_datadir = true;
}
else if (arg == "--resave")
{
resave = true;
Expand Down
1 change: 1 addition & 0 deletions src/supertux/command_line_arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CommandLineArguments final
boost::optional<std::string> repository_url;

boost::optional<bool> editor;
boost::optional<bool> from_datadir;
boost::optional<bool> resave;

// boost::optional<std::string> locale;
Expand Down
15 changes: 10 additions & 5 deletions src/supertux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,15 @@ Main::launch_game(const CommandLineArguments& args)
else if (args.editor)
{
auto level_file = start_level;
auto fileExists = PHYSFS_exists(level_file.c_str());
if(!fileExists)
bool file_exists = false;
if(args.from_datadir)
{
fileExists = FileSystem::exists(level_file);
if(fileExists)
file_exists = PHYSFS_exists(level_file.c_str());
}
else
{
file_exists = FileSystem::exists(level_file);
if(file_exists)
{
auto dirname = FileSystem::dirname(level_file) + "/";
auto filename = FileSystem::basename(level_file);
Expand All @@ -549,7 +553,8 @@ Main::launch_game(const CommandLineArguments& args)
level_file = filename;
}
}
if (fileExists) {
if (file_exists)
{
auto editor = std::make_unique<Editor>();
editor->set_level(level_file);
editor->setup();
Expand Down

0 comments on commit e0f5200

Please sign in to comment.