Skip to content

Commit

Permalink
feat: veh/player static check, perf private attrs, color
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Feb 12, 2023
1 parent ae8ab43 commit 7aac09e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 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.8.1",
"version": "0.8.2",
"description": "Better with omp-node-ts",
"main": "dist/bundle.js",
"types": "dist/bundle.d.ts",
Expand Down
22 changes: 17 additions & 5 deletions src/controllers/player/basePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,31 @@ export abstract class BasePlayer {
return this._locale;
}
set locale(value: string) {
playerBus.emit(playerHooks.setLocale, { player: this, value });
playerBus.emit(playerHooks.setCommonProp, {
player: this,
prop: "_locale",
value,
});
}
get charset(): string {
return this._charset;
}
set charset(value: string) {
playerBus.emit(playerHooks.setCharset, { player: this, value });
playerBus.emit(playerHooks.setCommonProp, {
player: this,
prop: "_charset",
value,
});
}
get isRecording() {
return this._isRecording;
}
set isRecording(value) {
playerBus.emit(playerHooks.setIsRecording, { player: this, value });
playerBus.emit(playerHooks.setCommonProp, {
player: this,
prop: "_isRecording",
value,
});
}

constructor(id: number) {
Expand Down Expand Up @@ -566,8 +578,8 @@ export abstract class BasePlayer {
}
return playerFunc.CreateExplosionForPlayer(this.id, X, Y, Z, type, Radius);
}
static isConnected<P extends BasePlayer>(player: P): boolean {
return playerFunc.IsPlayerConnected(player.id);
static isConnected(id: number): boolean {
return playerFunc.IsPlayerConnected(id);
}
isConnected(): boolean {
return playerFunc.IsPlayerConnected(this.id);
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/player/playerBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { EventBus } from "@/utils/eventBus";
export enum playerHooks {
pause = "OnPlayerPause",
create = "OnPlayerEventCreate",
setLocale = "OnPlayerSetLocale",
setCharset = "OnPlayerSetCharset",
setIsRecording = "OnPlayerSetIsRecording",
setCommonProp = "OnPlayerSetCommonProp",
}

export const playerBus = new EventBus();
13 changes: 4 additions & 9 deletions src/controllers/player/playerEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,9 @@ export abstract class BasePlayerEvent<P extends BasePlayer> {
this.onPause && this.onPause(player, player.lastUpdateTick);
});

playerBus.on(playerHooks.setLocale, ({ player, value }) => {
Reflect.set(player, "_locale", value);
});
playerBus.on(playerHooks.setCharset, ({ player, value }) => {
Reflect.set(player, "_charset", value);
});
playerBus.on(playerHooks.setIsRecording, ({ player, value }) => {
Reflect.set(player, "_isRecording", value);
playerBus.on(playerHooks.setCommonProp, ({ player, prop, value }) => {
Reflect.set(player, prop, value);
this.players.set(player.id, player);
});
}
findPlayerById(playerid: number) {
Expand All @@ -336,7 +331,7 @@ export abstract class BasePlayerEvent<P extends BasePlayer> {
60
);
private static fpsHeartbeat = throttle((player: BasePlayer) => {
if (!BasePlayer.isConnected(player)) return;
if (!BasePlayer.isConnected(player.id)) return;
const nowDrunkLevel = player.getDrunkLevel();
if (nowDrunkLevel < 100) {
player.setDrunkLevel(2000);
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/vehicle/baseVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ export abstract class BaseVehicle {
isValid(): boolean {
return vehFunc.IsValidVehicle(this.id);
}
static isValid(id: number): boolean {
return vehFunc.IsValidVehicle(id);
}
getMatrix() {
if (this.id === -1) return;
return GetVehicleMatrix(this.id);
Expand Down
1 change: 1 addition & 0 deletions src/utils/colorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export const rgba = (value: string | number): number => {
if (typeof value === "number") return value;
if (typeof +value === "number" && !isNaN(+value)) return +value;
if (value.charAt(0) === "#") {
if (value.length === 4) {
return parseInt(
Expand Down

0 comments on commit 7aac09e

Please sign in to comment.