diff --git a/packages-user/data-common/src/replay/system.ts b/packages-user/data-common/src/replay/system.ts index 7990424..c713d83 100644 --- a/packages-user/data-common/src/replay/system.ts +++ b/packages-user/data-common/src/replay/system.ts @@ -11,6 +11,7 @@ import { IReplaySandboxConfig, IReplaySystem, IReplaySystemHooks, + IReplaySystemSave, ReplayCommandWidth, ReplayParamValue } from './types'; @@ -23,7 +24,7 @@ export class ReplaySystem { replaying: boolean = false; sandbox: IReplaySandbox | null = null; - route: IReplayArray; + readonly route: IReplayArray; /** 所有注册的指令 */ private readonly commands: Map = new Map(); @@ -84,4 +85,22 @@ export class ReplaySystem this.sandbox?.stop(); this.sandbox = null; } + + saveState(): IReplaySystemSave { + return { + length: this.route.length, + commandWidth: this.route.commandWidth, + commandArray: this.route.getCommandArray(), + paramArray: this.route.getParamArray() + }; + } + + loadState(state: IReplaySystemSave): void { + this.route.setReplayArray( + state.commandWidth, + state.commandArray, + state.paramArray, + state.length + ); + } } diff --git a/packages-user/data-common/src/replay/types.ts b/packages-user/data-common/src/replay/types.ts index eed70e6..498780a 100644 --- a/packages-user/data-common/src/replay/types.ts +++ b/packages-user/data-common/src/replay/types.ts @@ -1,4 +1,5 @@ import { IHookable, IHookBase } from '@motajs/common'; +import { ISaveableContent } from '../save'; /** 录像指令码,数值属于录像格式的一部分 */ export const enum ReplayCommandCode { @@ -339,7 +340,19 @@ export interface IReplaySandboxConfig { save?: Map; } -export interface IReplaySystem extends IHookable { +export interface IReplaySystemSave { + /** 录像长度 */ + readonly length: number; + /** 指令位宽 */ + readonly commandWidth: number; + /** 指令数组 */ + readonly commandArray: ArrayBuffer; + /** 参数数组 */ + readonly paramArray: ArrayBuffer; +} + +export interface IReplaySystem + extends IHookable, ISaveableContent { /** 当前是否处在录像播放状态 */ readonly replaying: boolean; /** 当前正在播放的录像沙箱实例 */ diff --git a/packages-user/data-state/src/core.ts b/packages-user/data-state/src/core.ts index 0f4340b..35e45ab 100644 --- a/packages-user/data-state/src/core.ts +++ b/packages-user/data-state/src/core.ts @@ -238,6 +238,7 @@ export class CoreState implements ICoreState { this.addSaveableContent('@system/flags', this.flags); this.addSaveableContent('@system/maps', this.maps); this.addSaveableContent('@system/enemy', this.enemyManager); + this.addSaveableContent('@system/replay', this.replaySystem); // 初始化存档数据库,不要动 loading.once('coreInit', () => { this.saveSystem.init(`@game/${core.firstData.name}`);