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;
}
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_delete(const char *name);
void FILESYSTEM_deleteLevelSaves(void);
#endif /* FILESYSTEMUTILS_H */

View file

@ -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;

View file

@ -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<CustomLevelStat> customlevelstats;

View file

@ -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
{

View file

@ -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;