From 0f6f0137f5d4c76454088606dd7fbfd96b43c3b3 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 6 Oct 2024 22:56:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E8=BF=BD=E9=80=90?= =?UTF-8?q?=E6=88=98=E8=BF=87=E7=A8=8B=E4=B8=AD=E6=B7=BB=E5=8A=A0=E7=9B=91?= =?UTF-8?q?=E5=90=AC=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/chase/chase.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/plugin/chase/chase.ts b/src/plugin/chase/chase.ts index 53ef1a2..a0793cc 100644 --- a/src/plugin/chase/chase.ts +++ b/src/plugin/chase/chase.ts @@ -194,11 +194,10 @@ export class Chase extends EventEmitter { * @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 { * @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 { 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;