Add banner properties to plugin API for large scenery, walls and banners

This commit is contained in:
Stephan Spengler 2024-03-26 12:42:09 +01:00 committed by GitHub
parent 8e157bd709
commit 2913a0686a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 137 additions and 7 deletions

View File

@ -1,6 +1,7 @@
0.4.10 (in development)
------------------------------------------------------------------------
- Feature: [#18171] Add port of the RCT1 Stand-Up Roller Coaster.
- Feature: [#21590] [Plugin] Plugins can now read and write banner properties of tile elements.
- Feature: [#21636] Add shortcut key for sorting tile elements.
- Feature: [objects#294] Add scenery versions of wooden truss supports.
- Feature: [objects#295] Flipped version of wooden post.

View File

@ -1558,10 +1558,14 @@ declare global {
direction: Direction;
object: number;
primaryColour: number;
/** If the element is a banner, this is the text colour. */
secondaryColour: number;
tertiaryColour: number;
bannerIndex: number | null;
slope: Direction;
/** Writing to bannerIndex is deprecated and may result in uncontrolled behaviour. */
readonly bannerIndex: number | null;
/** If the element is a banner, this is its text. */
bannerText: string | null;
}
interface EntranceElement extends BaseTileElement {
@ -1582,16 +1586,28 @@ declare global {
direction: Direction;
object: number;
primaryColour: number;
/** If the element is a banner, this is the text colour. */
secondaryColour: number;
tertiaryColour: number;
bannerIndex: number | null;
sequence: number;
/** Writing to bannerIndex is deprecated and may result in uncontrolled behaviour. */
readonly bannerIndex: number | null;
/** If the element is a banner, this is its text. */
bannerText: string | null;
}
interface BannerElement extends BaseTileElement {
type: "banner";
direction: Direction;
bannerIndex: number;
object: number;
primaryColour: number;
/** This is the text colour. */
secondaryColour: number;
/** Writing to bannerIndex is deprecated and may result in uncontrolled behaviour. */
readonly bannerIndex: number;
bannerText: string;
isNoEntry: boolean;
}
/**

View File

@ -47,7 +47,7 @@ namespace OpenRCT2
namespace OpenRCT2::Scripting
{
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 83;
static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 84;
// Versions marking breaking changes.
static constexpr int32_t API_VERSION_33_PEEP_DEPRECATION = 33;

View File

@ -1153,6 +1153,12 @@ namespace OpenRCT2::Scripting
duk_push_int(ctx, el->GetEntranceType());
break;
}
case TileElementType::Banner:
{
auto* el = _element->AsBanner();
duk_push_int(ctx, el->GetBanner()->type);
break;
}
default:
{
duk_push_null(ctx);
@ -1207,6 +1213,13 @@ namespace OpenRCT2::Scripting
Invalidate();
break;
}
case TileElementType::Banner:
{
auto* el = _element->AsBanner();
el->GetBanner()->type = index;
Invalidate();
break;
}
default:
break;
}
@ -1314,6 +1327,12 @@ namespace OpenRCT2::Scripting
duk_push_int(ctx, el->GetPrimaryColour());
break;
}
case TileElementType::Banner:
{
auto* el = _element->AsBanner();
duk_push_int(ctx, el->GetBanner()->colour);
break;
}
default:
{
duk_push_null(ctx);
@ -1348,6 +1367,13 @@ namespace OpenRCT2::Scripting
Invalidate();
break;
}
case TileElementType::Banner:
{
auto* el = _element->AsBanner();
el->GetBanner()->colour = value;
Invalidate();
break;
}
default:
break;
}
@ -1377,6 +1403,12 @@ namespace OpenRCT2::Scripting
duk_push_int(ctx, el->GetSecondaryColour());
break;
}
case TileElementType::Banner:
{
auto* el = _element->AsBanner();
duk_push_int(ctx, el->GetBanner()->text_colour);
break;
}
default:
{
duk_push_null(ctx);
@ -1411,6 +1443,13 @@ namespace OpenRCT2::Scripting
Invalidate();
break;
}
case TileElementType::Banner:
{
auto* el = _element->AsBanner();
el->GetBanner()->text_colour = value;
Invalidate();
break;
}
default:
break;
}
@ -2040,13 +2079,75 @@ namespace OpenRCT2::Scripting
duk_push_uint(ctx, _element->GetOwner());
return DukValue::take_from_stack(ctx);
}
void ScTileElement::owner_set(uint8_t value)
{
ThrowIfGameStateNotMutable();
_element->SetOwner(value);
}
DukValue ScTileElement::bannerText_get() const
{
auto& scriptEngine = GetContext()->GetScriptEngine();
auto* ctx = scriptEngine.GetContext();
BannerIndex idx = _element->GetBannerIndex();
if (idx == BannerIndex::GetNull())
duk_push_null(ctx);
else
duk_push_string(ctx, GetBanner(idx)->GetText().c_str());
return DukValue::take_from_stack(ctx);
}
void ScTileElement::bannerText_set(std::string value)
{
ThrowIfGameStateNotMutable();
BannerIndex idx = _element->GetBannerIndex();
if (idx != BannerIndex::GetNull())
{
auto banner = GetBanner(idx);
banner->text = value;
if (_element->GetType() != TileElementType::Banner)
{
if (value.empty())
banner->ride_index = BannerGetClosestRideIndex({ banner->position.ToCoordsXY(), 16 });
else
banner->ride_index = RideId::GetNull();
if (banner->ride_index.IsNull())
banner->flags &= ~BANNER_FLAG_LINKED_TO_RIDE;
else
banner->flags |= BANNER_FLAG_LINKED_TO_RIDE;
}
}
}
DukValue ScTileElement::isNoEntry_get() const
{
auto& scriptEngine = GetContext()->GetScriptEngine();
auto* ctx = scriptEngine.GetContext();
auto* el = _element->AsBanner();
if (el != nullptr)
duk_push_boolean(ctx, (el->GetBanner()->flags & BANNER_FLAG_NO_ENTRY) != 0);
else
duk_push_null(ctx);
return DukValue::take_from_stack(ctx);
}
void ScTileElement::isNoEntry_set(bool value)
{
ThrowIfGameStateNotMutable();
auto* el = _element->AsBanner();
if (el != nullptr)
{
if (value)
{
el->GetBanner()->flags |= BANNER_FLAG_NO_ENTRY;
}
else
{
el->GetBanner()->flags &= ~BANNER_FLAG_NO_ENTRY;
}
Invalidate();
}
}
void ScTileElement::Invalidate()
{
MapInvalidateTileFull(_coords);
@ -2070,17 +2171,20 @@ namespace OpenRCT2::Scripting
// Track | Small Scenery | Wall | Entrance | Large Scenery | Banner
dukglue_register_property(ctx, &ScTileElement::direction_get, &ScTileElement::direction_set, "direction");
// Path | Small Scenery | Wall | Entrance | Large Scenery
// Path | Small Scenery | Wall | Entrance | Large Scenery | Banner
dukglue_register_property(ctx, &ScTileElement::object_get, &ScTileElement::object_set, "object");
// Small Scenery | Wall | Large Scenery
// Small Scenery | Wall | Large Scenery | Banner
dukglue_register_property(ctx, &ScTileElement::primaryColour_get, &ScTileElement::primaryColour_set, "primaryColour");
dukglue_register_property(
ctx, &ScTileElement::secondaryColour_get, &ScTileElement::secondaryColour_set, "secondaryColour");
// Small Scenery | Wall | Large Scenery
dukglue_register_property(
ctx, &ScTileElement::tertiaryColour_get, &ScTileElement::tertiaryColour_set, "tertiaryColour");
// Wall | Large Scenery | Banner
dukglue_register_property(ctx, &ScTileElement::bannerText_get, &ScTileElement::bannerText_set, "bannerText");
dukglue_register_property(ctx, &ScTileElement::bannerIndex_get, &ScTileElement::bannerIndex_set, "bannerIndex");
// Path | Track | Entrance
@ -2152,6 +2256,9 @@ namespace OpenRCT2::Scripting
ctx, &ScTileElement::footpathObject_get, &ScTileElement::footpathObject_set, "footpathObject");
dukglue_register_property(
ctx, &ScTileElement::footpathSurfaceObject_get, &ScTileElement::footpathSurfaceObject_set, "footpathSurfaceObject");
// Banner only
dukglue_register_property(ctx, &ScTileElement::isNoEntry_get, &ScTileElement::isNoEntry_set, "isNoEntry");
}
} // namespace OpenRCT2::Scripting

View File

@ -205,6 +205,12 @@ namespace OpenRCT2::Scripting
DukValue owner_get() const;
void owner_set(uint8_t value);
DukValue bannerText_get() const;
void bannerText_set(std::string value);
DukValue isNoEntry_get() const;
void isNoEntry_set(bool value);
void Invalidate();
public: