Add new HasAnyTag and HasAllTags overrides (#22577)

* Add new HasAnyTag and HasAllTags overrides

* Add missing overrides
This commit is contained in:
Leon Friedrich
2023-12-16 11:22:42 -05:00
committed by GitHub
parent 9a3342d972
commit 671e145a78

View 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>