Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game_Browser - Autorun a specific game #3133

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,40 @@ bool FileFinder::IsRPG2kProjectWithRenames(const FilesystemView& fs) {
return !FileExtGuesser::GetRPG2kProjectWithRenames(fs).Empty();
}

bool FileFinder::OpenViewToEasyRpgFile(FilesystemView& fs) {
auto files = fs.ListDirectory();
if (!files) {
return false;
}

int items = 0;
std::string filename;

for (auto& file : *files) {
if (StringView(file.second.name).ends_with(".easyrpg")) {
++items;
if (items == 2) {
// Contains more than one game
return false;
}
filename = file.second.name;
}
}

if (filename.empty()) {
return false;
}

// One candidate to check
auto ep_fs = fs.Create(filename);
if (FileFinder::IsValidProject(ep_fs)) {
fs = ep_fs;
return true;
} else {
return false;
}
}

bool FileFinder::HasSavegame() {
return GetSavegames() > 0;
}
Expand Down
17 changes: 13 additions & 4 deletions src/filefinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,19 @@ namespace FileFinder {
bool IsSupportedArchiveExtension(std::string path);

/**
* @param p tree Tree to check
* @param p fs Tree to check
* @return Whether the tree contains a valid RPG2k(3) or EasyRPG project
*/
bool IsValidProject(const FilesystemView& fs);

/**
* @param p tree Tree to check
* @param p fs Tree to check
* @return Whether the tree contains a valid RPG2k(3) project
*/
bool IsRPG2kProject(const FilesystemView& fs);

/**
* @param p tree Tree to check
* @param p fs Tree to check
* @return Whether the tree contains a valid EasyRPG project
*/
bool IsEasyRpgProject(const FilesystemView& fs);
Expand All @@ -274,11 +274,20 @@ namespace FileFinder {
* Determines if the directory in question represents an RPG2k project with non-standard
* database, map tree, or map file names.
*
* @param tree The directory tree in question
* @param fs The directory tree in question
* @return true if this is likely an RPG2k project; false otherwise
*/
bool IsRPG2kProjectWithRenames(const FilesystemView& fs);

/**
* Determines if the directory contains a single file/directory ending in ".easyrpg" for use in the
* autostart feature.
*
* @param fs The directory tree to check. Is replaced with a view to the game for autorun.
* @return true when autorun is possible, fs contains the new view; when false fs is not modified
*/
bool OpenViewToEasyRpgFile(FilesystemView& fs);

/**
* Checks whether the save directory contains any savegame with name
* SaveXX.lsd (XX from 00 to 15).
Expand Down
2 changes: 1 addition & 1 deletion src/scene_gamebrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void Scene_GameBrowser::BootGame() {
return;
}

if (!FileFinder::IsValidProject(fs)) {
if (!FileFinder::IsValidProject(fs) && !FileFinder::OpenViewToEasyRpgFile(fs)) {
// Not a game: Open as directory
load_window->SetVisible(false);
game_loading = false;
Expand Down
3 changes: 2 additions & 1 deletion src/scene_logo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ bool Scene_Logo::DetectGame() {
}
#endif

if (FileFinder::IsValidProject(fs)) {
if (FileFinder::IsValidProject(fs) || FileFinder::OpenViewToEasyRpgFile(fs)) {
FileFinder::SetGameFilesystem(fs);
Player::CreateGameObjects();
detected_game = true;
}
Expand Down
Loading