mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Configurable autosave limit and prefix - ingame handling
This commit is contained in:
parent
0c9e23edfa
commit
fbf0bf78d6
@ -56,6 +56,7 @@
|
||||
#include "../lib/mapObjects/CGTownInstance.h"
|
||||
#include "../lib/mapObjects/MiscObjects.h"
|
||||
#include "../lib/mapObjects/ObjectTemplate.h"
|
||||
#include "../lib/mapping/CMapHeader.h"
|
||||
#include "../lib/pathfinder/CGPathNode.h"
|
||||
#include "../lib/CStack.h"
|
||||
#include "../lib/JsonNode.h"
|
||||
@ -192,24 +193,39 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player)
|
||||
|
||||
void CPlayerInterface::performAutosave()
|
||||
{
|
||||
std::string prefix = settings["session"]["saveprefix"].String();
|
||||
int frequency = static_cast<int>(settings["general"]["saveFrequency"].Integer());
|
||||
if(firstCall)
|
||||
if(frequency > 0 && cb->getDate() % frequency == 0)
|
||||
{
|
||||
autosaveCount = getLastIndex(prefix + "Autosave_");
|
||||
bool usePrefix = settings["general"]["useSavePrefix"].Bool();
|
||||
std::string prefix = std::string();
|
||||
|
||||
if(firstCall > 0) //new game, not loaded
|
||||
if(usePrefix)
|
||||
{
|
||||
int index = getLastIndex(prefix + "Newgame_");
|
||||
index %= SAVES_COUNT;
|
||||
cb->save("Saves/" + prefix + "Newgame_Autosave_" + std::to_string(index + 1));
|
||||
prefix = settings["general"]["savePrefix"].String();
|
||||
if(prefix.empty())
|
||||
{
|
||||
prefix = cb->getMapHeader()->name.substr(0, 5) + "_";
|
||||
}
|
||||
}
|
||||
|
||||
autosaveCount++;
|
||||
|
||||
int autosaveCountLimit = settings["general"]["autosaveCountLimit"].Integer();
|
||||
if(autosaveCountLimit > 0)
|
||||
{
|
||||
cb->save("Saves/" + prefix + "Autosave_" + std::to_string(autosaveCount));
|
||||
autosaveCount %= autosaveCountLimit;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string stringifiedDate = (cb->getDate(Date::MONTH) < 10
|
||||
? std::string("0") + std::to_string(cb->getDate(Date::MONTH))
|
||||
: std::to_string(cb->getDate(Date::MONTH)))
|
||||
+ std::to_string(cb->getDate(Date::WEEK))
|
||||
+ std::to_string(cb->getDate(Date::DAY_OF_WEEK));
|
||||
|
||||
cb->save("Saves/" + prefix + "Autosave_" + stringifiedDate);
|
||||
}
|
||||
firstCall = 0;
|
||||
}
|
||||
else if(frequency > 0 && cb->getDate() % frequency == 0)
|
||||
{
|
||||
cb->save("Saves/" + prefix + "Autosave_" + std::to_string(autosaveCount++ + 1));
|
||||
autosaveCount %= 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,6 @@ class CPlayerInterface : public CGameInterface, public IUpdateable
|
||||
// -1 - just loaded game; 1 - just started game; 0 otherwise
|
||||
int firstCall;
|
||||
int autosaveCount;
|
||||
static const int SAVES_COUNT = 5;
|
||||
|
||||
std::pair<const CCreatureSet *, const CCreatureSet *> lastBattleArmies;
|
||||
bool allowBattleReplay = false;
|
||||
|
@ -33,7 +33,10 @@
|
||||
"extraDump",
|
||||
"userRelativePointer",
|
||||
"relativePointerSpeedMultiplier",
|
||||
"longTouchTimeMilliseconds"
|
||||
"longTouchTimeMilliseconds",
|
||||
"autosaveCountLimit",
|
||||
"useSavePrefix",
|
||||
"savePrefix"
|
||||
],
|
||||
"properties" : {
|
||||
"playerName" : {
|
||||
@ -101,6 +104,18 @@
|
||||
"longTouchTimeMilliseconds" : {
|
||||
"type" : "number",
|
||||
"default" : 1000
|
||||
},
|
||||
"autosaveCountLimit" : {
|
||||
"type" : "number",
|
||||
"default": 5
|
||||
},
|
||||
"useSavePrefix" : {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"savePrefix" : {
|
||||
"type": "string",
|
||||
"default": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user