From a13d26d866695ecd2221777121fa9880d229a77e Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 11 Aug 2021 20:54:02 -0700 Subject: [PATCH] Add option to delete all custom level save data To match the option to nuke all main game save data, there is also now an option to nuke all custom level save data separately (which is just all custom level quicksaves, along with stars for level completion). It has its own confirmation menu too. It does not delete any levels from the levels folder. --- desktop_version/src/FileSystemUtils.cpp | 30 +++++++++++++++++++++++++ desktop_version/src/FileSystemUtils.h | 1 + desktop_version/src/Game.cpp | 14 +++++++++++- desktop_version/src/Game.h | 2 ++ desktop_version/src/Input.cpp | 25 ++++++++++++++++++++- desktop_version/src/Render.cpp | 9 +++++++- 6 files changed, 78 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 38de9bf1..30706af5 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -1185,3 +1185,33 @@ bool FILESYSTEM_delete(const char *name) { return PHYSFS_delete(name) != 0; } + +static void levelSaveCallback(const char* filename) +{ + if (endsWith(filename, ".vvvvvv.vvv")) + { + if (!FILESYSTEM_delete(filename)) + { + printf("Error deleting %s\n", filename); + } + } +} + +void FILESYSTEM_deleteLevelSaves(void) +{ + int success; + + success = PHYSFS_enumerate( + "saves", + enumerateCallback, + (void*) levelSaveCallback + ); + + if (success == 0) + { + printf( + "Could not enumerate saves/: %s\n", + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()) + ); + } +} diff --git a/desktop_version/src/FileSystemUtils.h b/desktop_version/src/FileSystemUtils.h index c0269ce1..60b1309e 100644 --- a/desktop_version/src/FileSystemUtils.h +++ b/desktop_version/src/FileSystemUtils.h @@ -48,5 +48,6 @@ bool FILESYSTEM_openDirectoryEnabled(void); bool FILESYSTEM_openDirectory(const char *dname); bool FILESYSTEM_delete(const char *name); +void FILESYSTEM_deleteLevelSaves(void); #endif /* FILESYSTEMUTILS_H */ diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 76d7c9e4..8558a3fd 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -457,6 +457,16 @@ void Game::updatecustomlevelstats(std::string clevel, int cscore) savecustomlevelstats(); } +void Game::deletecustomlevelstats(void) +{ + customlevelstats.clear(); + + if (!FILESYSTEM_delete("saves/levelstats.vvv")) + { + puts("Error deleting levelstats.vvv"); + } +} + #define LOAD_ARRAY_RENAME(ARRAY_NAME, DEST) \ if (SDL_strcmp(pKey, #ARRAY_NAME) == 0 && pText[0] != '\0') \ { \ @@ -6061,7 +6071,8 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) option("toggle fps"); option("speedrun options"); option("advanced options"); - option("clear data"); + option("clear main game data"); + option("clear custom level data"); option("return"); menuyoff = -10; maxspacing = 15; @@ -6190,6 +6201,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) maxspacing = 10; break; case Menu::cleardatamenu: + case Menu::clearcustomdatamenu: option("no! don't delete"); option("yes, delete everything"); menuyoff = 64; diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 310403b0..c52cd954 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -52,6 +52,7 @@ namespace Menu accessibility, controller, cleardatamenu, + clearcustomdatamenu, setinvincibility, setslowdown, unlockmenu, @@ -423,6 +424,7 @@ public: void loadcustomlevelstats(void); void savecustomlevelstats(void); void updatecustomlevelstats(std::string clevel, int cscore); + void deletecustomlevelstats(void); std::vector customlevelstats; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 84c77b0a..bb86e810 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -905,7 +905,13 @@ static void menuactionpress(void) game.createmenu(Menu::cleardatamenu); map.nexttowercolour(); } - else if (game.currentmenuoption == gameplayoptionsoffset + 4) { + else if (game.currentmenuoption == gameplayoptionsoffset + 4) + { + music.playef(11); + game.createmenu(Menu::clearcustomdatamenu); + map.nexttowercolour(); + } + else if (game.currentmenuoption == gameplayoptionsoffset + 5) { //return to previous menu music.playef(11); game.returnmenu(); @@ -1482,6 +1488,23 @@ static void menuactionpress(void) break; } break; + case Menu::clearcustomdatamenu: + switch (game.currentmenuoption) + { + default: + music.playef(11); + break; + case 1: + game.deletecustomlevelstats(); + FILESYSTEM_deleteLevelSaves(); + music.playef(23); + game.flashlight = 5; + game.screenshake = 15; + break; + } + game.returnmenu(); + map.nexttowercolour(); + break; case Menu::playmodes: if (game.currentmenuoption == 0 && !game.nocompetitive()) //go to the time trial menu { diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 75333a19..cdc832dd 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -249,9 +249,15 @@ static void menurender(void) { //Clear Data graphics.bigprint(-1, 30, "Clear Data", tr, tg, tb, true); - graphics.Print(-1, 65, "Delete your save data", tr, tg, tb, true); + graphics.Print(-1, 65, "Delete your main game save data", tr, tg, tb, true); graphics.Print(-1, 75, "and unlocked play modes", tr, tg, tb, true); } + else if (game.currentmenuoption == gameplayoptionsoffset + 4) + { + graphics.bigprint(-1, 30, "Clear Data", tr, tg, tb, true); + graphics.Print(-1, 65, "Delete your custom level save data", tr, tg, tb, true); + graphics.Print(-1, 75, "and completion stars", tr, tg, tb, true); + } break; } @@ -543,6 +549,7 @@ static void menurender(void) graphics.Print( -1, 110, "delete your current saves...", tr, tg, tb, true); break; case Menu::cleardatamenu: + case Menu::clearcustomdatamenu: graphics.Print( -1, 100, "Are you sure you want to", tr, tg, tb, true); graphics.Print( -1, 110, "delete all your saved data?", tr, tg, tb, true); break;