mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 08:36:14 +00:00
new structure, spawner, rebind
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
assets/Scripts/Services/GameTimer.ts
Normal file
21
assets/Scripts/Services/GameTimer.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
9
assets/Scripts/Services/GameTimer.ts.meta
Normal file
9
assets/Scripts/Services/GameTimer.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "930242d8-1406-4fe0-9dd7-6b700ecff471",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
12
assets/Scripts/Services/UI.meta
Normal file
12
assets/Scripts/Services/UI.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "de96cc65-e1ab-47ec-b1c5-74cd116d4dc4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
12
assets/Scripts/Services/Utils.meta
Normal file
12
assets/Scripts/Services/Utils.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "9f621aea-cba9-4ef2-82af-6fae7a3a0fb7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
3
assets/Scripts/Services/Utils/AsyncUtils.ts
Normal file
3
assets/Scripts/Services/Utils/AsyncUtils.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export async function delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
9
assets/Scripts/Services/Utils/AsyncUtils.ts.meta
Normal file
9
assets/Scripts/Services/Utils/AsyncUtils.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a920e5e1-f469-4f4b-ad81-fa27d49f0389",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user