diff --git a/distribution/scripting/openrct2.d.ts b/distribution/scripting/openrct2.d.ts index 0dc44e634e..bb4dd4fbcd 100644 --- a/distribution/scripting/openrct2.d.ts +++ b/distribution/scripting/openrct2.d.ts @@ -3154,7 +3154,7 @@ declare global { * The type of subposition coordinates that this vehicle is using to find its * position on the track. */ - readonly subposition: number; + subposition: number; /** * List of guest IDs ordered by seat. diff --git a/src/openrct2/scripting/ScriptEngine.h b/src/openrct2/scripting/ScriptEngine.h index 59aa8c49fa..5b80de7de1 100644 --- a/src/openrct2/scripting/ScriptEngine.h +++ b/src/openrct2/scripting/ScriptEngine.h @@ -43,7 +43,7 @@ namespace OpenRCT2 namespace OpenRCT2::Scripting { // Grepped from CI (.github/workflows/publish-plugin-types.yml); keep the format `kPluginApiVersion = N`. - static constexpr int32_t kPluginApiVersion = 121; + static constexpr int32_t kPluginApiVersion = 122; // Versions marking breaking changes. static constexpr int32_t kApiVersionPeepDeprecation = 33; diff --git a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp index e7867a8aca..bc09dc8b8c 100644 --- a/src/openrct2/scripting/bindings/entity/ScVehicle.cpp +++ b/src/openrct2/scripting/bindings/entity/ScVehicle.cpp @@ -93,7 +93,7 @@ namespace OpenRCT2::Scripting JS_CGETSET_DEF("trackLocation", &ScVehicle::trackLocation_get, nullptr), JS_CGETSET_DEF("trackProgress", &ScVehicle::trackProgress_get, nullptr), JS_CGETSET_DEF("remainingDistance", &ScVehicle::remainingDistance_get, nullptr), - JS_CGETSET_DEF("subposition", &ScVehicle::subposition_get, nullptr), + JS_CGETSET_DEF("subposition", &ScVehicle::subposition_get, &ScVehicle::subposition_set), JS_CGETSET_DEF("poweredAcceleration", &ScVehicle::poweredAcceleration_get, &ScVehicle::poweredAcceleration_set), JS_CGETSET_DEF("poweredMaxSpeed", &ScVehicle::poweredMaxSpeed_get, &ScVehicle::poweredMaxSpeed_set), JS_CGETSET_DEF("status", &ScVehicle::status_get, &ScVehicle::status_set), @@ -464,6 +464,27 @@ namespace OpenRCT2::Scripting return JS_NewUint32(ctx, vehicle != nullptr ? static_cast(vehicle->TrackSubposition) : 0); } + JSValue ScVehicle::subposition_set(JSContext* ctx, JSValue thisVal, JSValue jsValue) + { + JS_UNPACK_UINT32(value, ctx, jsValue); + JS_THROW_IF_GAME_STATE_NOT_MUTABLE(); + + if (value >= static_cast(VehicleTrackSubposition::count)) + { + return JS_ThrowRangeError(ctx, "Invalid vehicle subposition"); + } + + auto vehicle = GetVehicle(thisVal); + if (vehicle != nullptr) + { + vehicle->TrackSubposition = static_cast(value); + vehicle->UpdateTrackChange(); + EntityTweener::Get().RemoveEntity(vehicle); + } + + return JS_UNDEFINED; + } + JSValue ScVehicle::poweredAcceleration_get(JSContext* ctx, JSValue thisVal) { auto vehicle = GetVehicle(thisVal); diff --git a/src/openrct2/scripting/bindings/entity/ScVehicle.hpp b/src/openrct2/scripting/bindings/entity/ScVehicle.hpp index 8de00e26cc..f537c7f9fe 100644 --- a/src/openrct2/scripting/bindings/entity/ScVehicle.hpp +++ b/src/openrct2/scripting/bindings/entity/ScVehicle.hpp @@ -82,6 +82,7 @@ namespace OpenRCT2::Scripting static JSValue remainingDistance_get(JSContext* ctx, JSValue thisVal); static JSValue subposition_get(JSContext* ctx, JSValue thisVal); + static JSValue subposition_set(JSContext* ctx, JSValue thisVal, JSValue jsValue); static JSValue poweredAcceleration_get(JSContext* ctx, JSValue thisVal); static JSValue poweredAcceleration_set(JSContext* ctx, JSValue thisVal, JSValue jsValue);