From 671e145a78bc8daea08d5d4df024f80411e6eeb6 Mon Sep 17 00:00:00 2001
From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Date: Sat, 16 Dec 2023 11:22:42 -0500
Subject: [PATCH] Add new HasAnyTag and HasAllTags overrides (#22577)
* Add new HasAnyTag and HasAllTags overrides
* Add missing overrides
---
Content.Shared/Tag/TagSystem.cs | 104 +++++++++++++++++++++++++++++++-
1 file changed, 103 insertions(+), 1 deletion(-)
diff --git a/Content.Shared/Tag/TagSystem.cs b/Content.Shared/Tag/TagSystem.cs
index 0f223afa4e..0628b892ed 100644
--- a/Content.Shared/Tag/TagSystem.cs
+++ b/Content.Shared/Tag/TagSystem.cs
@@ -188,6 +188,17 @@ public sealed class TagSystem : EntitySystem
HasTag(component, id);
}
+ ///
+ /// Checks if all of the given tags have been added to an entity.
+ ///
+ /// The entity to check.
+ /// The tags to check for.
+ /// true if they all exist, false otherwise.
+ ///
+ /// Thrown if one of the ids represents an unregistered .
+ ///
+ public bool HasAllTags(EntityUid entity, string id) => HasTag(entity, id);
+
///
/// Checks if all of the given tags have been added to an entity.
///
@@ -197,7 +208,7 @@ public sealed class TagSystem : EntitySystem
///
/// Thrown if one of the ids represents an unregistered .
///
- public bool HasAllTags(EntityUid entity, params string[] ids)
+ public bool HasAllTags(EntityUid entity, List ids)
{
return TryComp(entity, out var component) &&
HasAllTags(component, ids);
@@ -233,6 +244,32 @@ public sealed class TagSystem : EntitySystem
HasAnyTag(component, ids);
}
+ ///
+ /// Checks if all of the given tags have been added to an entity.
+ ///
+ /// The entity to check.
+ /// The tag to check for.
+ /// true if any of them exist, false otherwise.
+ ///
+ /// Thrown if one of the ids represents an unregistered .
+ ///
+ public bool HasAnyTag(EntityUid entity, string id) => HasTag(entity, id);
+
+ ///
+ /// Checks if all of the given tags have been added to an entity.
+ ///
+ /// The entity to check.
+ /// The tags to check for.
+ /// true if any of them exist, false otherwise.
+ ///
+ /// Thrown if one of the ids represents an unregistered .
+ ///
+ public bool HasAnyTag(EntityUid entity, List ids)
+ {
+ return TryComp(entity, out var component) &&
+ HasAnyTag(component, ids);
+ }
+
///
/// Checks if all of the given tags have been added to an entity.
///
@@ -388,6 +425,37 @@ public sealed class TagSystem : EntitySystem
return HasAllTags(component, ids.AsEnumerable());
}
+ ///
+ /// Checks if all of the given tags have been added.
+ ///
+ /// The tag to check for.
+ /// true if they all exist, false otherwise.
+ ///
+ /// Thrown if one of the ids represents an unregistered .
+ ///
+ public bool HasAllTags(TagComponent component, string id) => HasTag(component, id);
+
+ ///
+ /// Checks if all of the given tags have been added.
+ ///
+ /// The tags to check for.
+ /// true if they all exist, false otherwise.
+ ///
+ /// Thrown if one of the ids represents an unregistered .
+ ///
+ public bool HasAllTags(TagComponent component, List ids)
+ {
+ foreach (var id in ids)
+ {
+ AssertValidTag(id);
+
+ if (!component.Tags.Contains(id))
+ return false;
+ }
+
+ return true;
+ }
+
///
/// Checks if all of the given tags have been added.
///
@@ -423,6 +491,40 @@ public sealed class TagSystem : EntitySystem
return HasAnyTag(component, ids.AsEnumerable());
}
+
+ ///
+ /// Checks if any of the given tags have been added.
+ ///
+ /// The tag to check for.
+ /// true if any of them exist, false otherwise.
+ ///
+ /// Thrown if one of the ids represents an unregistered .
+ ///
+ public bool HasAnyTag(TagComponent component, string id) => HasTag(component, id);
+
+ ///
+ /// Checks if any of the given tags have been added.
+ ///
+ /// The tags to check for.
+ /// true if any of them exist, false otherwise.
+ ///
+ /// Thrown if one of the ids represents an unregistered .
+ ///
+ public bool HasAnyTag(TagComponent component, List ids)
+ {
+ foreach (var id in ids)
+ {
+ AssertValidTag(id);
+
+ if (component.Tags.Contains(id))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
///
/// Checks if any of the given tags have been added.
///