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;