import { DisplayedAction, PlayedMove } from '@gamepark/react-client'; import { Rules } from '@gamepark/rules-api'; import { MovePlayedLogDescription } from '../components'; import { MoveHistory } from './useFlatHistory'; export declare const CHECKPOINT_INTERVAL = 50; export type Checkpoint = { moveIndex: number; gameState: any; }; export type HistoryEngine = { rules: Rules; checkpoints: Checkpoint[]; movesProcessed: number; }; /** * Replays moves from the nearest checkpoint to produce the game state at a given move index. */ export declare const replayFromCheckpoint: (targetMoveIndex: number, checkpoints: Checkpoint[], allPlayedMoves: PlayedMove[], RulesClass: new (game: any, options?: any) => Rules, setup: any, gameOver: boolean | undefined, player: any, getAction: (actionId: string) => DisplayedAction | undefined) => any; export declare const saveCheckpointIfNeeded: (engine: HistoryEngine, moveIndex: number) => void; export declare const playMoveOnEngine: (engine: HistoryEngine, move: PlayedMove, getAction: (actionId: string) => DisplayedAction | undefined) => void; export declare const buildActionMap: (actions: DisplayedAction[] | undefined) => Map; export type LogContext = { logs?: { getMovePlayedLogDescription(move: any, context: any): MovePlayedLogDescription | undefined; }; RulesClass: new (game: any, options?: any) => Rules; setup: any; gameOver: boolean | undefined; player: any; getAction: (actionId: string) => DisplayedAction | undefined; }; export declare const getMoveEntry: (playedMove: PlayedMove, moveIndex: number, engine: HistoryEngine, allPlayedMoves: PlayedMove[], ctx: LogContext) => MoveHistory | undefined; export type RewindPlan = { /** Index of the first move that no longer matches the ones already processed (the first undone move). */ firstIndexChange: number; /** Index, in the current history, of the last entry that survives the rewind (-1 when none does). */ lastValidHistoryIndex: number; /** Index of the first move whose history entry must be rebuilt. Every move before it is replayed on the engine. */ newMovesStart: number; /** Checkpoints that are still usable, i.e. taken at or before `newMovesStart`. */ validCheckpoints: Checkpoint[]; /** Game state the engine must restart from, and the move index it corresponds to. */ restartState: any; restartIndex: number; }; /** * Computes how far back the engine must be rewound when moves are removed (undo). * * The engine has to be positioned exactly on `newMovesStart`, the first move whose history entry must be * rebuilt: every move before it is replayed once, and `processMovesSync` plays the remaining ones. A move * played twice would run its rule consequences twice (`onRuleEnd`, memory updates, ...) and silently corrupt * both the game state and every log entry computed from it afterwards. */ export declare const computeRewindPlan: (processedMoves: PlayedMove[], playedMoves: PlayedMove[], history: MoveHistory[], checkpoints: Checkpoint[], setup: any) => RewindPlan; /** * Rebuilds the engine at `plan.newMovesStart`, from the nearest usable checkpoint (or the setup). */ export declare const rewindEngine: (engine: HistoryEngine, plan: RewindPlan, playedMoves: PlayedMove[], ctx: LogContext) => void; /** * Processes a list of moves synchronously, returning history entries. * This is the core logic extracted from the hook for testability. */ export declare const processMovesSync: (moves: PlayedMove[], startIndex: number, engine: HistoryEngine, allPlayedMoves: PlayedMove[], ctx: LogContext) => MoveHistory[];