mirror of
https://github.com/motajs/template.git
synced 2026-09-26 12:50:18 +08:00
feat: 录像存储
This commit is contained in:
parent
cee843981f
commit
82205a9dc1
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
/** 当前正在播放的录像沙箱实例 */
|
||||
|
||||
@ -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}`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user