浏览代码

Configurable autosave limit and prefix - ingame handling

Dydzio 2 年之前
父节点
当前提交
fbf0bf78d6
共有 3 个文件被更改,包括 45 次插入15 次删除
  1. 29 13
      client/CPlayerInterface.cpp
  2. 0 1
      client/CPlayerInterface.h
  3. 16 1
      config/schemas/settings.json

+ 29 - 13
client/CPlayerInterface.cpp

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

+ 0 - 1
client/CPlayerInterface.h

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

+ 16 - 1
config/schemas/settings.json

@@ -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": ""
 				}
 			}
 		},