1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Rework reading peep anim object properties

This commit is contained in:
Aaron van Geffen
2024-12-10 23:39:58 +01:00
parent d768811c5c
commit 4f1a7c72aa
4 changed files with 46 additions and 16 deletions

View File

@@ -58,11 +58,8 @@ void PeepAnimationsObject::ReadJson(IReadObjectContext* context, json_t& root)
Guard::Assert(root.is_object(), "PeepAnimationsObject::ReadJson expects parameter root to be an object");
PopulateTablesFromJson(context, root);
Guard::Assert(root["peepType"].is_string(), "PeepAnimationsObject::ReadJson expects peepType to be a string");
_peepType = animationPeepTypeMap[Json::GetString(root["peepType"])];
Guard::Assert(root["isSlowWalking"].is_boolean(), "PeepAnimationsObject::ReadJson expects isSlowWalking to be a boolean");
_slowWalking = Json::GetBoolean(root["isSlowWalking"]);
Guard::Assert(root["properties"].is_object(), "PeepAnimationsObject::ReadJson expects properties to be an object");
ReadProperties(root["properties"]);
auto& requiredAnimationMap = getAnimationsByPeepType(_peepType);
_animationGroups.clear();
@@ -147,6 +144,21 @@ PeepAnimations PeepAnimationsObject::ReadAnimations(const EnumMap<PeepAnimationT
return group;
}
void PeepAnimationsObject::ReadProperties(json_t& props)
{
Guard::Assert(props["peepType"].is_string(), "PeepAnimationsObject::ReadProperties expects peepType to be a string");
_peepType = animationPeepTypeMap[Json::GetString(props["peepType"])];
Guard::Assert(
props["isSlowWalking"].is_boolean(), "PeepAnimationsObject::ReadProperties expects isSlowWalking to be a boolean");
_slowWalking = Json::GetBoolean(props["isSlowWalking"], false);
Guard::Assert(
props["noRandomPlacement"].is_boolean(),
"PeepAnimationsObject::ReadProperties expects noRandomPlacement to be a boolean");
_noRandomPlacement = Json::GetBoolean(props["noRandomPlacement"], false);
}
std::string PeepAnimationsObject::GetCostumeName() const
{
return GetStringTable().GetString(ObjectStringID::NAME);

View File

@@ -22,15 +22,17 @@ class PeepAnimationsObject final : public Object
{
private:
ImageIndex _imageOffsetId;
std::vector<OpenRCT2::PeepAnimations> _animationGroups;
OpenRCT2::AnimationPeepType _peepType;
bool _slowWalking;
std::vector<OpenRCT2::PeepAnimations> _animationGroups;
bool _noRandomPlacement;
public:
static constexpr ObjectType kObjectType = ObjectType::PeepAnimations;
void ReadJson(IReadObjectContext* context, json_t& root) override;
OpenRCT2::PeepAnimations ReadAnimations(const EnumMap<PeepAnimationType>& requiredAnimationMap, json_t& animations);
void ReadProperties(json_t& properties);
void Load() override;
void Unload() override;
@@ -47,11 +49,16 @@ public:
RCT12PeepAnimationGroup GetLegacyPosition(PeepAnimationGroup animGroup) const;
std::string_view GetScriptName(PeepAnimationGroup animGroup) const;
bool IsSlowWalking()
bool IsSlowWalking() const
{
return _slowWalking;
};
bool ShouldExcludeFromRandomPlacement() const
{
return _noRandomPlacement;
}
void DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const override;
void SetRepositoryItem(ObjectRepositoryItem* item) const override;
};

View File

@@ -133,35 +133,45 @@ namespace OpenRCT2
return nullptr;
}
std::vector<ObjectEntryIndex> findAllPeepAnimationsIndexesForType(const AnimationPeepType type)
std::vector<ObjectEntryIndex> findAllPeepAnimationsIndexesForType(const AnimationPeepType type, bool randomOnly)
{
std::vector<ObjectEntryIndex> output{};
auto& objManager = GetContext()->GetObjectManager();
for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++)
{
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(i);
if (animObj != nullptr && animObj->GetPeepType() == type)
output.push_back(i);
if (animObj == nullptr || animObj->GetPeepType() != type)
continue;
if (randomOnly && animObj->ShouldExcludeFromRandomPlacement())
continue;
output.push_back(i);
}
return output;
}
std::vector<PeepAnimationsObject*> findAllPeepAnimationsObjectForType(const AnimationPeepType type)
std::vector<PeepAnimationsObject*> findAllPeepAnimationsObjectForType(const AnimationPeepType type, bool randomOnly)
{
std::vector<PeepAnimationsObject*> output{};
auto& objManager = GetContext()->GetObjectManager();
for (auto i = 0u; i < kMaxPeepAnimationsObjects; i++)
{
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(i);
if (animObj != nullptr && animObj->GetPeepType() == type)
output.push_back(animObj);
if (animObj == nullptr || animObj->GetPeepType() != type)
continue;
if (randomOnly && animObj->ShouldExcludeFromRandomPlacement())
continue;
output.push_back(animObj);
}
return output;
}
ObjectEntryIndex findRandomPeepAnimationsIndexForType(const AnimationPeepType type)
{
auto costumes = findAllPeepAnimationsIndexesForType(type);
auto costumes = findAllPeepAnimationsIndexesForType(type, true);
if (costumes.empty())
return OBJECT_ENTRY_INDEX_NULL;

View File

@@ -70,8 +70,9 @@ namespace OpenRCT2
ObjectEntryIndex findPeepAnimationsIndexForType(const AnimationPeepType type);
PeepAnimationsObject* findPeepAnimationsObjectForType(const AnimationPeepType type);
std::vector<ObjectEntryIndex> findAllPeepAnimationsIndexesForType(const AnimationPeepType type);
std::vector<PeepAnimationsObject*> findAllPeepAnimationsObjectForType(const AnimationPeepType type);
std::vector<ObjectEntryIndex> findAllPeepAnimationsIndexesForType(const AnimationPeepType type, bool randomOnly = false);
std::vector<PeepAnimationsObject*> findAllPeepAnimationsObjectForType(
const AnimationPeepType type, bool randomOnly = false);
ObjectEntryIndex findRandomPeepAnimationsIndexForType(const AnimationPeepType type);