mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-02-02 19:56:13 +01:00
Move ScRideStation into its own files
This commit is contained in:
@@ -412,6 +412,7 @@
|
||||
<ClInclude Include="scripting\bindings\entity\ScVehicle.hpp" />
|
||||
<ClInclude Include="scripting\bindings\network\ScPlayer.hpp" />
|
||||
<ClInclude Include="scripting\bindings\network\ScPlayerGroup.hpp" />
|
||||
<ClInclude Include="scripting\bindings\ride\ScRideStation.hpp" />
|
||||
<ClInclude Include="scripting\Duktape.hpp" />
|
||||
<ClInclude Include="scripting\HookEngine.h" />
|
||||
<ClInclude Include="scripting\Plugin.h" />
|
||||
@@ -863,6 +864,7 @@
|
||||
<ClCompile Include="scripting\bindings\network\ScNetwork.cpp" />
|
||||
<ClCompile Include="scripting\bindings\network\ScPlayer.cpp" />
|
||||
<ClCompile Include="scripting\bindings\network\ScPlayerGroup.cpp" />
|
||||
<ClCompile Include="scripting\bindings\ride\ScRideStation.cpp" />
|
||||
<ClCompile Include="scripting\HookEngine.cpp" />
|
||||
<ClCompile Include="scripting\Plugin.cpp" />
|
||||
<ClCompile Include="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"
|
||||
|
||||
@@ -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<CoordsXYZ>(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<CoordsXYZD>(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<CoordsXYZD>(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:
|
||||
|
||||
136
src/openrct2/scripting/bindings/ride/ScRideStation.cpp
Normal file
136
src/openrct2/scripting/bindings/ride/ScRideStation.cpp
Normal file
@@ -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<CoordsXYZ>(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<CoordsXYZD>(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<CoordsXYZD>(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
|
||||
54
src/openrct2/scripting/bindings/ride/ScRideStation.hpp
Normal file
54
src/openrct2/scripting/bindings/ride/ScRideStation.hpp
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user