UNPKG

narraleaf-react

Version:

A React visual novel player framework

49 lines (48 loc) 1.81 kB
import { Timeline } from "../../../game/player/Tasks"; import { Action } from "./action"; import { LiveGameEventToken } from "../types"; import { GameHistoryManager } from "./gameHistory"; import { StackModel, StackModelRawData } from "./stackModel"; import type { LiveGame } from "../game/liveGame"; export type ActionHistory<T extends Array<unknown> = any> = { action: Action; timeline?: Timeline; args: T; id: string; undo?: (...args: T) => void; rootStackSnapshot: StackModelRawData; stackModel: StackModel; }; export type ActionHistoryPushOptions = { timeline?: Timeline; stackModel: StackModel; action: Action; }; export declare class ActionHistoryManager { readonly liveGame: LiveGame; private history; private readonly maxHistorySize; private hooks; constructor(maxHistorySize: number | undefined, liveGame: LiveGame); /** * Push an action to the history */ push<T extends Array<any> = Array<any>>(props: ActionHistoryPushOptions, onUndo?: (...args: T) => void, args?: T): { id: string; }; /** * Undo all actions until the given id * * If the given id is not found, nothing will happen * @param id random id generated by push */ undoUntil(id: string): ActionHistory | null; undo(gameHistory: GameHistoryManager): ActionHistory | null; ableToUndo(gameHistory: GameHistoryManager): boolean; onUndo(callback: (affected: ActionHistory<any>[]) => void): LiveGameEventToken; offUndo(callback: (affected: ActionHistory<any>[]) => void): void; getHistory(): ActionHistory<any>[]; onHistoryLimit(callback: (removed: ActionHistory<any>[]) => void): LiveGameEventToken; offHistoryLimit(callback: (removed: ActionHistory<any>[]) => void): void; reset(): void; }