diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index 0584f1857a..65b94c530f 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -786,6 +786,8 @@ E436DE7807A74621B7BF2276 /* ScPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E2A4181A243F4B77BA36ACE2 /* ScPlayer.cpp */; }; 2D0A43F28D5747C9B617F342 /* ScPlayer.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 7A08C451885D4D419FB4820D /* ScPlayer.hpp */; }; F08623EA69E7456DB79F3E06 /* ScNetwork.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 200F0E6CAD3B41499A3CFC36 /* ScNetwork.cpp */; }; + CDC72A71A28542F4AD73A91C /* ScRideStation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 522FE124ED4F4E18BCF79042 /* ScRideStation.cpp */; }; + 63858E295E3F451283987982 /* ScRideStation.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 1260386710BF4EA4B4FC31D3 /* ScRideStation.hpp */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -1874,6 +1876,8 @@ E2A4181A243F4B77BA36ACE2 /* ScPlayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScPlayer.cpp; path = src/openrct2/scripting/bindings/network/ScPlayer.cpp; sourceTree = SOURCE_ROOT; }; 7A08C451885D4D419FB4820D /* ScPlayer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScPlayer.hpp; path = src/openrct2/scripting/bindings/network/ScPlayer.hpp; sourceTree = SOURCE_ROOT; }; 200F0E6CAD3B41499A3CFC36 /* ScNetwork.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScNetwork.cpp; path = src/openrct2/scripting/bindings/network/ScNetwork.cpp; sourceTree = SOURCE_ROOT; }; + 522FE124ED4F4E18BCF79042 /* ScRideStation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ScRideStation.cpp; path = src/openrct2/scripting/bindings/ride/ScRideStation.cpp; sourceTree = SOURCE_ROOT; }; + 1260386710BF4EA4B4FC31D3 /* ScRideStation.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ScRideStation.hpp; path = src/openrct2/scripting/bindings/ride/ScRideStation.hpp; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -3438,6 +3442,8 @@ isa = PBXGroup; children = ( AD97B712FDF7454CADC7A328 /* ScRide.hpp */, + 522FE124ED4F4E18BCF79042 /* ScRideStation.cpp */, + 1260386710BF4EA4B4FC31D3 /* ScRideStation.hpp */, ); name = ride; sourceTree = ""; @@ -3605,6 +3611,7 @@ 359328A3A65D49578912CA40 /* ScLitter.hpp in Headers */, 97C222A2A4F543E9AEC3912B /* ScPlayerGroup.hpp in Headers */, 2D0A43F28D5747C9B617F342 /* ScPlayer.hpp in Headers */, + 63858E295E3F451283987982 /* ScRideStation.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -4417,6 +4424,7 @@ 149D1ACFD5FA42938364C843 /* ScPlayerGroup.cpp in Sources */, E436DE7807A74621B7BF2276 /* ScPlayer.cpp in Sources */, F08623EA69E7456DB79F3E06 /* ScNetwork.cpp in Sources */, + CDC72A71A28542F4AD73A91C /* ScRideStation.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 46cd93b2e7..ca6974de07 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -412,6 +412,7 @@ + @@ -863,6 +864,7 @@ + diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 8d25a6c226..04e11e54c8 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -39,6 +39,7 @@ # include "bindings/network/ScSocket.hpp" # include "bindings/object/ScObject.hpp" # include "bindings/ride/ScRide.hpp" +# include "bindings/ride/ScRideStation.hpp" # include "bindings/world/ScClimate.hpp" # include "bindings/world/ScDate.hpp" # include "bindings/world/ScMap.hpp" diff --git a/src/openrct2/scripting/bindings/ride/ScRide.hpp b/src/openrct2/scripting/bindings/ride/ScRide.hpp index fdab16479c..c8d32bb2b6 100644 --- a/src/openrct2/scripting/bindings/ride/ScRide.hpp +++ b/src/openrct2/scripting/bindings/ride/ScRide.hpp @@ -17,6 +17,7 @@ # include "../../Duktape.hpp" # include "../../ScriptEngine.h" # include "../object/ScObject.hpp" +# include "ScRideStation.hpp" namespace OpenRCT2::Scripting { @@ -56,124 +57,6 @@ namespace OpenRCT2::Scripting return result; } - class ScRideStation - { - private: - ride_id_t _rideId = RIDE_ID_NULL; - StationIndex _stationIndex{}; - - public: - ScRideStation(ride_id_t rideId, StationIndex stationIndex) - : _rideId(rideId) - , _stationIndex(stationIndex) - { - } - - static void Register(duk_context* ctx) - { - dukglue_register_property(ctx, &ScRideStation::start_get, &ScRideStation::start_set, "start"); - dukglue_register_property(ctx, &ScRideStation::length_get, &ScRideStation::length_set, "length"); - dukglue_register_property(ctx, &ScRideStation::entrance_get, &ScRideStation::entrance_set, "entrance"); - dukglue_register_property(ctx, &ScRideStation::exit_get, &ScRideStation::exit_set, "exit"); - } - - private: - DukValue start_get() const - { - auto ctx = GetContext()->GetScriptEngine().GetContext(); - auto station = GetRideStation(); - if (station != nullptr) - { - auto start = CoordsXYZ(station->Start, station->GetBaseZ()); - return ToDuk(ctx, start); - } - return ToDuk(ctx, nullptr); - } - - void start_set(const DukValue& value) - { - auto station = GetRideStation(); - if (station != nullptr) - { - auto start = FromDuk(value); - station->Start = { start.x, start.y }; - station->SetBaseZ(start.z); - } - } - - int32_t length_get() const - { - auto station = GetRideStation(); - if (station != nullptr) - { - return station->Length; - } - return 0; - } - - void length_set(int32_t value) - { - auto station = GetRideStation(); - if (station != nullptr) - { - station->Length = value; - } - } - - DukValue entrance_get() const - { - auto ctx = GetContext()->GetScriptEngine().GetContext(); - auto station = GetRideStation(); - if (station != nullptr) - { - return ToDuk(ctx, station->Entrance.ToCoordsXYZD()); - } - return ToDuk(ctx, nullptr); - } - - void entrance_set(const DukValue& value) - { - auto station = GetRideStation(); - if (station != nullptr) - { - station->Entrance = FromDuk(value); - } - } - - DukValue exit_get() const - { - auto ctx = GetContext()->GetScriptEngine().GetContext(); - auto station = GetRideStation(); - if (station != nullptr) - { - return ToDuk(ctx, station->Exit.ToCoordsXYZD()); - } - return ToDuk(ctx, nullptr); - } - - void exit_set(const DukValue& value) - { - auto station = GetRideStation(); - if (station != nullptr) - { - station->Exit = FromDuk(value); - } - } - - RideStation* GetRideStation() const - { - auto ride = get_ride(_rideId); - if (ride != nullptr) - { - if (_stationIndex < std::size(ride->stations)) - { - return &ride->stations[_stationIndex]; - } - } - return nullptr; - } - }; - class ScRide { private: diff --git a/src/openrct2/scripting/bindings/ride/ScRideStation.cpp b/src/openrct2/scripting/bindings/ride/ScRideStation.cpp new file mode 100644 index 0000000000..7717dc724d --- /dev/null +++ b/src/openrct2/scripting/bindings/ride/ScRideStation.cpp @@ -0,0 +1,136 @@ +/***************************************************************************** + * Copyright (c) 2021 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#ifdef ENABLE_SCRIPTING + +# include "ScRideStation.hpp" + +# include "../../../Context.h" +# include "../../../common.h" +# include "../../../ride/Ride.h" +# include "../../Duktape.hpp" +# include "../../ScriptEngine.h" +# include "../object/ScObject.hpp" + +namespace OpenRCT2::Scripting +{ + ScRideStation::ScRideStation(ride_id_t rideId, StationIndex stationIndex) + : _rideId(rideId) + , _stationIndex(stationIndex) + { + } + + void ScRideStation::Register(duk_context* ctx) + { + dukglue_register_property(ctx, &ScRideStation::start_get, &ScRideStation::start_set, "start"); + dukglue_register_property(ctx, &ScRideStation::length_get, &ScRideStation::length_set, "length"); + dukglue_register_property(ctx, &ScRideStation::entrance_get, &ScRideStation::entrance_set, "entrance"); + dukglue_register_property(ctx, &ScRideStation::exit_get, &ScRideStation::exit_set, "exit"); + } + + DukValue ScRideStation::start_get() const + { + auto ctx = GetContext()->GetScriptEngine().GetContext(); + auto station = GetRideStation(); + if (station != nullptr) + { + auto start = CoordsXYZ(station->Start, station->GetBaseZ()); + return ToDuk(ctx, start); + } + return ToDuk(ctx, nullptr); + } + + void ScRideStation::start_set(const DukValue& value) + { + auto station = GetRideStation(); + if (station != nullptr) + { + auto start = FromDuk(value); + station->Start = { start.x, start.y }; + station->SetBaseZ(start.z); + } + } + + int32_t ScRideStation::length_get() const + { + auto station = GetRideStation(); + if (station != nullptr) + { + return station->Length; + } + return 0; + } + + void ScRideStation::length_set(int32_t value) + { + auto station = GetRideStation(); + if (station != nullptr) + { + station->Length = value; + } + } + + DukValue ScRideStation::entrance_get() const + { + auto ctx = GetContext()->GetScriptEngine().GetContext(); + auto station = GetRideStation(); + if (station != nullptr) + { + return ToDuk(ctx, station->Entrance.ToCoordsXYZD()); + } + return ToDuk(ctx, nullptr); + } + + void ScRideStation::entrance_set(const DukValue& value) + { + auto station = GetRideStation(); + if (station != nullptr) + { + station->Entrance = FromDuk(value); + } + } + + DukValue ScRideStation::exit_get() const + { + auto ctx = GetContext()->GetScriptEngine().GetContext(); + auto station = GetRideStation(); + if (station != nullptr) + { + return ToDuk(ctx, station->Exit.ToCoordsXYZD()); + } + return ToDuk(ctx, nullptr); + } + + void ScRideStation::exit_set(const DukValue& value) + { + auto station = GetRideStation(); + if (station != nullptr) + { + station->Exit = FromDuk(value); + } + } + + RideStation* ScRideStation::GetRideStation() const + { + auto ride = get_ride(_rideId); + if (ride != nullptr) + { + if (_stationIndex < std::size(ride->stations)) + { + return &ride->stations[_stationIndex]; + } + } + return nullptr; + } + +} // namespace OpenRCT2::Scripting + +#endif diff --git a/src/openrct2/scripting/bindings/ride/ScRideStation.hpp b/src/openrct2/scripting/bindings/ride/ScRideStation.hpp new file mode 100644 index 0000000000..7b8c1804b9 --- /dev/null +++ b/src/openrct2/scripting/bindings/ride/ScRideStation.hpp @@ -0,0 +1,54 @@ +/***************************************************************************** + * Copyright (c) 2021 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#ifdef ENABLE_SCRIPTING + +# include "../../../Context.h" +# include "../../../common.h" +# include "../../../ride/Ride.h" +# include "../../Duktape.hpp" + +namespace OpenRCT2::Scripting +{ + class ScRideStation + { + private: + ride_id_t _rideId = RIDE_ID_NULL; + StationIndex _stationIndex{}; + + public: + ScRideStation(ride_id_t rideId, StationIndex stationIndex); + + static void Register(duk_context* ctx); + + private: + DukValue start_get() const; + + void start_set(const DukValue& value); + + int32_t length_get() const; + + void length_set(int32_t value); + + DukValue entrance_get() const; + + void entrance_set(const DukValue& value); + + DukValue exit_get() const; + + void exit_set(const DukValue& value); + + RideStation* GetRideStation() const; + }; + +} // namespace OpenRCT2::Scripting + +#endif