new structure, spawner, rebind

This commit is contained in:
Martin
2022-11-08 19:45:57 +01:00
parent 5b098af31d
commit 279218b4c3
45 changed files with 1157 additions and 302 deletions

View File

@@ -1,4 +1,4 @@
export interface ISignal<T> {
on(handler: (data: T) => void): void;
on(handler: (data: T) => void, thisArg: any): void;
off(handler: (data: T) => void): void;
}

View File

@@ -2,15 +2,23 @@ import { ISignal } from "./ISignal";
export class Signal<T> implements ISignal<T> {
private handlers: ((data: T) => void)[] = [];
private thisArgs: any[] = [];
public on(handler: (data: T) => void): void {
public on(handler: (data: T) => void, thisArg: any): void {
this.handlers.push(handler);
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);
}
public trigger(data: T): void {
[...this.handlers].forEach((handler) => handler(data));
//[...this.handlers].forEach((handler) => handler(data));
for (let i = 0; i < this.handlers.length; i++) {
this.handlers[i].call(this.thisArgs[i], data);
}
}
}

View File

@@ -0,0 +1,21 @@
export class GameTimer {
private targetDelay: number;
private currentDelay = 0;
public constructor(targetDelay: number) {
this.targetDelay = targetDelay;
}
public gameTick(deltaTime: number): void {
this.currentDelay += deltaTime;
}
public tryFinishPeriod(): boolean {
if (this.targetDelay <= this.currentDelay) {
this.currentDelay = 0;
return true;
} else {
return false;
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "930242d8-1406-4fe0-9dd7-6b700ecff471",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "de96cc65-e1ab-47ec-b1c5-74cd116d4dc4",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "9f621aea-cba9-4ef2-82af-6fae7a3a0fb7",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,3 @@
export async function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a920e5e1-f469-4f4b-ad81-fa27d49f0389",
"files": [],
"subMetas": {},
"userData": {}
}