Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds AttributeContainer::get_attributes_as_dictionary
Browse files Browse the repository at this point in the history
OctoD committed Jan 12, 2024
1 parent 29fd8d6 commit f7c3129
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/system/attribute/attribute_container.cpp
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ void AttributeContainer::_bind_methods()
ClassDB::bind_method(D_METHOD("count_timeouts", "attribute_effect"), &AttributeContainer::count_timeouts);
ClassDB::bind_method(D_METHOD("ensure_attributes", "attributes"), &AttributeContainer::ensure_attributes);
ClassDB::bind_method(D_METHOD("get_attribute", "attribute_name"), &AttributeContainer::get_attribute);
ClassDB::bind_method(D_METHOD("get_attributes_as_dictionary"), &AttributeContainer::get_attributes_as_dictionary);
ClassDB::bind_method(D_METHOD("get_attributes_owner"), &AttributeContainer::get_attributes_owner);
ClassDB::bind_method(D_METHOD("get_attributes"), &AttributeContainer::get_attributes);
ClassDB::bind_method(D_METHOD("get_ongoing_effects"), &AttributeContainer::get_ongoing_effects);
@@ -384,6 +385,24 @@ TypedArray<AttributeEffect> AttributeContainer::get_ongoing_effects() const
return ongoing_effects.duplicate(true);
}

Dictionary AttributeContainer::get_attributes_as_dictionary() const
{
Dictionary attributes_dictionary;

for (int i = 0; i < attributes.size(); i++)
{
Variant attribute_variant = attributes[i];
Attribute *attribute = cast_to<Attribute>(attribute_variant);

if (attribute != nullptr)
{
attributes_dictionary[attribute->get_tag_name()] = attribute->get_value();
}
}

return attributes_dictionary;
}

Node *AttributeContainer::get_attributes_owner() const
{
return attributes_owner;
9 changes: 6 additions & 3 deletions src/system/attribute/attribute_container.h
Original file line number Diff line number Diff line change
@@ -89,9 +89,12 @@ namespace ggs
/// @brief Gets the ongoing attributes' effects of the container.
/// @return The ongoing attributes' effects of the container.
TypedArray<AttributeEffect> get_ongoing_effects() const;
/// @brief Gets the owner of the attributes.
/// @return The owner of the attributes.
Node *get_attributes_owner() const;
/// @brief Returns the attributes as a dictionary. It is a dictionary where keys are the Attribute's tag_name and the value is the Attribute value.
/// @return The attributes as a dictionary.
Dictionary get_attributes_as_dictionary() const;
/// @brief Gets the owner of the attributes.
/// @return The owner of the attributes.
Node *get_attributes_owner() const;
/// @brief Get the attributes of the container.
/// @return The attributes of the container.
TypedArray<Attribute> get_attributes() const;

0 comments on commit f7c3129

Please sign in to comment.