From 2f0af0a005e2b312a66ec7035d0ca279f8a028d2 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Wed, 11 Dec 2024 19:06:47 +0100 Subject: [PATCH] Expose getCostumeStrings to scripts --- src/openrct2/peep/PeepAnimations.cpp | 17 +++++++++++ src/openrct2/peep/PeepAnimations.h | 2 ++ .../scripting/bindings/entity/ScStaff.cpp | 28 +++++++++++-------- .../scripting/bindings/entity/ScStaff.hpp | 1 + 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/openrct2/peep/PeepAnimations.cpp b/src/openrct2/peep/PeepAnimations.cpp index 457bcacc0d..dc205cc928 100644 --- a/src/openrct2/peep/PeepAnimations.cpp +++ b/src/openrct2/peep/PeepAnimations.cpp @@ -12,6 +12,7 @@ #include "../Context.h" #include "../drawing/Drawing.h" #include "../entity/Peep.h" +#include "../entity/Staff.h" #include "../object/ObjectLimits.h" #include "../object/ObjectManager.h" #include "../object/PeepAnimationsObject.h" @@ -110,6 +111,22 @@ namespace OpenRCT2 } } + AnimationPeepType getAnimationPeepType(StaffType staffType) + { + switch (staffType) + { + case StaffType::Handyman: + return AnimationPeepType::Handyman; + case StaffType::Mechanic: + return AnimationPeepType::Mechanic; + case StaffType::Security: + return AnimationPeepType::Security; + case StaffType::Entertainer: + default: + return AnimationPeepType::Entertainer; + } + } + ObjectEntryIndex findPeepAnimationsIndexForType(const AnimationPeepType type) { auto& objManager = GetContext()->GetObjectManager(); diff --git a/src/openrct2/peep/PeepAnimations.h b/src/openrct2/peep/PeepAnimations.h index 93dcea0a1d..b2f8de078a 100644 --- a/src/openrct2/peep/PeepAnimations.h +++ b/src/openrct2/peep/PeepAnimations.h @@ -19,6 +19,7 @@ class PeepAnimationsObject; enum class RCT12PeepAnimationGroup : uint8_t; +enum class StaffType : uint8_t; namespace OpenRCT2 { @@ -32,6 +33,7 @@ namespace OpenRCT2 }; const EnumMap& getAnimationsByPeepType(AnimationPeepType peepType); + AnimationPeepType getAnimationPeepType(StaffType staffType); struct SpriteBounds { diff --git a/src/openrct2/scripting/bindings/entity/ScStaff.cpp b/src/openrct2/scripting/bindings/entity/ScStaff.cpp index d88c90a8f1..51937be074 100644 --- a/src/openrct2/scripting/bindings/entity/ScStaff.cpp +++ b/src/openrct2/scripting/bindings/entity/ScStaff.cpp @@ -38,6 +38,7 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScStaff::animationOffset_get, &ScStaff::animationOffset_set, "animationOffset"); dukglue_register_property(ctx, &ScStaff::animationLength_get, nullptr, "animationLength"); dukglue_register_method(ctx, &ScStaff::getAnimationSpriteIds, "getAnimationSpriteIds"); + dukglue_register_method(ctx, &ScStaff::getCostumeStrings, "getCostumeStrings"); } Staff* ScStaff::GetStaff() const @@ -124,18 +125,8 @@ namespace OpenRCT2::Scripting static const std::vector costumesByStaffType(StaffType staffType) { // TODO: shouldn't get hit repeatedly, but cache these if (and only if) it's too slow - switch (staffType) - { - case StaffType::Handyman: - return getAnimationGroupsByPeepType(AnimationPeepType::Handyman); - case StaffType::Mechanic: - return getAnimationGroupsByPeepType(AnimationPeepType::Mechanic); - case StaffType::Security: - return getAnimationGroupsByPeepType(AnimationPeepType::Security); - case StaffType::Entertainer: - default: - return getAnimationGroupsByPeepType(AnimationPeepType::Entertainer); - } + auto animPeepType = getAnimationPeepType(staffType); + return getAnimationGroupsByPeepType(animPeepType); } std::vector ScStaff::availableCostumes_get() const @@ -152,6 +143,19 @@ namespace OpenRCT2::Scripting return availableCostumes; } + std::vector ScStaff::getCostumeStrings() const + { + auto peep = GetStaff(); + auto animPeepType = getAnimationPeepType(peep->AssignedStaffType); + + std::vector availableCostumes{}; + for (auto& costume : getAvailableCostumeStrings(animPeepType)) + { + availableCostumes.push_back(costume.friendlyName); + } + return availableCostumes; + } + std::string ScStaff::costume_get() const { auto peep = GetStaff(); diff --git a/src/openrct2/scripting/bindings/entity/ScStaff.hpp b/src/openrct2/scripting/bindings/entity/ScStaff.hpp index a38238900c..e34e8bfe63 100644 --- a/src/openrct2/scripting/bindings/entity/ScStaff.hpp +++ b/src/openrct2/scripting/bindings/entity/ScStaff.hpp @@ -60,6 +60,7 @@ namespace OpenRCT2::Scripting void colour_set(uint8_t value); std::vector availableCostumes_get() const; + std::vector getCostumeStrings() const; std::string costume_get() const; void costume_set(const DukValue& value);