Skip to content

Commit

Permalink
feat: adds has_all method
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoD committed Jan 12, 2024
1 parent 0650762 commit 58c7f46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/system/tag/tag_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/system/tag/tag_dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 58c7f46

Please sign in to comment.