Chessistics/Scripts/Automation/AutomationFacade.cs
Samuel Bouchet 97bca7d7df Add Undo (Ctrl+Z) backed by the WorldSave checkpoint mechanism
GameSim snapshots the state before each undoable command
(PlacePiece / RemovePiece / MovePiece) into a bounded LinkedList stack
(max 32). Undo() pops the last checkpoint and emits StateRestoredEvent,
reusing the presentation rebuild path already wired for QuickLoad.

Ctrl+Z in Main triggers the engine method; the harness exposes undo()
for tests. QuickLoad clears the stack (fresh timeline). Seven unit tests
cover empty stack, place/remove/move undo, reverse-order multiple undos,
rejected commands not checkpointing, and post-simulation rewind.
2026-04-17 22:14:06 +02:00

69 lines
2 KiB
C#

using System;
using Chessistics.Engine.Simulation;
using Chessistics.Scripts.Input;
using Chessistics.Scripts.Presentation;
using Chessistics.Scripts.UI;
namespace Chessistics.Scripts.Automation;
/// <summary>
/// Thin pass-through from the automation harness to the runtime objects it needs.
/// The harness never talks to Main directly — only through this facade — so the
/// surface to audit stays tiny.
/// </summary>
internal class AutomationFacade
{
public Func<GameSim?> Sim { get; }
public InputMapper Input { get; }
public EventAnimator Animator { get; }
public PieceStockPanel Stock { get; }
public ControlBar ControlBar { get; }
public Action<string, int> LoadMission { get; }
public Action Play { get; }
public Action Pause { get; }
public Action Step { get; }
public Action TogglePlayPause { get; }
public Action BackToMenu { get; }
public Action<float> SetSpeed { get; }
public Action Quit { get; }
public Action QuickSave { get; }
public Action QuickLoad { get; }
public Action Undo { get; }
public AutomationFacade(
Func<GameSim?> sim,
InputMapper input,
EventAnimator animator,
PieceStockPanel stock,
ControlBar controlBar,
Action<string, int> loadMission,
Action play,
Action pause,
Action step,
Action togglePlayPause,
Action backToMenu,
Action<float> setSpeed,
Action quit,
Action quickSave,
Action quickLoad,
Action undo)
{
Sim = sim;
Input = input;
Animator = animator;
Stock = stock;
ControlBar = controlBar;
LoadMission = loadMission;
Play = play;
Pause = pause;
Step = step;
TogglePlayPause = togglePlayPause;
BackToMenu = backToMenu;
SetSpeed = setSpeed;
Quit = quit;
QuickSave = quickSave;
QuickLoad = quickLoad;
Undo = undo;
}
}