From 107bea9c2e323d15948beeb759683a388f8f6eac Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 22 Apr 2023 13:38:54 -0400 Subject: [PATCH 1/4] implement: add "GetSubTags" to "Tags" --- Source/Engine/Level/Tags.cpp | 18 ++++++++++++++++++ Source/Engine/Level/Tags.h | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/Source/Engine/Level/Tags.cpp b/Source/Engine/Level/Tags.cpp index b9b3b1f79..b16928630 100644 --- a/Source/Engine/Level/Tags.cpp +++ b/Source/Engine/Level/Tags.cpp @@ -55,6 +55,24 @@ Tag Tags::Get(const StringView& tagName) return tag; } +Array Tags::GetSubTags(Tag parentTag) +{ + Array subTags = Array(); + + auto _parentTagName = parentTag.ToString(); + + for (int i = 0; i < Tags::List.Count(); i++) + { + auto& subTagName = Tags::List[i]; + if (subTagName.Contains(_parentTagName) && subTagName != _parentTagName) + { + subTags.Add(Tags::Get(subTagName)); + } + } + + return subTags; +} + bool Tags::HasTag(const Array& list, const Tag& tag) { if (tag.Index == 0) diff --git a/Source/Engine/Level/Tags.h b/Source/Engine/Level/Tags.h index 03b09a1fc..04ba76a23 100644 --- a/Source/Engine/Level/Tags.h +++ b/Source/Engine/Level/Tags.h @@ -92,6 +92,13 @@ API_CLASS(Static) class FLAXENGINE_API Tags /// The tag. API_FUNCTION() static Tag Get(const StringView& tagName); + /// + /// Get all subtags of the specific Tag + /// + /// + /// + API_FUNCTION() static Array GetSubTags(Tag tag); + public: /// /// Checks if the list of tags contains a given tag (including parent tags check). For example, HasTag({"A.B"}, "A") returns true, for exact check use HasTagExact. From 85cfc73bbfdbc736769ef006f7168985b341efc6 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 22 Apr 2023 14:51:40 -0400 Subject: [PATCH 2/4] clean code --- Source/Engine/Level/Tags.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Engine/Level/Tags.cpp b/Source/Engine/Level/Tags.cpp index b16928630..dd4bc331a 100644 --- a/Source/Engine/Level/Tags.cpp +++ b/Source/Engine/Level/Tags.cpp @@ -57,8 +57,7 @@ Tag Tags::Get(const StringView& tagName) Array Tags::GetSubTags(Tag parentTag) { - Array subTags = Array(); - + Array subTags; auto _parentTagName = parentTag.ToString(); for (int i = 0; i < Tags::List.Count(); i++) From db14c8a0a6fba0605babcc080761b3d821b8ee0a Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 6 May 2023 10:46:26 -0400 Subject: [PATCH 3/4] refactor "GetSubTags" --- Source/Engine/Level/Tags.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Level/Tags.cpp b/Source/Engine/Level/Tags.cpp index dd4bc331a..efdd522e7 100644 --- a/Source/Engine/Level/Tags.cpp +++ b/Source/Engine/Level/Tags.cpp @@ -58,14 +58,15 @@ Tag Tags::Get(const StringView& tagName) Array Tags::GetSubTags(Tag parentTag) { Array subTags; - auto _parentTagName = parentTag.ToString(); + const String& parentTagName = parentTag.ToString(); for (int i = 0; i < Tags::List.Count(); i++) { - auto& subTagName = Tags::List[i]; - if (subTagName.Contains(_parentTagName) && subTagName != _parentTagName) + const Tag tag = Tag(i + 1); + const String& tagName = Tags::List[i]; + if (tagName.StartsWith(parentTagName) && parentTag.Index != tag) { - subTags.Add(Tags::Get(subTagName)); + subTags.Add(tag); } } From 64515404e97e70994e04c3f5d7a7d982f57d41b2 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 6 May 2023 10:49:07 -0400 Subject: [PATCH 4/4] refactor again --- Source/Engine/Level/Tags.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Level/Tags.cpp b/Source/Engine/Level/Tags.cpp index efdd522e7..63cfd8442 100644 --- a/Source/Engine/Level/Tags.cpp +++ b/Source/Engine/Level/Tags.cpp @@ -64,7 +64,7 @@ Array Tags::GetSubTags(Tag parentTag) { const Tag tag = Tag(i + 1); const String& tagName = Tags::List[i]; - if (tagName.StartsWith(parentTagName) && parentTag.Index != tag) + if (tagName.StartsWith(parentTagName) && parentTag.Index != tag.Index) { subTags.Add(tag); }