New game from the panel instead of an uploaded save (2.9.3)
World & Backups -> Start new game (console: new-game, also when stopped): the save is backed up and replaced by a new-game marker (also as reset point). Joining players are told to start a new game; the server pulls the first player's save and from then on runs normally. Reset world returns to a new game when the reset point is one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+63
-2
@@ -19,7 +19,57 @@ public static class SaveStore
|
||||
public static string WorldPath(string dataDir) => Path.Combine(dataDir, "world.json");
|
||||
|
||||
public static bool HasSave(string dataDir) => File.Exists(Path.Combine(SavePath(dataDir), "defaultES2File.txt"));
|
||||
public static bool HasResetPoint(string dataDir) => File.Exists(Path.Combine(OriginalPath(dataDir), "defaultES2File.txt"));
|
||||
public static bool HasResetPoint(string dataDir) =>
|
||||
File.Exists(Path.Combine(OriginalPath(dataDir), "defaultES2File.txt")) || File.Exists(Path.Combine(OriginalPath(dataDir), NewGameMarker));
|
||||
|
||||
/// <summary>
|
||||
/// "Neues Spiel": statt Spielstand-Dateien liegt diese Markierung in data/save. Der erste Spieler startet im Spiel ein
|
||||
/// neues Spiel, der Server holt sich danach dessen Spielstand. Liegt sie im Reset-Punkt, geht "Reset world" zurück
|
||||
/// auf ein neues Spiel.
|
||||
/// </summary>
|
||||
public const string NewGameMarker = "NEWGAME.txt";
|
||||
public static bool IsNewGame(string dataDir) => !HasSave(dataDir) && File.Exists(Path.Combine(SavePath(dataDir), NewGameMarker));
|
||||
public static bool ResetPointIsNewGame(string dataDir) =>
|
||||
!File.Exists(Path.Combine(OriginalPath(dataDir), "defaultES2File.txt")) && File.Exists(Path.Combine(OriginalPath(dataDir), NewGameMarker));
|
||||
|
||||
/// <summary>Aktuellen Spielstand sichern und durch "neues Spiel" ersetzen (auch als Reset-Punkt).</summary>
|
||||
public static void MakeNewGame(string dataDir, bool alsoResetPoint)
|
||||
{
|
||||
Backup(dataDir);
|
||||
string save = SavePath(dataDir);
|
||||
Directory.CreateDirectory(save);
|
||||
foreach (string name in SaveFiles)
|
||||
{
|
||||
string file = Path.Combine(save, name);
|
||||
if (File.Exists(file)) File.Delete(file);
|
||||
}
|
||||
File.WriteAllText(Path.Combine(save, NewGameMarker), "MSCO: new game - the first player creates a fresh world");
|
||||
if (!alsoResetPoint) return;
|
||||
string original = OriginalPath(dataDir);
|
||||
if (Directory.Exists(original)) Directory.Delete(original, true);
|
||||
Directory.CreateDirectory(original);
|
||||
File.WriteAllText(Path.Combine(original, NewGameMarker), "MSCO: the reset point is a new game");
|
||||
}
|
||||
|
||||
/// <summary>Echter Spielstand ist da: die Neues-Spiel-Markierung entfernen.</summary>
|
||||
public static void ClearNewGameMarker(string dataDir)
|
||||
{
|
||||
string marker = Path.Combine(SavePath(dataDir), NewGameMarker);
|
||||
try { if (File.Exists(marker)) File.Delete(marker); } catch { }
|
||||
}
|
||||
|
||||
/// <summary>Server aus: neues Spiel einrichten.</summary>
|
||||
public static string NewGameOffline(string dataDir, string by)
|
||||
{
|
||||
try
|
||||
{
|
||||
MakeNewGame(dataDir, alsoResetPoint: true);
|
||||
ResetWorldFile(dataDir, full: true);
|
||||
}
|
||||
catch (Exception e) { return "Could not start a new game: " + e.Message; }
|
||||
GameServer.Log($"New game set up by {by} (server stopped) - the previous save game is in the backups");
|
||||
return "New game set up - start the server; the first player to join creates the new world";
|
||||
}
|
||||
|
||||
/// <summary>Backup-Ordner, neueste zuerst.</summary>
|
||||
public static List<string> BackupDirs(string dataDir)
|
||||
@@ -45,6 +95,15 @@ public static class SaveStore
|
||||
/// <summary>Aktuellen Spielstand als Reset-Punkt merken. Gibt einen Fehler zurück oder null.</summary>
|
||||
public static string SetResetPoint(string dataDir)
|
||||
{
|
||||
if (IsNewGame(dataDir))
|
||||
{
|
||||
// Neues Spiel als Reset-Punkt: "Reset world" startet wieder ein neues Spiel
|
||||
string orig = OriginalPath(dataDir);
|
||||
if (Directory.Exists(orig)) Directory.Delete(orig, true);
|
||||
Directory.CreateDirectory(orig);
|
||||
File.WriteAllText(Path.Combine(orig, NewGameMarker), "MSCO: the reset point is a new game");
|
||||
return null;
|
||||
}
|
||||
if (!HasSave(dataDir)) return "No save game to use as reset point";
|
||||
try
|
||||
{
|
||||
@@ -63,6 +122,7 @@ public static class SaveStore
|
||||
{
|
||||
string save = SavePath(dataDir);
|
||||
Directory.CreateDirectory(save);
|
||||
ClearNewGameMarker(dataDir);
|
||||
foreach (string name in SaveFiles)
|
||||
{
|
||||
string target = Path.Combine(save, name);
|
||||
@@ -212,7 +272,8 @@ public static class SaveStore
|
||||
{
|
||||
try
|
||||
{
|
||||
if (HasResetPoint(dataDir))
|
||||
if (ResetPointIsNewGame(dataDir)) MakeNewGame(dataDir, alsoResetPoint: false);
|
||||
else if (HasResetPoint(dataDir))
|
||||
{
|
||||
var files = ReadFolder(OriginalPath(dataDir));
|
||||
Backup(dataDir);
|
||||
|
||||
Reference in New Issue
Block a user