Skip to content

Commit

Permalink
feat: vehicle component utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Sep 3, 2022
1 parent 7382bf9 commit 75aca78
Show file tree
Hide file tree
Showing 2 changed files with 850 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/controllers/vehicle/baseVehicle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { CreateVehicle, DestroyVehicle } from "@/wrapper/functions";
import logger from "@/logger";
import { IsValidVehComponent } from "@/utils/vehicleUtils";
import {
AddVehicleComponent,
CreateVehicle,
DestroyVehicle,
} from "@/wrapper/functions";

export interface IVehicle {
vehicletype: number;
Expand All @@ -14,6 +20,7 @@ export interface IVehicle {

export abstract class BaseVehicle {
private _id = -1;
private info: IVehicle;
public get id(): number {
return this._id;
}
Expand All @@ -29,9 +36,19 @@ export abstract class BaseVehicle {
veh.respawn_delay || -1,
veh.addsiren || 0
);
this.info = veh;
}
public destroy(): void {
DestroyVehicle(this.id);
this._id = -1;
}
public addComponent(componentid: number): number {
if (!IsValidVehComponent(this.info.vehicletype, componentid)) {
logger.warn(
`[BaseVehicle]: Invalid component id ${componentid} attempted to attach to the vehicle ${this}`
);
return -1;
}
return AddVehicleComponent(this.id, componentid);
}
}
Loading

0 comments on commit 75aca78

Please sign in to comment.