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).
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
namespace Chessistics.Engine.Model;
|
|
|
|
public class PieceState
|
|
{
|
|
public int Id { get; }
|
|
public PieceKind Kind { get; }
|
|
public int Level { get; }
|
|
public Coords StartCell { get; private set; }
|
|
public Coords EndCell { get; private set; }
|
|
public Coords CurrentCell { get; set; }
|
|
public CargoType? Cargo { get; set; }
|
|
public CargoType? CargoFilter { get; set; }
|
|
public int SocialStatus { get; }
|
|
public int PlacementOrder { get; }
|
|
|
|
public PieceState(int id, PieceKind kind, Coords startCell, Coords endCell, int placementOrder, int level = 1)
|
|
{
|
|
Id = id;
|
|
Kind = kind;
|
|
Level = level;
|
|
StartCell = startCell;
|
|
EndCell = endCell;
|
|
CurrentCell = startCell;
|
|
Cargo = null;
|
|
SocialStatus = PieceRules.GetSocialStatus(kind);
|
|
PlacementOrder = placementOrder;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the cell this piece will move to next.
|
|
/// </summary>
|
|
public Coords TargetCell => CurrentCell == StartCell ? EndCell : StartCell;
|
|
|
|
/// <summary>
|
|
/// Relocate this piece (drag & drop).
|
|
/// </summary>
|
|
public void SetPosition(Coords newStart, Coords newEnd)
|
|
{
|
|
StartCell = newStart;
|
|
EndCell = newEnd;
|
|
CurrentCell = newStart;
|
|
}
|
|
|
|
public PieceState Clone()
|
|
{
|
|
var clone = new PieceState(Id, Kind, StartCell, EndCell, PlacementOrder, Level)
|
|
{
|
|
CurrentCell = CurrentCell,
|
|
Cargo = Cargo,
|
|
CargoFilter = CargoFilter
|
|
};
|
|
return clone;
|
|
}
|
|
}
|