mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Configurable autosave limit and prefix - ingame handling
This commit is contained in:
@@ -56,6 +56,7 @@
|
|||||||
#include "../lib/mapObjects/CGTownInstance.h"
|
#include "../lib/mapObjects/CGTownInstance.h"
|
||||||
#include "../lib/mapObjects/MiscObjects.h"
|
#include "../lib/mapObjects/MiscObjects.h"
|
||||||
#include "../lib/mapObjects/ObjectTemplate.h"
|
#include "../lib/mapObjects/ObjectTemplate.h"
|
||||||
|
#include "../lib/mapping/CMapHeader.h"
|
||||||
#include "../lib/pathfinder/CGPathNode.h"
|
#include "../lib/pathfinder/CGPathNode.h"
|
||||||
#include "../lib/CStack.h"
|
#include "../lib/CStack.h"
|
||||||
#include "../lib/JsonNode.h"
|
#include "../lib/JsonNode.h"
|
||||||
@@ -192,24 +193,39 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player)
|
|||||||
|
|
||||||
void CPlayerInterface::performAutosave()
|
void CPlayerInterface::performAutosave()
|
||||||
{
|
{
|
||||||
std::string prefix = settings["session"]["saveprefix"].String();
|
|
||||||
int frequency = static_cast<int>(settings["general"]["saveFrequency"].Integer());
|
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_");
|
prefix = settings["general"]["savePrefix"].String();
|
||||||
index %= SAVES_COUNT;
|
if(prefix.empty())
|
||||||
cb->save("Saves/" + prefix + "Newgame_Autosave_" + std::to_string(index + 1));
|
{
|
||||||
|
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
|
// -1 - just loaded game; 1 - just started game; 0 otherwise
|
||||||
int firstCall;
|
int firstCall;
|
||||||
int autosaveCount;
|
int autosaveCount;
|
||||||
static const int SAVES_COUNT = 5;
|
|
||||||
|
|
||||||
std::pair<const CCreatureSet *, const CCreatureSet *> lastBattleArmies;
|
std::pair<const CCreatureSet *, const CCreatureSet *> lastBattleArmies;
|
||||||
bool allowBattleReplay = false;
|
bool allowBattleReplay = false;
|
||||||
|
|||||||
@@ -33,7 +33,10 @@
|
|||||||
"extraDump",
|
"extraDump",
|
||||||
"userRelativePointer",
|
"userRelativePointer",
|
||||||
"relativePointerSpeedMultiplier",
|
"relativePointerSpeedMultiplier",
|
||||||
"longTouchTimeMilliseconds"
|
"longTouchTimeMilliseconds",
|
||||||
|
"autosaveCountLimit",
|
||||||
|
"useSavePrefix",
|
||||||
|
"savePrefix"
|
||||||
],
|
],
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"playerName" : {
|
"playerName" : {
|
||||||
@@ -101,6 +104,18 @@
|
|||||||
"longTouchTimeMilliseconds" : {
|
"longTouchTimeMilliseconds" : {
|
||||||
"type" : "number",
|
"type" : "number",
|
||||||
"default" : 1000
|
"default" : 1000
|
||||||
|
},
|
||||||
|
"autosaveCountLimit" : {
|
||||||
|
"type" : "number",
|
||||||
|
"default": 5
|
||||||
|
},
|
||||||
|
"useSavePrefix" : {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"savePrefix" : {
|
||||||
|
"type": "string",
|
||||||
|
"default": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user