refactor(replay): rewrite remaining commands and register in CoreState

- ReplayUseItemCommand / ReplayEquipCommand / ReplayUnequipCommand now extend
  BaseReplayCommand with fixed numeric params and per-false-position logger
  error codes (2006-2010); string item/slot params removed, autoUnload is a
  required bool.
- remove isNumber/isItem/isBoolean/isSlot/resolveSlot helpers; all logic now
  lives in the command classes.
- drop createReplayCommandItems/registerReplayCommandItems; CoreState owns a
  private registerReplayCommand() registering the eight stable codes directly.
- prune unused replay boundary types from replay/types.ts.
- fix ReplaySandbox: a replay ending on a run of moves now finalizes the
  trailing run through notExecuted (previously the last move never started).
- rewrite commands.test.ts for the base-class design and direct registration.

Verified: data type gate 0 in-scope; vitest 19 files / 112 tests pass; prettier
and eslint clean on touched files.
This commit is contained in:
AncTe committed 2026-09-13 15:39:12 +08:00
1 parent 37bfb77301
commit dd4e66a335
6 files changed
+398 -569

No files matched your search

+48 -7
View File
@@ -82,7 +82,14 @@ import {
import { isNil } from 'lodash-es';
import { DefaultHeroMoveTopImpl } from './hero';
import { createEventBuiltinRegistrations } from './event/registrations';
import { createReplayCommandItems, registerReplayCommandItems } from './replay';
import {
ReplayCommandCode,
ReplayEquipCommand,
ReplayMoveCommand,
ReplayTeleportCommand,
ReplayUnequipCommand,
ReplayUseItemCommand
} from './replay';
export class CoreState implements ICoreState {
// Layer 0 公共层,最底层的接口,不会依赖任何其他内容,一般是工具性接口及不需要存档的数据
@@ -252,18 +259,52 @@ export class CoreState implements ICoreState {
pathfinding.useMover(this.hero.location.mover);
this.pathfinding = pathfinding;
const replaySystem = new ReplaySystem();
registerReplayCommandItems(
replaySystem,
createReplayCommandItems(this)
);
this.replaySystem = replaySystem;
this.replaySystem = new ReplaySystem();
this.registerReplayCommand();
//#endregion
}
//#region 私有方法
/**
* 注册全部录像指令
*/
private registerReplayCommand() {
this.replaySystem.registerCommand(
ReplayCommandCode.Up,
new ReplayMoveCommand(this, FaceDirection.Up)
);
this.replaySystem.registerCommand(
ReplayCommandCode.Right,
new ReplayMoveCommand(this, FaceDirection.Right)
);
this.replaySystem.registerCommand(
ReplayCommandCode.Down,
new ReplayMoveCommand(this, FaceDirection.Down)
);
this.replaySystem.registerCommand(
ReplayCommandCode.Left,
new ReplayMoveCommand(this, FaceDirection.Left)
);
this.replaySystem.registerCommand(
ReplayCommandCode.AutoPathfindToPoint,
new ReplayTeleportCommand(this)
);
this.replaySystem.registerCommand(
ReplayCommandCode.UseItem,
new ReplayUseItemCommand(this)
);
this.replaySystem.registerCommand(
ReplayCommandCode.Equip,
new ReplayEquipCommand(this)
);
this.replaySystem.registerCommand(
ReplayCommandCode.Unequip,
new ReplayUnequipCommand(this)
);
}
/**
* 初始化图块存储对象
* @param data 旧样板图块定义对象