Records every action dispatched on a signal, stamped with the current frame.
In a game the two signals are Input.onAction and Game.onFrame:
Input.onAction
Game.onFrame
const recorder = new Recorder(Input.onAction, game.onFrame);// ...play...const saved = serializeReplay(recorder.toJSON()); Copy
const recorder = new Recorder(Input.onAction, game.onFrame);// ...play...const saved = serializeReplay(recorder.toJSON());
The signals are parameters rather than imports so tests can drive a recorder with plain Signal instances instead of a whole Game.
Signal
Game
import { Recorder, Signal, serializeReplay } from '@datamoc/mw_games/core';const onAction = new Signal<string>();const onFrame = new Signal<number>();const recorder = new Recorder(onAction, onFrame);onFrame.dispatch(0);onAction.dispatch('confirm');const saved = serializeReplay(recorder.toJSON());recorder.stop(); Copy
import { Recorder, Signal, serializeReplay } from '@datamoc/mw_games/core';const onAction = new Signal<string>();const onFrame = new Signal<number>();const recorder = new Recorder(onAction, onFrame);onFrame.dispatch(0);onAction.dispatch('confirm');const saved = serializeReplay(recorder.toJSON());recorder.stop();
Detaches both listeners; safe to call twice.
A deep copy, safe to serialise or hand to a Player.
Player
Records every action dispatched on a signal, stamped with the current frame.
In a game the two signals are
Input.onActionandGame.onFrame:The signals are parameters rather than imports so tests can drive a recorder with plain
Signalinstances instead of a wholeGame.Example