refactor: 录像系统指令

This commit is contained in:
AncTe committed 2026-09-13 16:38:19 +08:00
1 parent dd4e66a335
commit 46a38fa0c6
7 files changed
+47 -57

No files matched your search

+27 -24
View File
@@ -118,6 +118,24 @@ export class ReplaySandbox
this.forEachHook(hook => hook.onStopReplay?.());
}
/**
* 触发上一步指令的连续步骤后处理
*/
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;
}
async step(): Promise<boolean> {
if (!this.playing || this.ended) return false;
if (this.reader.expired) {
@@ -127,17 +145,20 @@ export class ReplaySandbox
const next = this.reader.read();
if (!next) {
// notExecuted
if (!(await this.finalizeLast())) {
return false;
const ne = await this.finalizeLast();
if (ne) {
this.last = -1;
this.ending = true;
}
this.last = -1;
this.ending = true;
return false;
}
// notExecuted
if (!(await this.finalizeLast())) {
return false;
if (next.command !== this.last) {
const ne = await this.finalizeLast();
if (!ne) {
return false;
}
}
this.last = next.command;
@@ -162,22 +183,4 @@ 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;
}
}