From 58c7f46eea3f20de5a1131adcc4fd424ab14329c Mon Sep 17 00:00:00 2001 From: octod Date: Fri, 12 Jan 2024 18:43:17 +0100 Subject: [PATCH] feat: adds has_all method --- src/system/tag/tag_dictionary.cpp | 14 ++++++++++++++ src/system/tag/tag_dictionary.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/system/tag/tag_dictionary.cpp b/src/system/tag/tag_dictionary.cpp index 189aba0..c6acbc2 100644 --- a/src/system/tag/tag_dictionary.cpp +++ b/src/system/tag/tag_dictionary.cpp @@ -13,6 +13,7 @@ void TagDictionary::_bind_methods() ClassDB::bind_method(D_METHOD("add_tag", "tag"), &TagDictionary::add_tag); ClassDB::bind_method(D_METHOD("clear_tags"), &TagDictionary::clear_tags); ClassDB::bind_method(D_METHOD("get_tags"), &TagDictionary::get_tags); + ClassDB::bind_method(D_METHOD("has_all", "tags"), &TagDictionary::has_all); ClassDB::bind_method(D_METHOD("has_tag_path", "tag_path"), &TagDictionary::has_tag_path); ClassDB::bind_method(D_METHOD("has_tag", "tag"), &TagDictionary::has_tag); ClassDB::bind_method(D_METHOD("remove_tag_path", "tag_path"), &TagDictionary::remove_tag_path); @@ -173,6 +174,19 @@ PackedStringArray TagDictionary::get_tags_from_path(const StringName &p_tag_path return out; } +bool TagDictionary::has_all(const PackedStringArray p_tags) const +{ + for (StringName tag : p_tags) + { + if (!tags.has(tag)) + { + return false; + } + } + + return true; +} + bool TagDictionary::has_tag(const StringName &tag) const { return tags.has(tag); diff --git a/src/system/tag/tag_dictionary.h b/src/system/tag/tag_dictionary.h index f77bf25..ecc0ced 100644 --- a/src/system/tag/tag_dictionary.h +++ b/src/system/tag/tag_dictionary.h @@ -61,6 +61,10 @@ namespace ggs /// @param p_tag_path The tag path to get. /// @return PackedStringArray get_tags_from_path(const StringName &p_tag_path) const; + /// @brief Checks if the tag dictionary has all the tags. + /// @param tags The tags to check. + /// @return True if the tag dictionary has all the tags, false otherwise. + bool has_all(const PackedStringArray p_tags) const; /// @brief Returns `true` if the tag dictionary has the tag. /// @param tag The tag to check. /// @return `true` if the tag dictionary has the tag.