mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 12:33:17 +01:00
Implement SmallSceneryObject for getObject plugin API (#11489)
This commit is contained in:
@@ -59,6 +59,8 @@ namespace OpenRCT2::Scripting
|
||||
{
|
||||
case OBJECT_TYPE_RIDE:
|
||||
return GetObjectAsDukValue(ctx, std::make_shared<ScRideObject>(type, index));
|
||||
case OBJECT_TYPE_SMALL_SCENERY:
|
||||
return GetObjectAsDukValue(ctx, std::make_shared<ScSmallSceneryObject>(type, index));
|
||||
default:
|
||||
return GetObjectAsDukValue(ctx, std::make_shared<ScObject>(type, index));
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
# include "../common.h"
|
||||
# include "../object/ObjectManager.h"
|
||||
# include "../object/RideObject.h"
|
||||
# include "../object/SmallSceneryObject.h"
|
||||
# include "Duktape.hpp"
|
||||
# include "ScriptEngine.h"
|
||||
|
||||
@@ -147,6 +148,81 @@ namespace OpenRCT2::Scripting
|
||||
return static_cast<RideObject*>(ScObject::GetObject());
|
||||
}
|
||||
};
|
||||
|
||||
class ScSmallSceneryObject : public ScObject
|
||||
{
|
||||
public:
|
||||
ScSmallSceneryObject(uint8_t type, int32_t index)
|
||||
: ScObject(type, index)
|
||||
{
|
||||
}
|
||||
|
||||
static void Register(duk_context* ctx)
|
||||
{
|
||||
dukglue_set_base_class<ScObject, ScSmallSceneryObject>(ctx);
|
||||
dukglue_register_property(ctx, &ScSmallSceneryObject::flags_get, nullptr, "flags");
|
||||
dukglue_register_property(ctx, &ScSmallSceneryObject::height_get, nullptr, "height");
|
||||
dukglue_register_property(ctx, &ScSmallSceneryObject::price_get, nullptr, "price");
|
||||
dukglue_register_property(ctx, &ScSmallSceneryObject::removalPrice_get, nullptr, "removalPrice");
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t flags_get() const
|
||||
{
|
||||
auto sceneryEntry = GetLegacyData();
|
||||
if (sceneryEntry != nullptr)
|
||||
{
|
||||
return sceneryEntry->small_scenery.flags;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t height_get() const
|
||||
{
|
||||
auto sceneryEntry = GetLegacyData();
|
||||
if (sceneryEntry != nullptr)
|
||||
{
|
||||
return sceneryEntry->small_scenery.height;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t price_get() const
|
||||
{
|
||||
auto sceneryEntry = GetLegacyData();
|
||||
if (sceneryEntry != nullptr)
|
||||
{
|
||||
return sceneryEntry->small_scenery.price;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t removalPrice_get() const
|
||||
{
|
||||
auto sceneryEntry = GetLegacyData();
|
||||
if (sceneryEntry != nullptr)
|
||||
{
|
||||
return sceneryEntry->small_scenery.removal_price;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
rct_scenery_entry* GetLegacyData() const
|
||||
{
|
||||
auto obj = GetObject();
|
||||
if (obj != nullptr)
|
||||
{
|
||||
return static_cast<rct_scenery_entry*>(obj->GetLegacyData());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SmallSceneryObject* GetObject() const
|
||||
{
|
||||
return static_cast<SmallSceneryObject*>(ScObject::GetObject());
|
||||
}
|
||||
};
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
#endif
|
||||
|
||||
@@ -375,6 +375,7 @@ void ScriptEngine::Initialise()
|
||||
ScMap::Register(ctx);
|
||||
ScNetwork::Register(ctx);
|
||||
ScObject::Register(ctx);
|
||||
ScSmallSceneryObject::Register(ctx);
|
||||
ScPark::Register(ctx);
|
||||
ScPlayer::Register(ctx);
|
||||
ScPlayerGroup::Register(ctx);
|
||||
|
||||
Reference in New Issue
Block a user