Skip to content

Commit

Permalink
feat: adds has_some
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoD committed Jan 12, 2024
1 parent 58c7f46 commit d4de440
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/system/tag/tag_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void TagDictionary::_bind_methods()
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_some", "tags"), &TagDictionary::has_some);
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 @@ -176,7 +177,7 @@ PackedStringArray TagDictionary::get_tags_from_path(const StringName &p_tag_path

bool TagDictionary::has_all(const PackedStringArray p_tags) const
{
for (StringName tag : p_tags)
for (StringName tag : p_tags)
{
if (!tags.has(tag))
{
Expand All @@ -187,6 +188,19 @@ bool TagDictionary::has_all(const PackedStringArray p_tags) const
return true;
}

bool TagDictionary::has_some(const PackedStringArray p_tags) const
{
for (StringName tag : p_tags)
{
if (tags.has(tag))
{
return true;
}
}

return false;
}

bool TagDictionary::has_tag(const StringName &tag) const
{
return tags.has(tag);
Expand Down Expand Up @@ -244,7 +258,7 @@ void TagDictionary::remove_tags(const PackedStringArray &p_tags)
{
PackedStringArray removed_tags = PackedStringArray();
PackedStringArray copy = PackedStringArray(tags);

for (StringName tag : p_tags)
{
int index = tags.find(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 @@ -65,6 +65,10 @@ namespace ggs
/// @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 Checks if the tag dictionary has any of the tags.
/// @param p_tags The tags to check.
/// @return True if the tag dictionary has any of the tags, false otherwise.
bool has_some(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 d4de440

Please sign in to comment.