added temp enemy mover

This commit is contained in:
Martin
2022-11-14 16:35:47 +01:00
parent 279218b4c3
commit 3dd10f13ef
16 changed files with 212 additions and 23 deletions

View File

@@ -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;

View File

@@ -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);
}