1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +01:00

Add angle and banking to track segment

This commit is contained in:
Ted John
2022-05-10 21:54:28 +01:00
parent bf1e3412a5
commit 71a6e2bf74
5 changed files with 109 additions and 2 deletions

View File

@@ -1169,7 +1169,7 @@ declare global {
/**
* The slope angle the segment starts with.
*/
readonly beginAngle: number;
readonly beginAngle: TrackSlope;
/**
* The kind of banking the segment starts with.
@@ -1201,7 +1201,7 @@ declare global {
/**
* The slope angle the segment ends with.
*/
readonly endAngle: number;
readonly endAngle: TrackSlope;
/**
* The kind of banking the segment ends with.
@@ -1221,6 +1221,16 @@ declare global {
readonly elements: TrackSegmentElement[];
}
enum TrackSlope {
None = 0,
Up25 = 2,
Up60 = 4,
Down25 = 6,
Down60 = 8,
Up90 = 10,
Down90 = 18
}
enum TrackBanking {
None = 0,
Left = 2,

View File

@@ -440,6 +440,8 @@ void ScriptEngine::Initialise()
dukglue_register_global(ctx, std::make_shared<ScProfiler>(ctx), "profiler");
dukglue_register_global(ctx, std::make_shared<ScScenario>(), "scenario");
RegisterConstants();
_initialised = true;
_transientPluginsEnabled = false;
_transientPluginsStarted = false;
@@ -448,6 +450,72 @@ void ScriptEngine::Initialise()
ClearParkStorage();
}
class ConstantBuilder
{
private:
duk_context* _ctx;
DukValue _obj;
public:
ConstantBuilder(duk_context* ctx)
: _ctx(ctx)
{
duk_push_global_object(_ctx);
_obj = DukValue::take_from_stack(_ctx);
}
ConstantBuilder& Namespace(std::string_view ns)
{
auto flags = DUK_DEFPROP_ENUMERABLE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE
| DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_HAVE_VALUE;
// Create a new object for namespace
duk_push_global_object(_ctx);
duk_push_lstring(_ctx, ns.data(), ns.size());
duk_push_object(_ctx);
// Keep a reference to the namespace object
duk_dup_top(_ctx);
_obj = DukValue::take_from_stack(_ctx);
// Place the namespace object into the global context
duk_def_prop(_ctx, -3, flags);
duk_pop(_ctx);
return *this;
}
ConstantBuilder& Constant(std::string_view name, int32_t value)
{
auto flags = DUK_DEFPROP_ENUMERABLE | DUK_DEFPROP_HAVE_WRITABLE | DUK_DEFPROP_HAVE_ENUMERABLE
| DUK_DEFPROP_HAVE_CONFIGURABLE | DUK_DEFPROP_HAVE_VALUE;
_obj.push();
duk_push_lstring(_ctx, name.data(), name.size());
duk_push_int(_ctx, value);
duk_def_prop(_ctx, -3, flags);
duk_pop(_ctx);
return *this;
}
};
void ScriptEngine::RegisterConstants()
{
ConstantBuilder builder(_context);
builder.Namespace("TrackSlope")
.Constant("None", TRACK_SLOPE_NONE)
.Constant("Up25", TRACK_SLOPE_UP_25)
.Constant("Up60", TRACK_SLOPE_UP_60)
.Constant("Down25", TRACK_SLOPE_DOWN_25)
.Constant("Down60", TRACK_SLOPE_DOWN_60)
.Constant("Up90", TRACK_SLOPE_UP_90)
.Constant("Down90", TRACK_SLOPE_DOWN_90);
builder.Namespace("TrackBanking")
.Constant("None", TRACK_BANK_NONE)
.Constant("BankLeft", TRACK_BANK_LEFT)
.Constant("BankRight", TRACK_BANK_RIGHT)
.Constant("UpsideDown", TRACK_BANK_UPSIDE_DOWN);
}
void ScriptEngine::RefreshPlugins()
{
// Get a list of removed and added plugin files

View File

@@ -252,6 +252,7 @@ namespace OpenRCT2::Scripting
# endif
private:
void RegisterConstants();
void RefreshPlugins();
std::vector<std::string> GetPluginFiles() const;
void UnregisterPlugin(std::string_view path);

View File

@@ -60,6 +60,18 @@ int32_t ScTrackSegment::beginDirection_get() const
return ted.Coordinates.rotation_begin;
}
int32_t ScTrackSegment::beginAngle_get() const
{
const auto& ted = GetTrackElementDescriptor(_type);
return ted.Definition.vangle_start;
}
int32_t ScTrackSegment::beginBank_get() const
{
const auto& ted = GetTrackElementDescriptor(_type);
return ted.Definition.bank_start;
}
int32_t ScTrackSegment::endX_get() const
{
const auto& ted = GetTrackElementDescriptor(_type);
@@ -84,6 +96,18 @@ int32_t ScTrackSegment::endDirection_get() const
return ted.Coordinates.rotation_end;
}
int32_t ScTrackSegment::endAngle_get() const
{
const auto& ted = GetTrackElementDescriptor(_type);
return ted.Definition.vangle_end;
}
int32_t ScTrackSegment::endBank_get() const
{
const auto& ted = GetTrackElementDescriptor(_type);
return ted.Definition.bank_end;
}
int32_t ScTrackSegment::length_get() const
{
const auto& ted = GetTrackElementDescriptor(_type);

View File

@@ -34,10 +34,14 @@ namespace OpenRCT2::Scripting
std::string description_get() const;
int32_t beginZ_get() const;
int32_t beginDirection_get() const;
int32_t beginAngle_get() const;
int32_t beginBank_get() const;
int32_t endX_get() const;
int32_t endY_get() const;
int32_t endZ_get() const;
int32_t endDirection_get() const;
int32_t endAngle_get() const;
int32_t endBank_get() const;
int32_t length_get() const;
DukValue elements_get() const;
};