mirror of
https://github.com/motajs/template.git
synced 2026-11-16 00:44:43 +08:00
refactor: 录像系统指令
This commit is contained in:
1 parent
dd4e66a335
commit
46a38fa0c6
7 files changed
+47
-57
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user