From b7c0a2c0dd8e6d3dfb4097fad2a9d088b77833f3 Mon Sep 17 00:00:00 2001 From: Vektor Date: Sat, 19 Dec 2020 15:57:53 +0100 Subject: [PATCH] mark isRoofOpened and setRoofOpened as deprecated Former-commit-id: eeba229efa1f39f3b0c130b1f322949d432b14ea --- src/bindings/Vehicle.cpp | 4 ++++ src/bindings/vehicle/GameState.h | 36 ++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/bindings/Vehicle.cpp b/src/bindings/Vehicle.cpp index 3d8b732e..d1515ab6 100644 --- a/src/bindings/Vehicle.cpp +++ b/src/bindings/Vehicle.cpp @@ -175,6 +175,10 @@ extern V8Class v8Vehicle("Vehicle", v8Entity, Constructor, [](v8::LocalSetAccessor(v8::String::NewFromUtf8(isolate, "daylightOn"), &DaylightOnGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "nightlightOn"), &NightlightOnGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "roofState"), &RoofStateGetter, &RoofStateSetter); + + proto->Set(v8::String::NewFromUtf8(isolate, "isRoofOpened"), v8::FunctionTemplate::New(isolate, &IsRoofOpenedDeprecated)); + proto->Set(v8::String::NewFromUtf8(isolate, "setRoofOpened"), v8::FunctionTemplate::New(isolate, &SetRoofOpenedDeprecated)); + proto->SetAccessor(v8::String::NewFromUtf8(isolate, "flamethrowerActive"), &FlamethrowerActiveGetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "activeRadioStation"), &ActiveRadioStationGetter, &ActiveRadioStationSetter); proto->SetAccessor(v8::String::NewFromUtf8(isolate, "lightsMultiplier"), &LightsMultiplierGetter, &LightsMultiplierSetter); diff --git a/src/bindings/vehicle/GameState.h b/src/bindings/vehicle/GameState.h index 87f58199..e8630cf4 100644 --- a/src/bindings/vehicle/GameState.h +++ b/src/bindings/vehicle/GameState.h @@ -209,7 +209,7 @@ namespace V8::Vehicle Ref vehicle = _this->GetHandle().As(); - info.GetReturnValue().Set(v8::Boolean::New(isolate, vehicle->GetRoofState())); + info.GetReturnValue().Set(v8::Integer::New(isolate, vehicle->GetRoofState())); } void RoofStateSetter(v8::Local name, v8::Local value, const v8::PropertyCallbackInfo& info) @@ -224,7 +224,39 @@ namespace V8::Vehicle Ref vehicle = _this->GetHandle().As(); - vehicle->SetRoofState(value->ToBoolean(info.GetIsolate())->Value()); + vehicle->SetRoofState(value->ToInteger(info.GetIsolate())->Value()); + } + + void IsRoofOpenedDeprecated(const v8::FunctionCallbackInfo& info) + { + v8::Isolate* isolate = info.GetIsolate(); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref vehicle = _this->GetHandle().As(); + + info.GetReturnValue().Set(v8::Boolean::New(isolate, vehicle->GetRoofState())); + } + + void SetRoofOpenedDeprecated(const v8::FunctionCallbackInfo& info) + { + v8::Isolate* isolate = info.GetIsolate(); + + V8_CHECK(info.Length() == 1, "1 arg expected"); + + V8ResourceImpl* resource = V8ResourceImpl::Get(isolate->GetEnteredContext()); + V8_CHECK(resource, "invalid resource"); + + V8Entity* _this = V8Entity::Get(info.This()); + V8_CHECK(_this, "entity is invalid"); + + Ref vehicle = _this->GetHandle().As(); + + vehicle->SetRoofState(info[0]->ToInteger(isolate)->Value()); } void FlamethrowerActiveGetter(v8::Local name, const v8::PropertyCallbackInfo& info)