From 5b3db50bf39228831ebffc1e6949bdf53015e021 Mon Sep 17 00:00:00 2001 From: yucarl77 Date: Fri, 16 Sep 2022 15:44:28 +0800 Subject: [PATCH] feat: added streamer map icon --- src/controllers/index.ts | 1 + src/controllers/streamer/index.ts | 1 + src/controllers/streamer/mapIcon/index.ts | 103 ++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/controllers/streamer/index.ts create mode 100644 src/controllers/streamer/mapIcon/index.ts diff --git a/src/controllers/index.ts b/src/controllers/index.ts index ce6a1ce..77e724f 100644 --- a/src/controllers/index.ts +++ b/src/controllers/index.ts @@ -9,3 +9,4 @@ import "./netstats"; import "./gametext"; import "./menu"; import "./gangzone"; +import "./streamer"; diff --git a/src/controllers/streamer/index.ts b/src/controllers/streamer/index.ts new file mode 100644 index 0000000..723ef30 --- /dev/null +++ b/src/controllers/streamer/index.ts @@ -0,0 +1 @@ +export * from "./mapIcon"; diff --git a/src/controllers/streamer/mapIcon/index.ts b/src/controllers/streamer/mapIcon/index.ts new file mode 100644 index 0000000..badb37a --- /dev/null +++ b/src/controllers/streamer/mapIcon/index.ts @@ -0,0 +1,103 @@ +import { IDynamicMapIcon } from "@/interfaces"; +import { logger } from "@/logger"; +import { rgba } from "@/utils/colorUtils"; + +import { + IsValidDynamicMapIcon, + DestroyDynamicMapIcon, + StreamerDistances, + CreateDynamicMapIconEx, + CreateDynamicMapIcon, + MapIconStyles, +} from "omp-wrapper-streamer"; + +export class DynamicMapIcon { + private sourceInfo: IDynamicMapIcon; + private _id = -1; + public get id(): number { + return this._id; + } + constructor(mapIcon: IDynamicMapIcon) { + this.sourceInfo = mapIcon; + } + public create(): void | this { + if (this.id !== -1) + return logger.warn("[StreamerMapIcon]: Unable to create map icon again"); + let { + style, + streamdistance, + worldid, + interiorid, + playerid, + areaid, + priority, + } = this.sourceInfo; + const { x, y, z, type, color, extended } = this.sourceInfo; + style ??= MapIconStyles.LOCAL; + streamdistance ??= StreamerDistances.MAP_ICON_SD; + priority ??= 0; + if (extended) { + if (typeof worldid === "number") worldid = [-1]; + else worldid ??= [-1]; + if (typeof interiorid === "number") interiorid = [-1]; + else interiorid ??= [-1]; + if (typeof playerid === "number") playerid = [-1]; + else playerid ??= [-1]; + if (typeof areaid === "number") areaid = [-1]; + else areaid ??= [-1]; + + this._id = CreateDynamicMapIconEx( + x, + y, + z, + type, + rgba(color), + style, + streamdistance, + worldid, + interiorid, + playerid, + areaid, + priority + ); + + return this; + } + + if (Array.isArray(worldid)) worldid = -1; + else worldid ??= -1; + if (Array.isArray(interiorid)) interiorid = -1; + else interiorid ??= -1; + if (Array.isArray(playerid)) playerid = -1; + else playerid ??= -1; + if (Array.isArray(areaid)) areaid = -1; + else areaid ??= -1; + + this._id = CreateDynamicMapIcon( + x, + y, + z, + type, + rgba(color), + worldid, + interiorid, + playerid, + streamdistance, + style, + areaid, + priority + ); + return this; + } + public destroy(): void | this { + if (this.id === -1) + return logger.warn( + "[StreamerMapIcon]: Unable to destroy the map icon before create" + ); + DestroyDynamicMapIcon(this.id); + return this; + } + public static isValid(icon: DynamicMapIcon): boolean { + return IsValidDynamicMapIcon(icon.id); + } +}