1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 14:24:33 +01:00

Merge pull request #14252 from Phelicks/develop

Add plugin API for vehicle g-forces
This commit is contained in:
Michael Steenbeek
2021-03-07 13:46:16 +01:00
committed by GitHub
5 changed files with 37 additions and 1 deletions

View File

@@ -29,6 +29,7 @@
- Feature: [#14171] [Plugin] Add API for creating custom widgets.
- Feature: [#14171] [Plugin] Add API for drawing graphics for custom widgets.
- Feature: [#14171] [Plugin] Add click event to spinners and allow them to be held down.
- Feature: [#14252] [Plugin] Add API for vehicle g-forces.
- Change: [#13346] [Plugin] Renamed FootpathScenery to FootpathAddition, fix typos.
- Change: [#13857] Change Rotation Control Toggle to track element number 256
- Fix: [#4605, #11912] Water palettes are not updated properly when selected in Object Selection.

View File

@@ -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.
@@ -1173,6 +1181,11 @@ declare global {
*/
trackLocation: CoordsXYZD;
/**
* The current g-forces of this car.
*/
readonly gForces: GForces;
/**
* The progress on the current track piece, in steps.
*/

View File

@@ -12,6 +12,7 @@
#ifdef ENABLE_SCRIPTING
# include "../core/Console.hpp"
# include "../ride/Vehicle.h"
# include "../world/Map.h"
# include <cstdio>
@@ -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;

View File

@@ -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();

View File

@@ -44,7 +44,7 @@
using namespace OpenRCT2;
using namespace OpenRCT2::Scripting;
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 23;
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 24;
struct ExpressionStringifier final
{