mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Add ride value to ScRide
This commit is contained in:
5
distribution/openrct2.d.ts
vendored
5
distribution/openrct2.d.ts
vendored
@@ -783,6 +783,11 @@ declare global {
|
||||
* How often the ride should be inspected by a mechanic.
|
||||
*/
|
||||
inspectionInterval: number;
|
||||
|
||||
/**
|
||||
* The value of the ride.
|
||||
*/
|
||||
value: number;
|
||||
}
|
||||
|
||||
type RideClassification = "ride" | "stall" | "facility";
|
||||
|
||||
@@ -257,6 +257,12 @@ namespace OpenRCT2::Scripting
|
||||
return DukValue::take_from_stack(ctx);
|
||||
}
|
||||
|
||||
template<> inline DukValue ToDuk(duk_context* ctx, const int32_t& value)
|
||||
{
|
||||
duk_push_int(ctx, value);
|
||||
return DukValue::take_from_stack(ctx);
|
||||
}
|
||||
|
||||
template<> inline DukValue ToDuk(duk_context* ctx, const std::string_view& value)
|
||||
{
|
||||
duk_push_lstring(ctx, value.data(), value.size());
|
||||
|
||||
@@ -591,6 +591,34 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
}
|
||||
|
||||
DukValue value_get() const
|
||||
{
|
||||
auto ctx = GetContext()->GetScriptEngine().GetContext();
|
||||
auto ride = GetRide();
|
||||
if (ride != nullptr && ride->value != RIDE_VALUE_UNDEFINED)
|
||||
{
|
||||
return ToDuk<int32_t>(ctx, ride->value);
|
||||
}
|
||||
return ToDuk(ctx, nullptr);
|
||||
}
|
||||
|
||||
void value_set(const DukValue& value)
|
||||
{
|
||||
ThrowIfGameStateNotMutable();
|
||||
auto ride = GetRide();
|
||||
if (ride != nullptr)
|
||||
{
|
||||
if (value.type() == DukValue::Type::NUMBER)
|
||||
{
|
||||
ride->value = value.as_int();
|
||||
}
|
||||
else
|
||||
{
|
||||
ride->value = RIDE_VALUE_UNDEFINED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ride* GetRide() const
|
||||
{
|
||||
return get_ride(_rideId);
|
||||
@@ -626,6 +654,7 @@ namespace OpenRCT2::Scripting
|
||||
dukglue_register_property(ctx, &ScRide::runningCost_get, &ScRide::runningCost_set, "runningCost");
|
||||
dukglue_register_property(
|
||||
ctx, &ScRide::inspectionInterval_get, &ScRide::inspectionInterval_set, "inspectionInterval");
|
||||
dukglue_register_property(ctx, &ScRide::value_get, &ScRide::value_set, "value");
|
||||
}
|
||||
};
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
Reference in New Issue
Block a user