using System.Collections.Generic; using Robust.Shared.GameObjects; using Robust.Shared.Prototypes; namespace Content.Shared.Tag { public static class TagComponentExtensions { /// /// Tries to add a tag to an entity if the tag doesn't already exist. /// /// The entity to add the tag to. /// The tag to add. /// /// true if it was added, false otherwise even if it already existed. /// /// /// Thrown if no exists with the given id. /// public static bool AddTag(this IEntity entity, string id) { return entity.EnsureComponent(out TagComponent tagComponent) && tagComponent.AddTag(id); } /// /// Tries to add the given tags to an entity if the tags don't already exist. /// /// The entity to add the tag to. /// The tags to add. /// /// true if any tags were added, false otherwise even if they all already existed. /// /// /// Thrown if one of the ids represents an unregistered . /// public static bool AddTags(this IEntity entity, params string[] ids) { return entity.EnsureComponent(out TagComponent tagComponent) && tagComponent.AddTags(ids); } /// /// Tries to add the given tags to an entity if the tags don't already exist. /// /// The entity to add the tag to. /// The tags to add. /// /// true if any tags were added, false otherwise even if they all already existed. /// /// /// Thrown if one of the ids represents an unregistered . /// public static bool AddTags(this IEntity entity, IEnumerable ids) { return entity.EnsureComponent(out TagComponent tagComponent) && tagComponent.AddTags(ids); } /// /// Tries to add a tag to an entity if it has a /// and the tag doesn't already exist. /// /// The entity to add the tag to. /// The tag to add. /// /// true if it was added, false otherwise even if it already existed. /// /// /// Thrown if no exists with the given id. /// public static bool TryAddTag(this IEntity entity, string id) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.AddTag(id); } /// /// Tries to add the given tags to an entity if it has a /// and the tags don't already exist. /// /// The entity to add the tag to. /// The tags to add. /// /// true if any tags were added, false otherwise even if they all already existed. /// /// /// Thrown if one of the ids represents an unregistered . /// public static bool TryAddTags(this IEntity entity, params string[] ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.AddTags(ids); } /// /// Tries to add the given tags to an entity if it has a /// and the tags don't already exist. /// /// The entity to add the tag to. /// The tags to add. /// /// true if any tags were added, false otherwise even if they all already existed. /// /// /// Thrown if one of the ids represents an unregistered . /// public static bool TryAddTags(this IEntity entity, IEnumerable ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.AddTags(ids); } /// /// Checks if a tag has been added to an entity. /// /// The entity to check. /// The tag to check for. /// true if it exists, false otherwise. /// /// Thrown if no exists with the given id. /// public static bool HasTag(this IEntity entity, string id) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.HasTag(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 static bool HasAllTags(this IEntity entity, params string[] ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.HasAllTags(ids); } /// /// 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 static bool HasAllTags(this IEntity entity, IEnumerable ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.HasAllTags(ids); } /// /// 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 static bool HasAnyTag(this IEntity entity, params string[] ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.HasAnyTag(ids); } /// /// 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 static bool HasAnyTag(this IEntity entity, IEnumerable ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.HasAnyTag(ids); } /// /// Tries to remove a tag from an entity if it exists. /// /// The entity to remove the tag from. /// The tag to remove. /// /// true if it was removed, false otherwise even if it didn't exist. /// /// /// Thrown if no exists with the given id. /// public static bool RemoveTag(this IEntity entity, string id) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.RemoveTag(id); } /// /// Tries to remove a tag from an entity if it exists. /// /// The entity to remove the tag from. /// The tag to remove. /// /// true if it was removed, false otherwise even if it didn't exist. /// /// Thrown if one of the ids represents an unregistered . /// /// public static bool RemoveTags(this IEntity entity, params string[] ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.RemoveTags(ids); } /// /// Tries to remove a tag from an entity if it exists. /// /// The entity to remove the tag from. /// The tag to remove. /// /// true if it was removed, false otherwise even if it didn't exist. /// /// /// Thrown if one of the ids represents an unregistered . /// public static bool RemoveTags(this IEntity entity, IEnumerable ids) { return entity.TryGetComponent(out TagComponent? tagComponent) && tagComponent.RemoveTags(ids); } } }