Skip to content

Commit

Permalink
feat(shared): Add Vehicle.getNeonActive and Vehicle.setNeonActive
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Mar 29, 2024
1 parent 64f6526 commit 817bf6b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
24 changes: 23 additions & 1 deletion server/src/classes/Vehicle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Class.h"
#include "cpp-sdk/ICore.h"

static void NeonSetter(js::DynamicPropertySetterContext& ctx)
{
Expand All @@ -23,6 +22,28 @@ static void NeonSetter(js::DynamicPropertySetterContext& ctx)
vehicle->SetNeonActive(left, right, front, back);
}

static void SetNeonActive(js::FunctionContext& ctx)
{
if (!ctx.CheckThis()) return;
if (!ctx.CheckArgCount(1)) return;
if (!ctx.CheckArgType(0, js::Type::OBJECT)) return;

alt::IVehicle* vehicle = ctx.GetThisObject<alt::IVehicle>();

js::Object neonActive;
if (!ctx.GetArg(0, neonActive)) return;

bool activeLeft, activeRight, activeFront, activeBack;
vehicle->GetNeonActive(&activeLeft, &activeRight, &activeFront, &activeBack);

bool left = neonActive.Get<bool>("left", activeLeft);
bool right = neonActive.Get<bool>("right", activeRight);
bool front = neonActive.Get<bool>("front", activeFront);
bool back = neonActive.Get<bool>("back", activeBack);

vehicle->SetNeonActive(left, right, front, back);
}

static void ModKitGetter(js::PropertyContext& ctx)
{
if(!ctx.CheckThis()) return;
Expand Down Expand Up @@ -96,6 +117,7 @@ extern js::Class vehicleClass("Vehicle", &sharedVehicleClass, nullptr, [](js::Cl
tpl.BindToType(alt::IBaseObject::Type::VEHICLE);

tpl.DynamicProperty("neon", nullptr, &NeonSetter, nullptr, nullptr);
tpl.Method("setNeonActive", &SetNeonActive);

tpl.Property("modKit", &ModKitGetter, &ModKitSetter);
tpl.Property<&alt::IVehicle::GetPrimaryColor, &alt::IVehicle::SetPrimaryColor>("primaryColor");
Expand Down
20 changes: 19 additions & 1 deletion shared/src/classes/SharedVehicle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Class.h"
#include "cpp-sdk/ICore.h"

static void NeonGetter(js::DynamicPropertyGetterContext& ctx)
{
Expand All @@ -21,6 +20,24 @@ static void NeonGetter(js::DynamicPropertyGetterContext& ctx)
ctx.Return(val);
}

static void GetNeonActive(js::FunctionContext& ctx)
{
if (!ctx.CheckThis()) return;

alt::IVehicle* vehicle = ctx.GetThisObject<alt::IVehicle>();

bool left, right, front, back;
vehicle->GetNeonActive(&left, &right, &front, &back);

js::Object neonStates;
neonStates.Set("left", left);
neonStates.Set("right", right);
neonStates.Set("front", front);
neonStates.Set("back", back);

ctx.Return(neonStates);
}

static void NeonEnumerator(js::DynamicPropertyEnumeratorContext& ctx)
{
js::Array arr(4);
Expand All @@ -36,6 +53,7 @@ extern js::Class entityClass;
extern js::Class sharedVehicleClass("SharedVehicle", &entityClass, nullptr, [](js::ClassTemplate& tpl)
{
tpl.DynamicProperty("neon", &NeonGetter, nullptr, nullptr, &NeonEnumerator);
tpl.Method("getNeonActive", &GetNeonActive);

tpl.Property<&alt::IVehicle::GetDriver>("driver");
tpl.Property<&alt::IVehicle::IsDestroyed>("isDestroyed");
Expand Down
2 changes: 2 additions & 0 deletions types/client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ declare module "@altv/client" {
batteryLightState: boolean;
suspensionHeight: number;

getNeonActive(): altShared.VehicleNeonState;

getMod(category: number): number;
getModsCount(category: number): number;
isExtraOn(extraId: number): boolean;
Expand Down
2 changes: 1 addition & 1 deletion types/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@altv/client",
"version": "0.0.32",
"version": "0.0.33",
"description": "This package contains the type definitions for the alt:V JS module v2 client types",
"types": "index.d.ts",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions types/server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ declare module "@altv/server" {
readonly accelerationLevel: number;
readonly brakeLevel: number;

setNeonActive(neons: Partial<altShared.VehicleNeonState>): void;
getNeonActive(): altShared.VehicleNeonState;

getMod(category: number): number;
getModsCount(category: number): number;
isExtraOn(extraId: number): boolean;
Expand Down
2 changes: 1 addition & 1 deletion types/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@altv/server",
"version": "0.0.37",
"version": "0.0.38",
"description": "This package contains the type definitions for the alt:V JS module v2 server types",
"types": "index.d.ts",
"files": [
Expand Down
8 changes: 4 additions & 4 deletions types/shared/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ declare module "@altv/shared" {
}

export interface VehicleNeonState {
readonly left: boolean;
readonly right: boolean;
readonly front: boolean;
readonly back: boolean;
left: boolean;
right: boolean;
front: boolean;
back: boolean;
}

export interface KeyStateInfo {
Expand Down
2 changes: 1 addition & 1 deletion types/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@altv/shared",
"version": "0.0.15",
"version": "0.0.16",
"description": "This package contains the type definitions for the alt:V JS module v2 shared types",
"types": "index.d.ts",
"files": [
Expand Down

0 comments on commit 817bf6b

Please sign in to comment.