mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
added temp enemy mover
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export interface ISignal<T> {
|
||||
on(handler: (data: T) => void, thisArg: any): void;
|
||||
off(handler: (data: T) => void): void;
|
||||
|
@@ -1,3 +1,5 @@
|
||||
// Need to capture *this*
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { ISignal } from "./ISignal";
|
||||
|
||||
export class Signal<T> implements ISignal<T> {
|
||||
@@ -9,14 +11,12 @@ export class Signal<T> implements ISignal<T> {
|
||||
this.thisArgs.push(thisArg);
|
||||
}
|
||||
public off(handler: (data: T) => void): void {
|
||||
console.log("[OFF] " + this.handlers.length);
|
||||
this.handlers = this.handlers.filter((h) => h !== handler);
|
||||
console.log("[OFF] >> " + this.handlers.length);
|
||||
const index: number = this.handlers.indexOf(handler);
|
||||
this.handlers.splice(index, 1);
|
||||
this.thisArgs.splice(index, 1);
|
||||
}
|
||||
|
||||
public trigger(data: T): void {
|
||||
//[...this.handlers].forEach((handler) => handler(data));
|
||||
|
||||
for (let i = 0; i < this.handlers.length; i++) {
|
||||
this.handlers[i].call(this.thisArgs[i], data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user