]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add new HasAnyTag and HasAllTags overrides (#22577)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Sat, 16 Dec 2023 16:22:42 +0000 (11:22 -0500)
committerGitHub <noreply@github.com>
Sat, 16 Dec 2023 16:22:42 +0000 (03:22 +1100)
* Add new HasAnyTag and HasAllTags overrides

* Add missing overrides

Content.Shared/Tag/TagSystem.cs

index 0f223afa4ed22195c2072e2178e992381b40eede..0628b892edd1e20e391a8fa0f4b23dacbc6cc289 100644 (file)
@@ -188,6 +188,17 @@ public sealed class TagSystem : EntitySystem
                HasTag(component, id);
     }
 
+    /// <summary>
+    ///     Checks if all of the given tags have been added to an entity.
+    /// </summary>
+    /// <param name="entity">The entity to check.</param>
+    /// <param name="id">The tags to check for.</param>
+    /// <returns>true if they all exist, false otherwise.</returns>
+    /// <exception cref="UnknownPrototypeException">
+    ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
+    /// </exception>
+    public bool HasAllTags(EntityUid entity, string id) => HasTag(entity, id);
+
     /// <summary>
     ///     Checks if all of the given tags have been added to an entity.
     /// </summary>
@@ -197,7 +208,7 @@ public sealed class TagSystem : EntitySystem
     /// <exception cref="UnknownPrototypeException">
     ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
     /// </exception>
-    public bool HasAllTags(EntityUid entity, params string[] ids)
+    public bool HasAllTags(EntityUid entity, List<string> ids)
     {
         return TryComp<TagComponent>(entity, out var component) &&
                HasAllTags(component, ids);
@@ -233,6 +244,32 @@ public sealed class TagSystem : EntitySystem
                HasAnyTag(component, ids);
     }
 
+    /// <summary>
+    ///     Checks if all of the given tags have been added to an entity.
+    /// </summary>
+    /// <param name="entity">The entity to check.</param>
+    /// <param name="id">The tag to check for.</param>
+    /// <returns>true if any of them exist, false otherwise.</returns>
+    /// <exception cref="UnknownPrototypeException">
+    ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
+    /// </exception>
+    public bool HasAnyTag(EntityUid entity, string id) => HasTag(entity, id);
+
+    /// <summary>
+    ///     Checks if all of the given tags have been added to an entity.
+    /// </summary>
+    /// <param name="entity">The entity to check.</param>
+    /// <param name="ids">The tags to check for.</param>
+    /// <returns>true if any of them exist, false otherwise.</returns>
+    /// <exception cref="UnknownPrototypeException">
+    ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
+    /// </exception>
+    public bool HasAnyTag(EntityUid entity, List<string> ids)
+    {
+        return TryComp<TagComponent>(entity, out var component) &&
+               HasAnyTag(component, ids);
+    }
+
     /// <summary>
     ///     Checks if all of the given tags have been added to an entity.
     /// </summary>
@@ -388,6 +425,37 @@ public sealed class TagSystem : EntitySystem
         return HasAllTags(component, ids.AsEnumerable());
     }
 
+    /// <summary>
+    ///     Checks if all of the given tags have been added.
+    /// </summary>
+    /// <param name="id">The tag to check for.</param>
+    /// <returns>true if they all exist, false otherwise.</returns>
+    /// <exception cref="UnknownPrototypeException">
+    ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
+    /// </exception>
+    public bool HasAllTags(TagComponent component, string id) => HasTag(component, id);
+
+    /// <summary>
+    ///     Checks if all of the given tags have been added.
+    /// </summary>
+    /// <param name="ids">The tags to check for.</param>
+    /// <returns>true if they all exist, false otherwise.</returns>
+    /// <exception cref="UnknownPrototypeException">
+    ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
+    /// </exception>
+    public bool HasAllTags(TagComponent component, List<string> ids)
+    {
+        foreach (var id in ids)
+        {
+            AssertValidTag(id);
+
+            if (!component.Tags.Contains(id))
+                return false;
+        }
+
+        return true;
+    }
+
     /// <summary>
     ///     Checks if all of the given tags have been added.
     /// </summary>
@@ -423,6 +491,40 @@ public sealed class TagSystem : EntitySystem
         return HasAnyTag(component, ids.AsEnumerable());
     }
 
+
+    /// <summary>
+    ///     Checks if any of the given tags have been added.
+    /// </summary>
+    /// <param name="id">The tag to check for.</param>
+    /// <returns>true if any of them exist, false otherwise.</returns>
+    /// <exception cref="UnknownPrototypeException">
+    ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
+    /// </exception>
+    public bool HasAnyTag(TagComponent component, string id) => HasTag(component, id);
+
+    /// <summary>
+    ///     Checks if any of the given tags have been added.
+    /// </summary>
+    /// <param name="ids">The tags to check for.</param>
+    /// <returns>true if any of them exist, false otherwise.</returns>
+    /// <exception cref="UnknownPrototypeException">
+    ///     Thrown if one of the ids represents an unregistered <see cref="TagPrototype"/>.
+    /// </exception>
+    public bool HasAnyTag(TagComponent component, List<string> ids)
+    {
+        foreach (var id in ids)
+        {
+            AssertValidTag(id);
+
+            if (component.Tags.Contains(id))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /// <summary>
     ///     Checks if any of the given tags have been added.
     /// </summary>