1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

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.
This commit is contained in:
Misa 2021-08-11 20:54:02 -07:00
parent 3a2265ef0d
commit a13d26d866
6 changed files with 78 additions and 3 deletions

View file

@ -1185,3 +1185,33 @@ bool FILESYSTEM_delete(const char *name)
{ {
return PHYSFS_delete(name) != 0; 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())
);
}
}

View file

@ -48,5 +48,6 @@ bool FILESYSTEM_openDirectoryEnabled(void);
bool FILESYSTEM_openDirectory(const char *dname); bool FILESYSTEM_openDirectory(const char *dname);
bool FILESYSTEM_delete(const char *name); bool FILESYSTEM_delete(const char *name);
void FILESYSTEM_deleteLevelSaves(void);
#endif /* FILESYSTEMUTILS_H */ #endif /* FILESYSTEMUTILS_H */

View file

@ -457,6 +457,16 @@ void Game::updatecustomlevelstats(std::string clevel, int cscore)
savecustomlevelstats(); 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) \ #define LOAD_ARRAY_RENAME(ARRAY_NAME, DEST) \
if (SDL_strcmp(pKey, #ARRAY_NAME) == 0 && pText[0] != '\0') \ 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("toggle fps");
option("speedrun options"); option("speedrun options");
option("advanced options"); option("advanced options");
option("clear data"); option("clear main game data");
option("clear custom level data");
option("return"); option("return");
menuyoff = -10; menuyoff = -10;
maxspacing = 15; maxspacing = 15;
@ -6190,6 +6201,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
maxspacing = 10; maxspacing = 10;
break; break;
case Menu::cleardatamenu: case Menu::cleardatamenu:
case Menu::clearcustomdatamenu:
option("no! don't delete"); option("no! don't delete");
option("yes, delete everything"); option("yes, delete everything");
menuyoff = 64; menuyoff = 64;

View file

@ -52,6 +52,7 @@ namespace Menu
accessibility, accessibility,
controller, controller,
cleardatamenu, cleardatamenu,
clearcustomdatamenu,
setinvincibility, setinvincibility,
setslowdown, setslowdown,
unlockmenu, unlockmenu,
@ -423,6 +424,7 @@ public:
void loadcustomlevelstats(void); void loadcustomlevelstats(void);
void savecustomlevelstats(void); void savecustomlevelstats(void);
void updatecustomlevelstats(std::string clevel, int cscore); void updatecustomlevelstats(std::string clevel, int cscore);
void deletecustomlevelstats(void);
std::vector<CustomLevelStat> customlevelstats; std::vector<CustomLevelStat> customlevelstats;

View file

@ -905,7 +905,13 @@ static void menuactionpress(void)
game.createmenu(Menu::cleardatamenu); game.createmenu(Menu::cleardatamenu);
map.nexttowercolour(); 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 //return to previous menu
music.playef(11); music.playef(11);
game.returnmenu(); game.returnmenu();
@ -1482,6 +1488,23 @@ static void menuactionpress(void)
break; break;
} }
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: case Menu::playmodes:
if (game.currentmenuoption == 0 && !game.nocompetitive()) //go to the time trial menu if (game.currentmenuoption == 0 && !game.nocompetitive()) //go to the time trial menu
{ {

View file

@ -249,9 +249,15 @@ static void menurender(void)
{ {
//Clear Data //Clear Data
graphics.bigprint(-1, 30, "Clear Data", tr, tg, tb, true); 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); 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; break;
} }
@ -543,6 +549,7 @@ static void menurender(void)
graphics.Print( -1, 110, "delete your current saves...", tr, tg, tb, true); graphics.Print( -1, 110, "delete your current saves...", tr, tg, tb, true);
break; break;
case Menu::cleardatamenu: case Menu::cleardatamenu:
case Menu::clearcustomdatamenu:
graphics.Print( -1, 100, "Are you sure you want to", tr, tg, tb, true); 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); graphics.Print( -1, 110, "delete all your saved data?", tr, tg, tb, true);
break; break;