From f4fb456c50df7f9689d424d4b7c00a503ac41de5 Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 15 May 2020 00:41:37 +0100 Subject: [PATCH] Add ride value to ScRide --- distribution/openrct2.d.ts | 5 +++++ src/openrct2/scripting/Duktape.hpp | 6 ++++++ src/openrct2/scripting/ScRide.hpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index f0996f6cc4..1d4c207a94 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -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"; diff --git a/src/openrct2/scripting/Duktape.hpp b/src/openrct2/scripting/Duktape.hpp index 36816c93cd..43b535a698 100644 --- a/src/openrct2/scripting/Duktape.hpp +++ b/src/openrct2/scripting/Duktape.hpp @@ -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()); diff --git a/src/openrct2/scripting/ScRide.hpp b/src/openrct2/scripting/ScRide.hpp index c1290dfac2..7d74ae9887 100644 --- a/src/openrct2/scripting/ScRide.hpp +++ b/src/openrct2/scripting/ScRide.hpp @@ -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(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