Skip to content

Commit

Permalink
feat: base vehicle create logger warn
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Sep 4, 2022
1 parent 8a14c4e commit daedc71
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/controllers/vehicle/baseVehicle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InvalidEnum } from "@/enums";
import logger from "@/logger";
import { IsValidVehComponent } from "@/utils/vehicleUtils";
import {
Expand All @@ -20,6 +21,7 @@ export interface IVehicle {
}

export abstract class BaseVehicle {
private static createdCount = 0;
private _id = -1;
private info: IVehicle;
public get id(): number {
Expand All @@ -29,7 +31,12 @@ export abstract class BaseVehicle {
this.info = veh;
}
public create(): void {
if (this.id !== -1) return;
if (this.id !== -1)
return logger.warn("[BaseVehicle]: Unable to create the vehicle again");
if (BaseVehicle.createdCount === InvalidEnum.INVALID_VEHICLE_ID)
return logger.warn(
"[BaseVehicle]: Unable to continue to create vehicle, maximum allowable quantity has been reached"
);
const {
vehicletype,
x,
Expand All @@ -52,11 +59,16 @@ export abstract class BaseVehicle {
respawn_delay || -1,
addsiren || 0
);
BaseVehicle.createdCount++;
vehicleBus.emit(vehicleHooks.created, this);
}
public destroy(): void {
if (this.id === -1) return;
if (this.id === -1)
return logger.warn(
"[BaseVehicle]: Unable to destroy the vehicle before create"
);
DestroyVehicle(this.id);
BaseVehicle.createdCount--;
vehicleBus.emit(vehicleHooks.created, this);
this._id = -1;
}
Expand Down

0 comments on commit daedc71

Please sign in to comment.