From 6209d1e1a7a40df87e493673783470831ec90872 Mon Sep 17 00:00:00 2001 From: yucarl77 Date: Tue, 13 Sep 2022 18:41:34 +0800 Subject: [PATCH] feat: text draw skeleton --- .../textdraw/basePlayerTextDraw.ts | 3 +++ src/controllers/textdraw/baseTextDraw.ts | 1 + src/controllers/textdraw/index.ts | 3 +++ src/controllers/textdraw/textdrawBus.ts | 8 +++++++ src/controllers/textdraw/textdrawEvent.ts | 22 +++++++++++++++++++ src/interfaces/index.ts | 11 ++++++++++ 6 files changed, 48 insertions(+) create mode 100644 src/controllers/textdraw/basePlayerTextDraw.ts create mode 100644 src/controllers/textdraw/baseTextDraw.ts create mode 100644 src/controllers/textdraw/index.ts create mode 100644 src/controllers/textdraw/textdrawBus.ts create mode 100644 src/controllers/textdraw/textdrawEvent.ts diff --git a/src/controllers/textdraw/basePlayerTextDraw.ts b/src/controllers/textdraw/basePlayerTextDraw.ts new file mode 100644 index 0000000..283c693 --- /dev/null +++ b/src/controllers/textdraw/basePlayerTextDraw.ts @@ -0,0 +1,3 @@ +import { BaseTextDraw } from "./baseTextDraw"; + +export abstract class BasePlayerTextDraw extends BaseTextDraw {} diff --git a/src/controllers/textdraw/baseTextDraw.ts b/src/controllers/textdraw/baseTextDraw.ts new file mode 100644 index 0000000..16f3dc0 --- /dev/null +++ b/src/controllers/textdraw/baseTextDraw.ts @@ -0,0 +1 @@ +export abstract class BaseTextDraw {} diff --git a/src/controllers/textdraw/index.ts b/src/controllers/textdraw/index.ts new file mode 100644 index 0000000..3c811b7 --- /dev/null +++ b/src/controllers/textdraw/index.ts @@ -0,0 +1,3 @@ +export * from "./baseTextDraw"; +export * from "./basePlayerTextDraw"; +export * from "./textdrawEvent"; diff --git a/src/controllers/textdraw/textdrawBus.ts b/src/controllers/textdraw/textdrawBus.ts new file mode 100644 index 0000000..396e02d --- /dev/null +++ b/src/controllers/textdraw/textdrawBus.ts @@ -0,0 +1,8 @@ +import { EventBus } from "@/utils/eventBus"; + +export enum textDrawHooks { + created = "OnTextDrawCreate", + destroyed = "OnTextDrawDestroy", +} + +export const textDrawBus = new EventBus(); diff --git a/src/controllers/textdraw/textdrawEvent.ts b/src/controllers/textdraw/textdrawEvent.ts new file mode 100644 index 0000000..9abbf01 --- /dev/null +++ b/src/controllers/textdraw/textdrawEvent.ts @@ -0,0 +1,22 @@ +import { CommonTextDraw } from "@/interfaces"; +import { BasePlayerTextDraw } from "./basePlayerTextDraw"; +import { BaseTextDraw } from "./baseTextDraw"; +import { textDrawBus, textDrawHooks } from "./textdrawBus"; + +export abstract class BaseTextDrawEvent< + T extends BaseTextDraw, + PT extends BasePlayerTextDraw +> { + public readonly textDraws = new Set>(); + constructor() { + textDrawBus.on(textDrawHooks.created, (textDraw: CommonTextDraw) => { + this.textDraws.add(textDraw); + }); + textDrawBus.on( + textDrawHooks.destroyed, + (textDraw: CommonTextDraw) => { + this.textDraws.delete(textDraw); + } + ); + } +} diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 1a6db33..fedc180 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -1,3 +1,5 @@ +import { BasePlayerTextDraw } from "@/controllers/textdraw/basePlayerTextDraw"; +import { BaseTextDraw } from "@/controllers/textdraw/baseTextDraw"; import { DialogStylesEnum } from "../enums"; import { EventFunc, EventName } from "../types"; @@ -65,3 +67,12 @@ export interface IBaseGangZone { maxx: number; maxy: number; } + +export interface CommonTextDraw< + T extends BaseTextDraw, + PT extends BasePlayerTextDraw +> { + id: number; + global: boolean; + value: T | PT; +}