mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 04:23:20 +01:00
Add plugin API for vehicle g-forces
This commit is contained in:
13
distribution/openrct2.d.ts
vendored
13
distribution/openrct2.d.ts
vendored
@@ -114,6 +114,14 @@ declare global {
|
||||
rightBottom: CoordsXY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents lateral and vertical g-forces.
|
||||
*/
|
||||
interface GForces {
|
||||
lateralG: number;
|
||||
verticalG: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents information about the plugin such as type, name, author and version.
|
||||
* It also includes the entry point.
|
||||
@@ -1153,6 +1161,11 @@ declare global {
|
||||
*/
|
||||
trackLocation: CoordsXYZD;
|
||||
|
||||
/**
|
||||
* The current g-forces of this car.
|
||||
*/
|
||||
gForces: GForces;
|
||||
|
||||
/**
|
||||
* The progress on the current track piece, in steps.
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
# include "../core/Console.hpp"
|
||||
# include "../world/Map.h"
|
||||
# include "../ride/Vehicle.h"
|
||||
|
||||
# include <cstdio>
|
||||
# include <dukglue/dukglue.h>
|
||||
@@ -408,6 +409,14 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
}
|
||||
|
||||
template<> inline DukValue ToDuk(duk_context* ctx, const GForces& value)
|
||||
{
|
||||
DukObject dukGForces(ctx);
|
||||
dukGForces.Set("lateralG", value.LateralG);
|
||||
dukGForces.Set("verticalG", value.VerticalG);
|
||||
return dukGForces.Take();
|
||||
}
|
||||
|
||||
template<> inline CoordsXYZD FromDuk(const DukValue& value)
|
||||
{
|
||||
CoordsXYZD result;
|
||||
|
||||
@@ -270,6 +270,7 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_property(ctx, &ScVehicle::poweredMaxSpeed_get, &ScVehicle::poweredMaxSpeed_set, "poweredMaxSpeed");
|
||||
dukglue_register_property(ctx, &ScVehicle::status_get, &ScVehicle::status_set, "status");
|
||||
dukglue_register_property(ctx, &ScVehicle::peeps_get, nullptr, "peeps");
|
||||
dukglue_register_property(ctx, &ScVehicle::gForces_get, nullptr, "gForces");
|
||||
dukglue_register_method(ctx, &ScVehicle::travelBy, "travelBy");
|
||||
}
|
||||
|
||||
@@ -627,6 +628,18 @@ namespace OpenRCT2::Scripting
|
||||
return result;
|
||||
}
|
||||
|
||||
DukValue gForces_get() const
|
||||
{
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
auto vehicle = GetVehicle();
|
||||
if (vehicle != nullptr)
|
||||
{
|
||||
GForces gForces = vehicle->GetGForces();
|
||||
return ToDuk<GForces>(ctx, gForces);
|
||||
}
|
||||
return ToDuk(ctx, nullptr);
|
||||
}
|
||||
|
||||
void travelBy(int32_t value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
|
||||
Reference in New Issue
Block a user