diff --git a/src/system/attribute/attribute_container.cpp b/src/system/attribute/attribute_container.cpp index aeb9cb9..b9abfb6 100644 --- a/src/system/attribute/attribute_container.cpp +++ b/src/system/attribute/attribute_container.cpp @@ -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 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_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; diff --git a/src/system/attribute/attribute_container.h b/src/system/attribute/attribute_container.h index 80bbd8a..f23008b 100644 --- a/src/system/attribute/attribute_container.h +++ b/src/system/attribute/attribute_container.h @@ -89,9 +89,12 @@ namespace ggs /// @brief Gets the ongoing attributes' effects of the container. /// @return The ongoing attributes' effects of the container. TypedArray 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 get_attributes() const;