Skip to content

Commit

Permalink
feat: added dynamic areas natives and callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Sep 24, 2022
1 parent 6d8ff9f commit d8fc1ce
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omp-node-lib",
"version": "0.1.7",
"version": "0.1.8",
"description": "Better with omp-node-ts",
"main": "dist/bundle.js",
"types": "dist/bundle.d.ts",
Expand Down
3 changes: 0 additions & 3 deletions src/controllers/menu/baseMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ export class BaseMenu {
return logger.error("[BaseMenu]: Wrong number of rows");
fns.DisableMenuRow(this.id, row);
}
public static isValid<M extends BaseMenu>(menu: M): boolean {
return fns.IsValidMenu(menu.id);
}
public isValid(): boolean {
return fns.IsValidMenu(this.id);
}
Expand Down
3 changes: 0 additions & 3 deletions src/controllers/streamer/3dtext/base3DText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ export class Dynamic3DTextLabel {
DestroyDynamic3DTextLabel(this.id);
return this;
}
public static isValid(textLabel: Dynamic3DTextLabel): boolean {
return IsValidDynamic3DTextLabel(textLabel.id);
}
public isValid(): boolean {
return IsValidDynamic3DTextLabel(this.id);
}
Expand Down
3 changes: 0 additions & 3 deletions src/controllers/streamer/actor/baseActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export class DynamicActor {
actorBus.emit(actorHooks.destroyed, this);
return this;
}
public static isValid(actor: DynamicActor): boolean {
return ows.IsValidDynamicActor(actor.id);
}
public isValid(): boolean {
return ows.IsValidDynamicActor(this.id);
}
Expand Down
188 changes: 188 additions & 0 deletions src/controllers/streamer/area/baseArea.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { logger } from "@/logger";
import { InvalidEnum } from "@/enums";
import { BasePlayer } from "@/controllers/player";
import { BaseVehicle } from "@/controllers/vehicle";
import { DynamicObject } from "@/controllers/streamer";
import { TDynamicArea, TDynamicAreaTypes } from "@/types";
import * as ows from "omp-wrapper-streamer";
import { areaBus, areaHooks } from "./areaBus";
Expand Down Expand Up @@ -206,4 +210,188 @@ export class DynamicArea {
areaBus.emit(areaHooks.destroyed, this);
return this;
}
public isValid(): boolean {
if (this.id === -1) return false;
return ows.IsValidDynamicArea(this.id);
}
public getType(): void | ows.StreamerAreaTypes {
if (this.id !== -1)
return logger.warn("[StreamerArea]: Unable to get type before create");
return ows.GetDynamicAreaType(this.id);
}
public getPolygonPoints(): void | number[] {
if (this.id !== -1)
return logger.warn(
"[StreamerArea]: Unable to get polygon points before create"
);
if (this.type !== "polygon") return undefined;
return ows.GetDynamicPolygonPoints(this.id);
}
public getPolygonNumberPoints(): void | number {
if (this.id !== -1)
return logger.warn(
"[StreamerArea]: Unable to get polygon points number before create"
);
if (this.type !== "polygon") return undefined;
return ows.GetDynamicPolygonNumberPoints(this.id);
}
public isPlayerIn<P extends BasePlayer>(player: P, recheck = false): boolean {
if (this.id === -1) return false;
return ows.IsPlayerInDynamicArea(player.id, this.id, recheck);
}
public static isPlayerInAny<P extends BasePlayer>(
player: P,
recheck = false
): boolean {
return ows.IsPlayerInAnyDynamicArea(player.id, recheck);
}
public isAnyPlayerIn(recheck = false): boolean {
if (this.id === -1) return false;
return ows.IsAnyPlayerInDynamicArea(this.id, recheck);
}
public static isAnyPlayerInAny(recheck = false): boolean {
return ows.IsAnyPlayerInAnyDynamicArea(recheck);
}
public static getPlayerAreas<P extends BasePlayer, A extends DynamicArea>(
player: P,
areas: Map<number, A>
): Array<A | undefined> {
if (!DynamicArea.getPlayerAreasNumber(player)) return [];
const ids = ows.GetPlayerDynamicAreas(player.id);
return ids.map((a) => areas.get(a));
}
public static getPlayerAreasNumber<P extends BasePlayer>(player: P) {
return ows.GetPlayerNumberDynamicAreas(player.id);
}
public isPointIn(x: number, y: number, z: number): boolean {
if (this.id === -1) return false;
return ows.IsPointInDynamicArea(this.id, x, y, z);
}
public static isPointInAny(x: number, y: number, z: number): boolean {
return ows.IsPointInAnyDynamicArea(x, y, z);
}
public isLineIn(
x1: number,
y1: number,
z1: number,
x2: number,
y2: number,
z2: number
): boolean {
if (this.id === -1) return false;
return ows.IsLineInDynamicArea(this.id, x1, y1, z1, x2, y2, z2);
}
public static isLineInAny(
x1: number,
y1: number,
z1: number,
x2: number,
y2: number,
z2: number
): boolean {
return ows.IsLineInAnyDynamicArea(x1, y1, z1, x2, y2, z2);
}
public static getForPoint<A extends DynamicArea>(
x: number,
y: number,
z: number,
areas: Map<number, A>
): Array<A | undefined> {
if (!DynamicArea.getNumberForPoint(x, y, z)) return [];
const ids = ows.GetDynamicAreasForPoint(x, y, z);
return ids.map((a) => areas.get(a));
}
public static getNumberForPoint(x: number, y: number, z: number): number {
return ows.GetNumberDynamicAreasForPoint(x, y, z);
}
public static getForLine<A extends DynamicArea>(
x1: number,
y1: number,
z1: number,
x2: number,
y2: number,
z2: number,
areas: Map<number, A>
): Array<A | undefined> {
if (!DynamicArea.getNumberForLine(x1, y1, z1, x2, y2, z2)) return [];
const ids = ows.GetDynamicAreasForLine(x1, y1, z1, x2, y2, z2);
return ids.map((a) => areas.get(a));
}
public static getNumberForLine(
x1: number,
y1: number,
z1: number,
x2: number,
y2: number,
z2: number
): number {
return ows.GetNumberDynamicAreasForLine(x1, y1, z1, x2, y2, z2);
}
public attachToObject<O extends DynamicObject>(
obj: O,
offsetx = 0.0,
offsety = 0.0,
offsetz = 0.0
): void | number {
if (this.id === -1 || obj.id === -1)
return logger.warn(
"[StreamerArea]: Unable to toggle attach to object before create"
);
return ows.AttachDynamicAreaToObject(
this.id,
obj.id,
ows.StreamerObjectTypes.DYNAMIC,
InvalidEnum.PLAYER_ID,
offsetx,
offsety,
offsetz
);
}
public attachToPlayer<P extends BasePlayer>(
player: P,
offsetx = 0.0,
offsety = 0.0,
offsetz = 0.0
): void | number {
if (this.id === -1 || player.id === -1)
return logger.warn(
"[StreamerArea]: Unable to toggle attach to player before create"
);
return ows.AttachDynamicAreaToPlayer(
this.id,
player.id,
offsetx,
offsety,
offsetz
);
}
public attachToVehicle<V extends BaseVehicle>(
vehicle: V,
offsetx = 0.0,
offsety = 0.0,
offsetz = 0.0
): void | number {
if (this.id === -1 || vehicle.id === -1)
return logger.warn(
"[StreamerArea]: Unable to toggle attach to vehicle before create"
);
return ows.AttachDynamicAreaToVehicle(
this.id,
vehicle.id,
offsetx,
offsety,
offsetz
);
}
public toggleSpectateMode(toggle: boolean): void | number {
if (this.id === -1)
return logger.warn(
"[StreamerArea]: Unable to toggle specate mode before create"
);
return ows.ToggleDynAreaSpectateMode(this.id, toggle);
}
public isToggleSpectateMode(): boolean {
if (this.id === -1) return false;
return ows.IsToggleDynAreaSpectateMode(this.id);
}
}
3 changes: 0 additions & 3 deletions src/controllers/streamer/checkpoint/baseCheckpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ export class DynamicCheckpoint {
checkPointBus.emit(checkPointHooks.destroyed, this);
return this;
}
public static isValid(checkpoint: DynamicCheckpoint): boolean {
return IsValidDynamicCP(checkpoint.id);
}
public isValid(): boolean {
return IsValidDynamicCP(this.id);
}
Expand Down
3 changes: 0 additions & 3 deletions src/controllers/streamer/mapIcon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ export class DynamicMapIcon {
DestroyDynamicMapIcon(this.id);
return this;
}
public static isValid(icon: DynamicMapIcon): boolean {
return IsValidDynamicMapIcon(icon.id);
}
public isValid(): boolean {
return IsValidDynamicMapIcon(this.id);
}
Expand Down
4 changes: 0 additions & 4 deletions src/controllers/streamer/object/baseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ export class DynamicObject {
return this;
}

public static isValid(object: DynamicObject): boolean {
return ows.IsValidDynamicObject(object.id);
}

public isValid(): boolean {
return ows.IsValidDynamicObject(this.id);
}
Expand Down
3 changes: 0 additions & 3 deletions src/controllers/streamer/pickup/basePickup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export class DynamicPickup {
pickupBus.emit(pickupHooks.destroyed, this);
return this;
}
public static isValid(pickup: DynamicPickup): boolean {
return IsValidDynamicPickup(pickup.id);
}
public isValid(): boolean {
return IsValidDynamicPickup(this.id);
}
Expand Down
3 changes: 0 additions & 3 deletions src/controllers/streamer/raceCP/baseRaceCP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ export class DynamicRaceCP {
raceCPBus.emit(raceCPHooks.destroyed, this);
return this;
}
public static isValid(checkpoint: DynamicRaceCP): boolean {
return IsValidDynamicCP(checkpoint.id);
}
public isValid(): boolean {
return IsValidDynamicCP(this.id);
}
Expand Down
7 changes: 0 additions & 7 deletions src/controllers/textdraw/baseTextDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,6 @@ export abstract class BaseTextDraw<P extends BasePlayer> {
"[BaseTextDraw]: player's textdraw should not be hide for all."
);
}
public static isValid<T extends BaseTextDraw<P>, P extends BasePlayer>(
textdraw: T
): boolean {
const p = textdraw.sourceInfo.player;
if (p) return ow.IsValidPlayer3DTextLabel(p.id, textdraw.id);
return ow.IsValidTextDraw(textdraw.id);
}
public isValid(): boolean {
const p = this.sourceInfo.player;
if (p) return ow.IsValidPlayer3DTextLabel(p.id, this.id);
Expand Down
3 changes: 0 additions & 3 deletions src/controllers/vehicle/baseVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,6 @@ export abstract class BaseVehicle {
if (this.id === -1) return;
return vehicles.find((v) => v.id === vehFunc.GetVehicleTrailer(this.id));
}
public static isValid<V extends BaseVehicle>(vehicle: V): boolean {
return vehFunc.IsValidVehicle(vehicle.id);
}
public isValid(): boolean {
return vehFunc.IsValidVehicle(this.id);
}
Expand Down

0 comments on commit d8fc1ce

Please sign in to comment.