feat: 允许追逐战过程中添加监听器

This commit is contained in:
unanmed 2024-10-06 22:56:58 +08:00
parent 9b718e4c93
commit 0f6f0137f5

View File

@ -194,11 +194,10 @@ export class Chase extends EventEmitter<ChaseEvent> {
* @param fn
*/
onTime(time: number, fn: (emitTime: number) => void) {
if (this.started) {
logger.error(1501);
return;
}
this.onTimeListener.push({ time, fn });
if (this.started) {
this.onTimeListener.sort((a, b) => a.time - b.time);
}
}
/**
@ -208,13 +207,12 @@ export class Chase extends EventEmitter<ChaseEvent> {
* @param fn
*/
onFloorTime(floor: FloorIds, time: number, fn: (emitTime: number) => void) {
if (this.started) {
logger.error(1501);
return;
}
this.onFloorTimeListener[floor] ??= [];
const list = this.onFloorTimeListener[floor];
list.push({ time, fn });
if (this.started) {
list.sort((a, b) => a.time - b.time);
}
}
private ensureLocListener(index: number) {
@ -242,10 +240,6 @@ export class Chase extends EventEmitter<ChaseEvent> {
fn: (x: number, y: number) => void,
once: boolean = false
) {
if (this.started) {
logger.error(1501);
return;
}
const map = core.status.maps[floor];
const { width } = map;
const index = x + y * width;