Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistency: Keep engineOn alphabetically sorted #97

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code/client/src/core/modules/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace MafiaMP::Core::Modules {
metadata.colorPrimary = {colorPrimary.r, colorPrimary.g, colorPrimary.b, colorPrimary.a};
metadata.colorSecondary = {colorSecondary.r, colorSecondary.g, colorSecondary.b, colorSecondary.a};
metadata.dirt = vehicle->GetVehicleDirty();
metadata.engineOn = car->IsEngineOn();
metadata.fuel = car->GetActualFuel();
metadata.gear = car->GetGear();
metadata.handbrake = vehicle->GetHandbrake();
Expand All @@ -72,7 +73,6 @@ namespace MafiaMP::Core::Modules {
metadata.rimColor = {rimColor.r, rimColor.g, rimColor.b, rimColor.a};
metadata.rust = vehicle->GetVehicleRust();
metadata.sirenOn = vehicle->IsSiren();
metadata.engineOn = car->IsEngineOn();
metadata.steer = vehicle->GetSteer();
metadata.tireColor = {tireColor.r, tireColor.g, tireColor.b, tireColor.a};
metadata.velocity = {vehicleVelocity.x, vehicleVelocity.y, vehicleVelocity.z};
Expand Down Expand Up @@ -204,8 +204,8 @@ namespace MafiaMP::Core::Modules {
vehicle->SetBrake(updateData->brake, false);
vehicle->SetVehicleColor(&colorPrimary, &colorSecondary, false);
car->SetVehicleDirty(updateData->dirt); // We have to use the car to set the dirt otherwise the value is reset
car->SetActualFuel(updateData->fuel);
vehicle->SetEngineOn(updateData->engineOn, updateData->engineOn);
car->SetActualFuel(updateData->fuel);
vehicle->SetGear(updateData->gear);
vehicle->SetHandbrake(updateData->handbrake, false);
vehicle->SetHorn(updateData->hornOn);
Expand Down
29 changes: 15 additions & 14 deletions code/server/src/core/builtins/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ namespace MafiaMP::Scripting {
FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg);
}

bool Vehicle::GetEngineOn() {
auto syncData = _ent.get_mut<Shared::Modules::VehicleSync::UpdateData>();
return syncData->engineOn;
}

void Vehicle::SetEngineOn(bool on) {
auto vehData = _ent.get_mut<Shared::Modules::VehicleSync::UpdateData>();
vehData->engineOn = on;
MafiaMP::Shared::RPC::VehicleSetProps msg {};
msg.engineOn = on;
FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg);
}

float Vehicle::GetFuel() {
auto vehData = _ent.get_mut<Shared::Modules::VehicleSync::UpdateData>();
return vehData->fuel;
Expand Down Expand Up @@ -239,19 +252,6 @@ namespace MafiaMP::Scripting {
FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg);
}

bool Vehicle::GetEngineOn() {
auto syncData = _ent.get_mut<Shared::Modules::VehicleSync::UpdateData>();
return syncData->engineOn;
}

void Vehicle::SetEngineOn(bool on) {
auto vehData = _ent.get_mut<Shared::Modules::VehicleSync::UpdateData>();
vehData->engineOn = on;
MafiaMP::Shared::RPC::VehicleSetProps msg {};
msg.engineOn = on;
FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg);
}

void Vehicle::Register(v8::Isolate *isolate, v8pp::module *rootModule) {
if (!rootModule) {
return;
Expand All @@ -275,6 +275,7 @@ namespace MafiaMP::Scripting {
cls.function("getSirenOn", &Vehicle::GetSirenOn);
cls.function("getTireColor", &Vehicle::GetTireColor);
cls.function("getWindowTint", &Vehicle::GetWindowTint);

cls.function("setBeaconLightsOn", &Vehicle::SetBeaconLightsOn);
cls.function("setColorPrimary", &Vehicle::SetColorPrimary);
cls.function("setColorSecondary", &Vehicle::SetColorSecondary);
Expand All @@ -293,4 +294,4 @@ namespace MafiaMP::Scripting {

rootModule->class_("Vehicle", cls);
}
}
} // namespace MafiaMP::Scripting
6 changes: 3 additions & 3 deletions code/shared/game_rpc/vehicle/vehicle_setprops.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace MafiaMP::Shared::RPC {
Framework::Utils::Optional<glm::vec4> colorPrimary;
Framework::Utils::Optional<glm::vec4> colorSecondary;
Framework::Utils::Optional<float> dirt;
Framework::Utils::Optional<bool> engineOn;
Framework::Utils::Optional<float> fuel;
Framework::Utils::Optional<SLNet::RakString> licensePlate;
Framework::Utils::Optional<Modules::VehicleSync::LockState> lockState;
Expand All @@ -19,7 +20,6 @@ namespace MafiaMP::Shared::RPC {
Framework::Utils::Optional<glm::vec4> rimColor;
Framework::Utils::Optional<float> rust;
Framework::Utils::Optional<bool> sirenOn;
Framework::Utils::Optional<bool> engineOn;
Framework::Utils::Optional<glm::vec4> tireColor;
Framework::Utils::Optional<glm::vec4> windowTint;

Expand All @@ -28,6 +28,7 @@ namespace MafiaMP::Shared::RPC {
this->colorPrimary = props.colorPrimary;
this->colorSecondary = props.colorSecondary;
this->dirt = props.dirt;
this->engineOn = props.engineOn;
this->fuel = props.fuel;
this->licensePlate = props.licensePlate;
this->lockState = props.lockState;
Expand All @@ -36,7 +37,6 @@ namespace MafiaMP::Shared::RPC {
this->rimColor = props.rimColor;
this->rust = props.rust;
this->sirenOn = props.sirenOn;
this->engineOn = props.engineOn;
this->tireColor = props.tireColor;
this->windowTint = props.windowTint;
}
Expand All @@ -46,6 +46,7 @@ namespace MafiaMP::Shared::RPC {
colorPrimary.Serialize(bs, write);
colorSecondary.Serialize(bs, write);
dirt.Serialize(bs, write);
engineOn.Serialize(bs, write);
fuel.Serialize(bs, write);
licensePlate.Serialize(bs, write);
lockState.Serialize(bs, write);
Expand All @@ -54,7 +55,6 @@ namespace MafiaMP::Shared::RPC {
rimColor.Serialize(bs, write);
rust.Serialize(bs, write);
sirenOn.Serialize(bs, write);
engineOn.Serialize(bs, write);
tireColor.Serialize(bs, write);
windowTint.Serialize(bs, write);
}
Expand Down
2 changes: 1 addition & 1 deletion code/shared/modules/vehicle_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace MafiaMP::Shared::Modules {
glm::vec4 colorPrimary {1.0f, 1.0f, 1.0f, 1.0f};
glm::vec4 colorSecondary {1.0f, 1.0f, 1.0f, 1.0f};
float dirt = 0.0f;
bool engineOn = false;
float fuel = 100.0f; // We use arbitrary value, the max depends of the vehicle. See C_Motor::GetFuelSettings.
int gear = 0;
float handbrake = 0.0f;
Expand All @@ -33,7 +34,6 @@ namespace MafiaMP::Shared::Modules {
glm::vec4 rimColor {1.0f, 1.0f, 1.0f, 1.0f};
float rust = 0.0f;
bool sirenOn = false;
bool engineOn = false;
float steer = 0.0f;
glm::vec4 tireColor {1.0f, 1.0f, 1.0f, 1.0f};
glm::vec3 velocity {};
Expand Down
Loading