mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 14:24:33 +01:00
Fix scripting API returning 0 instead of null.
This commit is contained in:
8
distribution/openrct2.d.ts
vendored
8
distribution/openrct2.d.ts
vendored
@@ -1161,15 +1161,15 @@ declare global {
|
||||
|
||||
/**
|
||||
* The previous car on the ride. This may be the on the same train or the previous
|
||||
* train. This will point to the last car if this is the first car on the ride.
|
||||
* train. This will return null if there is no previous car.
|
||||
*/
|
||||
previousCarOnRide: number;
|
||||
previousCarOnRide: number | null;
|
||||
|
||||
/**
|
||||
* The next car on the ride. This may be the on the same train or the next
|
||||
* train. This will point to the first car if this is the last car on the ride.
|
||||
* train. This will return null if there is no next car.
|
||||
*/
|
||||
nextCarOnRide: number;
|
||||
nextCarOnRide: number | null;
|
||||
|
||||
/**
|
||||
* The current station the train is in or departing.
|
||||
|
||||
@@ -286,6 +286,12 @@ namespace OpenRCT2::Scripting
|
||||
return DukValue::take_from_stack(ctx);
|
||||
}
|
||||
|
||||
template<> inline DukValue ToDuk(duk_context* ctx, const uint16_t& value)
|
||||
{
|
||||
duk_push_int(ctx, value);
|
||||
return DukValue::take_from_stack(ctx);
|
||||
}
|
||||
|
||||
template<> inline DukValue ToDuk(duk_context* ctx, const int32_t& value)
|
||||
{
|
||||
duk_push_int(ctx, value);
|
||||
|
||||
@@ -196,34 +196,65 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ScVehicle::previousCarOnRide_get() const
|
||||
DukValue ScVehicle::previousCarOnRide_get() const
|
||||
{
|
||||
auto vehicle = GetVehicle();
|
||||
return vehicle != nullptr ? vehicle->prev_vehicle_on_ride.ToUnderlying() : EntityId::GetNull().ToUnderlying();
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
|
||||
const auto* vehicle = GetVehicle();
|
||||
if (vehicle == nullptr)
|
||||
return ToDuk(ctx, nullptr);
|
||||
|
||||
if (vehicle->prev_vehicle_on_ride.IsNull())
|
||||
return ToDuk(ctx, nullptr);
|
||||
|
||||
return ToDuk(ctx, vehicle->prev_vehicle_on_ride.ToUnderlying());
|
||||
}
|
||||
void ScVehicle::previousCarOnRide_set(uint16_t value)
|
||||
void ScVehicle::previousCarOnRide_set(DukValue value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto vehicle = GetVehicle();
|
||||
if (vehicle != nullptr)
|
||||
auto* vehicle = GetVehicle();
|
||||
if (vehicle == nullptr)
|
||||
return;
|
||||
|
||||
if (value.type() == DukValue::Type::NUMBER)
|
||||
{
|
||||
vehicle->prev_vehicle_on_ride = EntityId::FromUnderlying(value);
|
||||
vehicle->prev_vehicle_on_ride = EntityId::FromUnderlying(value.as_uint());
|
||||
}
|
||||
else
|
||||
{
|
||||
vehicle->prev_vehicle_on_ride = EntityId::GetNull();
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ScVehicle::nextCarOnRide_get() const
|
||||
DukValue ScVehicle::nextCarOnRide_get() const
|
||||
{
|
||||
auto vehicle = GetVehicle();
|
||||
return vehicle != nullptr ? vehicle->next_vehicle_on_ride.ToUnderlying() : EntityId::GetNull().ToUnderlying();
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
|
||||
const auto* vehicle = GetVehicle();
|
||||
if (vehicle == nullptr)
|
||||
return ToDuk(ctx, nullptr);
|
||||
|
||||
if (vehicle->next_vehicle_on_ride.IsNull())
|
||||
return ToDuk(ctx, nullptr);
|
||||
|
||||
return ToDuk(ctx, vehicle->next_vehicle_on_ride.ToUnderlying());
|
||||
}
|
||||
void ScVehicle::nextCarOnRide_set(uint16_t value)
|
||||
void ScVehicle::nextCarOnRide_set(DukValue value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto vehicle = GetVehicle();
|
||||
if (vehicle != nullptr)
|
||||
auto* vehicle = GetVehicle();
|
||||
if (vehicle == nullptr)
|
||||
return;
|
||||
|
||||
if (value.type() == DukValue::Type::NUMBER)
|
||||
{
|
||||
vehicle->next_vehicle_on_ride = EntityId::FromUnderlying(value);
|
||||
vehicle->next_vehicle_on_ride = EntityId::FromUnderlying(value.as_uint());
|
||||
}
|
||||
else
|
||||
{
|
||||
vehicle->next_vehicle_on_ride = EntityId::GetNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StationIndex ScVehicle::currentStation_get() const
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
# include "../../../ride/Ride.h"
|
||||
# include "ScEntity.hpp"
|
||||
|
||||
# include <optional>
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
class ScVehicle : public ScEntity
|
||||
@@ -44,11 +46,11 @@ namespace OpenRCT2::Scripting
|
||||
DukValue nextCarOnTrain_get() const;
|
||||
void nextCarOnTrain_set(DukValue value);
|
||||
|
||||
uint16_t previousCarOnRide_get() const;
|
||||
void previousCarOnRide_set(uint16_t value);
|
||||
DukValue previousCarOnRide_get() const;
|
||||
void previousCarOnRide_set(DukValue value);
|
||||
|
||||
uint16_t nextCarOnRide_get() const;
|
||||
void nextCarOnRide_set(uint16_t value);
|
||||
DukValue nextCarOnRide_get() const;
|
||||
void nextCarOnRide_set(DukValue value);
|
||||
|
||||
StationIndex currentStation_get() const;
|
||||
void currentStation_set(StationIndex value);
|
||||
|
||||
Reference in New Issue
Block a user