Skip to content

Commit

Permalink
Merge pull request #3133 from EasyRPG-NewFeatures/Game_Browser-Autoru…
Browse files Browse the repository at this point in the history
…nGame

Game_Browser - Autorun a specific game
  • Loading branch information
fdelapena authored Dec 23, 2023
2 parents 77d97bb + 6742b0e commit af03ab5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
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

0 comments on commit af03ab5

Please sign in to comment.