Refactor Game::savestats() to not use a default argument

In order to be able to fix the bug #556, I'm planning on adding
ScreenSettings* to the settings.vvv write function. However, that
entails adding another argument to Game::savesettings(), which is going
to be really messy given the default argument of Game::savestats().
That, combined with the fact that the code comment at the site of the
implementation of Game::savestats() being wrong (!!!), leads me to
believe that using default function arguments here isn't worth it.

Instead, what I've done is made it so callers are explicit about whether
or not they're calling savestats(), savesettings(), or both at the same
time. If they are calling both at the same time, then they will be using
a new function named savestatsandsettings().

In short, these are the interface changes:
 * bool Game::savestats(bool) has been removed
 * bool Game::savestatsandsettings() has been added
 * void Game::savestats_menu() has been renamed to
   void Game::savestatsandsettings_menu()
 * All previous callers of bool Game::savestats() are now using bool
   Game::savestatsandsettings()
 * The one caller of bool Game::savestats(bool) is now using bool
   Game::savestats()
This commit is contained in:
Misa
2020-12-21 16:03:19 -08:00
committed by Ethan Lee
parent 98effeee58
commit b62908f0f4
6 changed files with 61 additions and 56 deletions

View File

@@ -1334,7 +1334,7 @@ void Game::updatestate()
}
}
savestats();
savestatsandsettings();
graphics.fademode = 2;
music.fadeout();
@@ -3133,7 +3133,7 @@ void Game::updatestate()
}
savestats();
savestatsandsettings();
if (nodeathmode)
{
unlockAchievement("vvvvvvmaster"); //bloody hell
@@ -4447,7 +4447,7 @@ void Game::unlocknum( int t )
}
unlock[t] = true;
savestats();
savestatsandsettings();
#endif
}
@@ -4474,7 +4474,7 @@ void Game::loadstats(ScreenSettings* screen_settings)
{
// Save unlock.vvv only. Maybe we have a settings.vvv laying around too,
// and we don't want to overwrite that!
savestats(true);
savestats();
printf("No Stats found. Assuming a new player\n");
}
@@ -4736,7 +4736,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
}
}
bool Game::savestats(const bool stats_only /*= true*/)
bool Game::savestats()
{
tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc);
@@ -4812,20 +4812,22 @@ bool Game::savestats(const bool stats_only /*= true*/)
serializesettings(dataNode);
bool success = FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc);
if (!stats_only)
{
success &= savesettings();
}
return success;
return FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc);
}
void Game::savestats_menu()
bool Game::savestatsandsettings()
{
// Call Game::savestats(), but upon failure, go to the save error screen
if (!savestats() && !silence_settings_error)
const bool stats_saved = savestats();
const bool settings_saved = savesettings();
return stats_saved && settings_saved; // Not the same as `savestats() && savesettings()`!
}
void Game::savestatsandsettings_menu()
{
// Call Game::savestatsandsettings(), but upon failure, go to the save error screen
if (!savestatsandsettings() && !silence_settings_error)
{
createmenu(Menu::errorsavingsettings);
map.nexttowercolour();