BoardState.CaptureSave/RestoreFromSave deep-copy every mutable field (grid, pieces, demands, transformers, buffers, stock, campaign progress) into a WorldSave slot. GameSim.QuickSave/QuickLoad expose slotted saves and emit StateSavedEvent / StateRestoredEvent — the latter carries a fresh BoardSnapshot so the presentation can rebuild board, pieces, trajectories, objectives, stock, camera, and control bar in one pass. F5/F9 trigger it in Main; harness gains quick_save/quick_load commands so UI tests can checkpoint a scenario and resume without replaying from scratch. Seven xUnit tests cover the roundtrip (including independence from post-save mutations, campaign state, and multi-slot isolation).
40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
namespace Chessistics.Engine.Model;
|
|
|
|
/// <summary>
|
|
/// Deep copy of every mutable field needed to restore a BoardState to an
|
|
/// earlier point. Used by QuickSave/QuickLoad for rapid iteration during
|
|
/// UI/UX testing and by the harness to restore checkpoints.
|
|
///
|
|
/// Immutable refs (defs, CampaignDef) are shared; mutable state (Pieces,
|
|
/// DemandState, buffers, stock, campaign progression) is copied by value.
|
|
/// </summary>
|
|
public sealed class WorldSave
|
|
{
|
|
public int Width { get; init; }
|
|
public int Height { get; init; }
|
|
public CellType[,] Grid { get; init; } = new CellType[0, 0];
|
|
public SimPhase Phase { get; init; }
|
|
public int TurnNumber { get; init; }
|
|
public int NextPieceId { get; init; }
|
|
|
|
public Dictionary<Coords, ProductionDef> Productions { get; init; } = new();
|
|
public Dictionary<Coords, int> ProductionBuffers { get; init; } = new();
|
|
public Dictionary<Coords, DemandState> Demands { get; init; } = new();
|
|
public Dictionary<Coords, TransformerDef> Transformers { get; init; } = new();
|
|
public Dictionary<Coords, int> TransformerInputBuffers { get; init; } = new();
|
|
public Dictionary<Coords, int> TransformerOutputBuffers { get; init; } = new();
|
|
public List<PieceState> Pieces { get; init; } = new();
|
|
public List<PieceState> DestroyedPieces { get; init; } = new();
|
|
public Dictionary<PieceKind, int> RemainingStock { get; init; } = new();
|
|
public HashSet<Coords> OccupiedCells { get; init; } = new();
|
|
|
|
public CampaignSaveData? Campaign { get; init; }
|
|
}
|
|
|
|
public sealed class CampaignSaveData
|
|
{
|
|
public int CurrentMissionIndex { get; init; }
|
|
public List<int> CompletedMissions { get; init; } = new();
|
|
public HashSet<PieceKind> AvailablePieceKinds { get; init; } = new();
|
|
public HashSet<PieceUpgrade> AvailableLevels { get; init; } = new();
|
|
}
|