mirror of
				https://github.com/unanmed/HumanBreak.git
				synced 2025-11-04 15:12:58 +08:00 
			
		
		
		
	feat: 允许追逐战过程中添加监听器
This commit is contained in:
		
							parent
							
								
									9b718e4c93
								
							
						
					
					
						commit
						0f6f0137f5
					
				@ -194,11 +194,10 @@ export class Chase extends EventEmitter<ChaseEvent> {
 | 
				
			|||||||
     * @param fn 触发时执行的函数,函数的参数表示实际触发时间
 | 
					     * @param fn 触发时执行的函数,函数的参数表示实际触发时间
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    onTime(time: number, fn: (emitTime: number) => void) {
 | 
					    onTime(time: number, fn: (emitTime: number) => void) {
 | 
				
			||||||
        if (this.started) {
 | 
					 | 
				
			||||||
            logger.error(1501);
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        this.onTimeListener.push({ time, fn });
 | 
					        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 触发时执行的函数
 | 
					     * @param fn 触发时执行的函数
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    onFloorTime(floor: FloorIds, time: number, fn: (emitTime: number) => void) {
 | 
					    onFloorTime(floor: FloorIds, time: number, fn: (emitTime: number) => void) {
 | 
				
			||||||
        if (this.started) {
 | 
					 | 
				
			||||||
            logger.error(1501);
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        this.onFloorTimeListener[floor] ??= [];
 | 
					        this.onFloorTimeListener[floor] ??= [];
 | 
				
			||||||
        const list = this.onFloorTimeListener[floor];
 | 
					        const list = this.onFloorTimeListener[floor];
 | 
				
			||||||
        list.push({ time, fn });
 | 
					        list.push({ time, fn });
 | 
				
			||||||
 | 
					        if (this.started) {
 | 
				
			||||||
 | 
					            list.sort((a, b) => a.time - b.time);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private ensureLocListener(index: number) {
 | 
					    private ensureLocListener(index: number) {
 | 
				
			||||||
@ -242,10 +240,6 @@ export class Chase extends EventEmitter<ChaseEvent> {
 | 
				
			|||||||
        fn: (x: number, y: number) => void,
 | 
					        fn: (x: number, y: number) => void,
 | 
				
			||||||
        once: boolean = false
 | 
					        once: boolean = false
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
        if (this.started) {
 | 
					 | 
				
			||||||
            logger.error(1501);
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        const map = core.status.maps[floor];
 | 
					        const map = core.status.maps[floor];
 | 
				
			||||||
        const { width } = map;
 | 
					        const { width } = map;
 | 
				
			||||||
        const index = x + y * width;
 | 
					        const index = x + y * width;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user