1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Add scenery group object interface

This commit is contained in:
Ted John
2023-04-17 22:35:09 +01:00
parent 530dfac7c9
commit 2729956cef
6 changed files with 137 additions and 1 deletions

View File

@@ -1777,6 +1777,40 @@ declare global {
readonly removalPrice: number;
}
/**
* Represents the object definition of a scenery group.
*/
interface SceneryGroupObject extends LoadedImageObject {
/**
* The scenery items that belong to this scenery group.
*/
readonly items: SceneryGroupObjectItem[];
}
interface SceneryGroupObjectItem {
/**
* The JSON identifier of the object.
* Undefined if object only has a legacy identifier.
*/
identifier?: string;
/**
* The DAT identifier of the object.
* Undefined if object only has a JSON identifier.
*/
legacyIdentifier?: string;
/**
* The type of object
*/
type: ObjectType;
/**
* The object index
*/
object: number | null;
}
/**
* Represents a ride or stall within the park.
*/

View File

@@ -243,3 +243,8 @@ uint16_t SceneryGroupObject::GetNumIncludedObjects() const
{
return static_cast<uint16_t>(_items.size());
}
const std::vector<ObjectEntryDescriptor>& SceneryGroupObject::GetItems() const
{
return _items;
}

View File

@@ -41,6 +41,7 @@ public:
void SetRepositoryItem(ObjectRepositoryItem* item) const override;
uint16_t GetNumIncludedObjects() const;
const std::vector<ObjectEntryDescriptor>& GetItems() const;
private:
static std::vector<ObjectEntryDescriptor> ReadItems(OpenRCT2::IStream* stream);

View File

@@ -405,6 +405,7 @@ void ScriptEngine::Initialise()
ScNetwork::Register(ctx);
ScObject::Register(ctx);
ScSmallSceneryObject::Register(ctx);
ScSceneryGroupObject::Register(ctx);
ScPark::Register(ctx);
ScParkMessage::Register(ctx);
ScPlayer::Register(ctx);

View File

@@ -168,6 +168,8 @@ namespace OpenRCT2::Scripting
return GetObjectAsDukValue(ctx, std::make_shared<ScRideObject>(type, index));
case ObjectType::SmallScenery:
return GetObjectAsDukValue(ctx, std::make_shared<ScSmallSceneryObject>(type, index));
case ObjectType::SceneryGroup:
return GetObjectAsDukValue(ctx, std::make_shared<ScSceneryGroupObject>(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/SceneryGroupObject.h"
# include "../../../object/SmallSceneryObject.h"
# include "../../Duktape.hpp"
# include "../../ScriptEngine.h"
@@ -58,7 +59,7 @@ namespace OpenRCT2::Scripting
return static_cast<ObjectType>(i);
}
}
return ObjectType::None;
return std::nullopt;
}
static std::string_view ObjectTypeToString(uint8_t type)
@@ -865,6 +866,98 @@ namespace OpenRCT2::Scripting
return static_cast<SmallSceneryObject*>(ScObject::GetObject());
}
};
class ScSceneryGroupObject : public ScObject
{
public:
ScSceneryGroupObject(ObjectType type, int32_t index)
: ScObject(type, index)
{
}
static void Register(duk_context* ctx)
{
dukglue_set_base_class<ScObject, ScSceneryGroupObject>(ctx);
dukglue_register_property(ctx, &ScSceneryGroupObject::items_get, nullptr, "items");
}
private:
DukValue items_get() const
{
auto* gameContext = GetContext();
auto* ctx = gameContext->GetScriptEngine().GetContext();
duk_push_array(ctx);
auto obj = GetObject();
if (obj != nullptr)
{
auto& objManager = gameContext->GetObjectManager();
duk_uarridx_t index = 0;
auto& items = obj->GetItems();
for (const auto& item : items)
{
auto objectIndex = objManager.GetLoadedObjectEntryIndex(item);
auto object = objManager.GetLoadedObject(item);
DukObject dukObj(ctx);
if (item.Generation == ObjectGeneration::JSON)
{
dukObj.Set("identifier", item.Identifier);
if (object != nullptr)
{
auto legacyIdentifier = object->GetLegacyIdentifier();
if (!legacyIdentifier.empty())
{
dukObj.Set("legacyIdentifier", legacyIdentifier);
}
}
}
else
{
dukObj.Set("legacyIdentifier", item.Entry.GetName());
if (object != nullptr)
{
auto identifier = object->GetIdentifier();
if (!identifier.empty())
{
dukObj.Set("identifier", identifier);
}
}
}
if (object != nullptr)
{
dukObj.Set("type", ObjectTypeToString(EnumValue(object->GetObjectType())));
}
else
{
dukObj.Set("type", ObjectTypeToString(EnumValue(item.Type)));
}
if (objectIndex == OBJECT_ENTRY_INDEX_NULL)
{
dukObj.Set("object", nullptr);
}
else
{
dukObj.Set("object", objectIndex);
}
dukObj.Take().push();
duk_put_prop_index(ctx, -2, index);
index++;
}
}
return DukValue::take_from_stack(ctx, -1);
}
protected:
SceneryGroupObject* GetObject() const
{
return static_cast<SceneryGroupObject*>(ScObject::GetObject());
}
};
} // namespace OpenRCT2::Scripting
#endif