Implement SmallSceneryObject for getObject plugin API (#11489)

This commit is contained in:
Ted John 2020-04-27 17:41:49 +01:00 committed by GitHub
parent 2e50cd44ba
commit 06bbf5ddda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 109 additions and 4 deletions

View File

@ -119,6 +119,7 @@ declare global {
*/
getObject(type: ObjectType, index: number): Object;
getObject(type: "ride", index: number): RideObject;
getObject(type: "small_scenery", index: number): SmallSceneryObject;
getAllObjects(type: ObjectType): Object[];
getAllObjects(type: "ride"): RideObject[];
@ -450,6 +451,31 @@ declare global {
readonly capacity: string;
}
/**
* Represents the object definition of a small scenery item such a tree.
*/
interface SmallSceneryObject extends Object {
/**
* Raw bit flags that describe characteristics of the scenery item.
*/
readonly flags: number;
/**
* The default clearance height of the scenery item.
*/
readonly height: number;
/**
* How much the scenery item costs to build.
*/
readonly price: number;
/**
* How much the scenery item costs to remove.
*/
readonly removalPrice: number;
}
/**
* Represents a ride or stall within the park.
*/
@ -607,10 +633,10 @@ declare global {
* Park APIs
*/
/**
* The type of park message, including icon and behaviour.
*/
type ParkMessageType =
/**
* The type of park message, including icon and behaviour.
*/
type ParkMessageType =
"attraction" | "peep_on_attraction" | "peep" | "money" | "blank" | "research" | "guests" | "award" | "chart";
interface ParkMessage {

View File

@ -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));
}

View File

@ -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

View File

@ -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);