mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Move scripting command names to command classes
This way, new commands are required to have this field, or a compiler error will occur.
This commit is contained in:
@@ -47,16 +47,16 @@ namespace OpenRCT2::Scripting
|
||||
};
|
||||
|
||||
static const DukEnumMap<TitleScript> TitleScriptMap({
|
||||
{ "load", TitleScript::Load },
|
||||
{ "location", TitleScript::Location },
|
||||
{ "rotate", TitleScript::Rotate },
|
||||
{ "zoom", TitleScript::Zoom },
|
||||
{ "follow", TitleScript::Follow },
|
||||
{ "speed", TitleScript::Speed },
|
||||
{ "wait", TitleScript::Wait },
|
||||
{ "loadsc", TitleScript::LoadSc },
|
||||
{ "restart", TitleScript::Restart },
|
||||
{ "end", TitleScript::End },
|
||||
{ OpenRCT2::Title::LoadParkCommand::ScriptingName, TitleScript::Load },
|
||||
{ OpenRCT2::Title::SetLocationCommand::ScriptingName, TitleScript::Location },
|
||||
{ OpenRCT2::Title::RotateViewCommand::ScriptingName, TitleScript::Rotate },
|
||||
{ OpenRCT2::Title::SetZoomCommand::ScriptingName, TitleScript::Zoom },
|
||||
{ OpenRCT2::Title::FollowEntityCommand::ScriptingName, TitleScript::Follow },
|
||||
{ OpenRCT2::Title::SetSpeedCommand::ScriptingName, TitleScript::Speed },
|
||||
{ OpenRCT2::Title::WaitCommand::ScriptingName, TitleScript::Wait },
|
||||
{ OpenRCT2::Title::LoadScenarioCommand::ScriptingName, TitleScript::LoadSc },
|
||||
{ OpenRCT2::Title::RestartCommand::ScriptingName, TitleScript::Restart },
|
||||
{ OpenRCT2::Title::EndCommand::ScriptingName, TitleScript::End },
|
||||
});
|
||||
|
||||
template<> DukValue ToDuk(duk_context* ctx, const TitleScript& value)
|
||||
@@ -71,30 +71,26 @@ namespace OpenRCT2::Scripting
|
||||
std::visit(
|
||||
[&obj](auto&& value) {
|
||||
using T = std::decay<decltype(value)>::type;
|
||||
obj.Set("type", T::ScriptingName);
|
||||
if constexpr (std::is_same_v<T, LoadParkCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::Load]);
|
||||
obj.Set("index", value.SaveIndex);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, SetLocationCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::Location]);
|
||||
obj.Set("x", value.Location.X);
|
||||
obj.Set("y", value.Location.Y);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, RotateViewCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::Rotate]);
|
||||
obj.Set("rotations", value.Rotations);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, SetZoomCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::Zoom]);
|
||||
obj.Set("zoom", value.Zoom);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, FollowEntityCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::Follow]);
|
||||
if (value.Follow.SpriteIndex.IsNull())
|
||||
obj.Set("id", nullptr);
|
||||
else
|
||||
@@ -102,17 +98,14 @@ namespace OpenRCT2::Scripting
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, SetSpeedCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::Speed]);
|
||||
obj.Set("speed", value.Speed);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, WaitCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::Wait]);
|
||||
obj.Set("duration", value.Milliseconds);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, LoadScenarioCommand>)
|
||||
{
|
||||
obj.Set("type", TitleScriptMap[TitleScript::LoadSc]);
|
||||
obj.Set("scenario", String::ToStringView(value.Scenario, sizeof(value.Scenario)));
|
||||
}
|
||||
},
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRCT2
|
||||
|
||||
namespace OpenRCT2::Scripting
|
||||
{
|
||||
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 56;
|
||||
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 57;
|
||||
|
||||
// Versions marking breaking changes.
|
||||
static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct EndCommand
|
||||
{
|
||||
static constexpr const char* Name = "End Command";
|
||||
static constexpr const char* ScriptingName = "end";
|
||||
|
||||
int16_t operator()(int16_t timer);
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace OpenRCT2::Title
|
||||
struct FollowEntityCommand
|
||||
{
|
||||
static constexpr const char* Name = "Follow Entity Command";
|
||||
static constexpr const char* ScriptingName = "follow";
|
||||
|
||||
struct
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct LoadParkCommand
|
||||
{
|
||||
static constexpr const char* Name = "Load Park Command";
|
||||
static constexpr const char* ScriptingName = "load";
|
||||
|
||||
uint8_t SaveIndex;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace OpenRCT2::Title
|
||||
struct LoadScenarioCommand
|
||||
{
|
||||
static constexpr const char* Name = "Load Scenario Command";
|
||||
static constexpr const char* ScriptingName = "loadsc";
|
||||
|
||||
utf8 Scenario[TITLE_COMMAND_SCENARIO_LENGTH];
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct RestartCommand
|
||||
{
|
||||
static constexpr const char* Name = "Restart Command";
|
||||
static constexpr const char* ScriptingName = "restart";
|
||||
|
||||
int16_t operator()(int16_t timer);
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct RotateViewCommand
|
||||
{
|
||||
static constexpr const char* Name = "Rotate View Command";
|
||||
static constexpr const char* ScriptingName = "rotate";
|
||||
|
||||
uint8_t Rotations;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct SetLocationCommand
|
||||
{
|
||||
static constexpr const char* Name = "Set Location Command";
|
||||
static constexpr const char* ScriptingName = "location";
|
||||
|
||||
// TODO: Use TileCoordsXY instead
|
||||
struct
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct SetSpeedCommand
|
||||
{
|
||||
static constexpr const char* Name = "Set Speed Command";
|
||||
static constexpr const char* ScriptingName = "speed";
|
||||
|
||||
uint8_t Speed;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct SetZoomCommand
|
||||
{
|
||||
static constexpr const char* Name = "Set Zoom Command";
|
||||
static constexpr const char* ScriptingName = "zoom";
|
||||
|
||||
// TODO: Use ZoomLevel instead
|
||||
uint8_t Zoom;
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRCT2::Title
|
||||
struct WaitCommand
|
||||
{
|
||||
static constexpr const char* Name = "Wait Command";
|
||||
static constexpr const char* ScriptingName = "wait";
|
||||
|
||||
uint16_t Milliseconds;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user