mirror of
https://github.com/motajs/template.git
synced 2026-11-05 00:34:34 +08:00
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:
1 parent
37bfb77301
commit
dd4e66a335
6 files changed
+398
-569
No files matched your search
@@ -126,22 +126,18 @@ export class ReplaySandbox
|
||||
}
|
||||
const next = this.reader.read();
|
||||
if (!next) {
|
||||
// notExecuted
|
||||
if (!(await this.finalizeLast())) {
|
||||
return false;
|
||||
}
|
||||
this.last = -1;
|
||||
this.ending = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// notExecuted
|
||||
if (this.last !== -1) {
|
||||
const last = this.system.getCommand(this.last);
|
||||
if (!last) {
|
||||
logger.warn(157, this.last.toString());
|
||||
return false;
|
||||
}
|
||||
const success = (await last.notExecuted?.()) ?? true;
|
||||
if (!success) {
|
||||
logger.warn(175, this.last.toString());
|
||||
return false;
|
||||
}
|
||||
if (!(await this.finalizeLast())) {
|
||||
return false;
|
||||
}
|
||||
this.last = next.command;
|
||||
|
||||
@@ -166,4 +162,22 @@ export class ReplaySandbox
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发上一步指令的连续步骤后处理
|
||||
*/
|
||||
private async finalizeLast(): Promise<boolean> {
|
||||
if (this.last === -1) return true;
|
||||
const last = this.system.getCommand(this.last);
|
||||
if (!last) {
|
||||
logger.warn(157, this.last.toString());
|
||||
return false;
|
||||
}
|
||||
const success = (await last.notExecuted?.()) ?? true;
|
||||
if (!success) {
|
||||
logger.warn(175, this.last.toString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user