feat: 录像存储

This commit is contained in:
AncTe committed 2026-09-14 18:17:37 +08:00
1 parent cee843981f
commit 82205a9dc1
3 files changed
+35 -2

No files matched your search

+20 -1
View File
@@ -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<number, IReplayCommand> = 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
);
}
}
+14 -1
View File
@@ -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<string, unknown>;
}
export interface IReplaySystem extends IHookable<IReplaySystemHooks> {
export interface IReplaySystemSave {
/** 录像长度 */
readonly length: number;
/** 指令位宽 */
readonly commandWidth: number;
/** 指令数组 */
readonly commandArray: ArrayBuffer;
/** 参数数组 */
readonly paramArray: ArrayBuffer;
}
export interface IReplaySystem
extends IHookable<IReplaySystemHooks>, ISaveableContent<IReplaySystemSave> {
/** 当前是否处在录像播放状态 */
readonly replaying: boolean;
/** 当前正在播放的录像沙箱实例 */