Print message when attempting to set invalid property

Added for the previously track setters, and all surface element properties.
This commit is contained in:
Hielke Morsink 2022-05-08 00:40:34 +02:00
parent 4b081a8937
commit 813618d30b
No known key found for this signature in database
GPG Key ID: FE0B343DF883E7F2
1 changed files with 82 additions and 19 deletions

View File

@ -150,6 +150,7 @@ namespace OpenRCT2::Scripting
} }
default: default:
{ {
std::puts("Element of this type doesn't have a slope.");
duk_push_null(ctx); duk_push_null(ctx);
break; break;
} }
@ -173,6 +174,10 @@ namespace OpenRCT2::Scripting
el->SetSlope(value); el->SetSlope(value);
Invalidate(); Invalidate();
} }
else
{
std::puts("Element of this type doesn't have a slope.");
}
} }
DukValue ScTileElement::waterHeight_get() const DukValue ScTileElement::waterHeight_get() const
@ -180,20 +185,28 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext(); auto ctx = GetContext()->GetScriptEngine().GetContext();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el != nullptr)
{
duk_push_int(ctx, el->GetWaterHeight()); duk_push_int(ctx, el->GetWaterHeight());
}
else else
{
std::puts("Only surface tile elements have the 'waterHeight' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
void ScTileElement::waterHeight_set(int32_t value) void ScTileElement::waterHeight_set(int32_t value)
{ {
ThrowIfGameStateNotMutable(); ThrowIfGameStateNotMutable();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el == nullptr)
{ {
el->SetWaterHeight(value); std::puts("Cannot set 'waterHeight' property, tile element is not a SurfaceElement.");
Invalidate(); return;
} }
el->SetWaterHeight(value);
Invalidate();
} }
DukValue ScTileElement::surfaceStyle_get() const DukValue ScTileElement::surfaceStyle_get() const
@ -201,20 +214,28 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext(); auto ctx = GetContext()->GetScriptEngine().GetContext();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el != nullptr)
{
duk_push_int(ctx, el->GetSurfaceStyle()); duk_push_int(ctx, el->GetSurfaceStyle());
}
else else
{
std::puts("Only surface tile elements have the 'surfaceStyle' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
void ScTileElement::surfaceStyle_set(uint32_t value) void ScTileElement::surfaceStyle_set(uint32_t value)
{ {
ThrowIfGameStateNotMutable(); ThrowIfGameStateNotMutable();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el == nullptr)
{ {
el->SetSurfaceStyle(value); std::puts("Cannot set 'surfaceStyle' property, tile element is not a SurfaceElement.");
Invalidate(); return;
} }
el->SetSurfaceStyle(value);
Invalidate();
} }
DukValue ScTileElement::edgeStyle_get() const DukValue ScTileElement::edgeStyle_get() const
@ -222,20 +243,28 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext(); auto ctx = GetContext()->GetScriptEngine().GetContext();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el != nullptr)
{
duk_push_int(ctx, el->GetEdgeStyle()); duk_push_int(ctx, el->GetEdgeStyle());
}
else else
{
std::puts("Only surface tile elements have the 'edgeStyle' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
void ScTileElement::edgeStyle_set(uint32_t value) void ScTileElement::edgeStyle_set(uint32_t value)
{ {
ThrowIfGameStateNotMutable(); ThrowIfGameStateNotMutable();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el == nullptr)
{ {
el->SetEdgeStyle(value); std::puts("Cannot set 'edgeStyle' property, tile element is not a SurfaceElement.");
Invalidate(); return;
} }
el->SetEdgeStyle(value);
Invalidate();
} }
DukValue ScTileElement::grassLength_get() const DukValue ScTileElement::grassLength_get() const
@ -243,21 +272,29 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext(); auto ctx = GetContext()->GetScriptEngine().GetContext();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el != nullptr)
{
duk_push_int(ctx, el->GetGrassLength()); duk_push_int(ctx, el->GetGrassLength());
}
else else
{
std::puts("Only surface tile elements have the 'grassLength' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
void ScTileElement::grassLength_set(uint8_t value) void ScTileElement::grassLength_set(uint8_t value)
{ {
ThrowIfGameStateNotMutable(); ThrowIfGameStateNotMutable();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el == nullptr)
{ {
// TODO: Give warning when value > GRASS_LENGTH_CLUMPS_2 std::puts("Cannot set 'grassLength' property, tile element is not a SurfaceElement.");
el->SetGrassLengthAndInvalidate(value, _coords); return;
Invalidate();
} }
// TODO: Give warning when value > GRASS_LENGTH_CLUMPS_2
el->SetGrassLengthAndInvalidate(value, _coords);
Invalidate();
} }
DukValue ScTileElement::hasOwnership_get() const DukValue ScTileElement::hasOwnership_get() const
@ -265,9 +302,14 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext(); auto ctx = GetContext()->GetScriptEngine().GetContext();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el != nullptr)
{
duk_push_boolean(ctx, el->GetOwnership() & OWNERSHIP_OWNED); duk_push_boolean(ctx, el->GetOwnership() & OWNERSHIP_OWNED);
}
else else
{
std::puts("Only surface tile elements have the 'hasOwnership' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
@ -281,7 +323,10 @@ namespace OpenRCT2::Scripting
duk_push_boolean(ctx, (ownership & OWNERSHIP_OWNED) || (ownership & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED)); duk_push_boolean(ctx, (ownership & OWNERSHIP_OWNED) || (ownership & OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED));
} }
else else
{
std::puts("Only surface tile elements have the 'hasConstructionRights' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
@ -290,20 +335,28 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext(); auto ctx = GetContext()->GetScriptEngine().GetContext();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el != nullptr)
{
duk_push_int(ctx, el->GetOwnership()); duk_push_int(ctx, el->GetOwnership());
}
else else
{
std::puts("Only surface tile elements have the 'ownership' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
void ScTileElement::ownership_set(uint8_t value) void ScTileElement::ownership_set(uint8_t value)
{ {
ThrowIfGameStateNotMutable(); ThrowIfGameStateNotMutable();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el == nullptr)
{ {
el->SetOwnership(value); std::puts("Cannot set 'ownership' property, tile element is not a SurfaceElement.");
Invalidate(); return;
} }
el->SetOwnership(value);
Invalidate();
} }
DukValue ScTileElement::parkFences_get() const DukValue ScTileElement::parkFences_get() const
@ -311,20 +364,28 @@ namespace OpenRCT2::Scripting
auto ctx = GetContext()->GetScriptEngine().GetContext(); auto ctx = GetContext()->GetScriptEngine().GetContext();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el != nullptr)
{
duk_push_int(ctx, el->GetParkFences()); duk_push_int(ctx, el->GetParkFences());
}
else else
{
std::puts("Only surface tile elements have the 'parkFences' property.");
duk_push_null(ctx); duk_push_null(ctx);
}
return DukValue::take_from_stack(ctx); return DukValue::take_from_stack(ctx);
} }
void ScTileElement::parkFences_set(uint8_t value) void ScTileElement::parkFences_set(uint8_t value)
{ {
ThrowIfGameStateNotMutable(); ThrowIfGameStateNotMutable();
auto el = _element->AsSurface(); auto el = _element->AsSurface();
if (el != nullptr) if (el == nullptr)
{ {
el->SetParkFences(value); std::puts("Cannot set 'parkFences' property, tile element is not a SurfaceElement.");
Invalidate(); return;
} }
el->SetParkFences(value);
Invalidate();
} }
DukValue ScTileElement::trackType_get() const DukValue ScTileElement::trackType_get() const
@ -452,6 +513,7 @@ namespace OpenRCT2::Scripting
} }
catch (const DukException& e) catch (const DukException& e)
{ {
std::puts(e.what());
} }
} }
@ -666,6 +728,7 @@ namespace OpenRCT2::Scripting
} }
catch (const DukException& e) catch (const DukException& e)
{ {
std::puts(e.what());
} }
} }