using System; using System.Collections.Generic; using System.Linq; using Robust.Shared.GameObjects; using Robust.Shared.Toolshed.TypeParsers; namespace Robust.Shared.Toolshed.Commands.Entities.Components; [ToolshedCommand] internal sealed class CompCommand : ToolshedCommand { private static Type[] _parsers = [typeof(ComponentTypeParser)]; public override Type[] TypeParameterParsers => _parsers; [CommandImplementation("get")] public IEnumerable CompEnumerable([PipedArgument] IEnumerable input) where T: IComponent { return input.Where(HasComp).Select(Comp); } [CommandImplementation("get")] public T? CompDirect([PipedArgument] EntityUid input) where T : IComponent { TryComp(input, out T? res); return res; } [CommandImplementation("add")] public EntityUid Add([PipedArgument] EntityUid input) where T: IComponent, new() { AddComp(input); return input; } [CommandImplementation("add")] public IEnumerable Add([PipedArgument] IEnumerable input) where T : IComponent, new() => input.Select(Add); [CommandImplementation("rm")] public EntityUid Rm([PipedArgument] EntityUid input) where T: IComponent, new() { RemComp(input); return input; } [CommandImplementation("rm")] public IEnumerable Rm([PipedArgument] IEnumerable input) where T : IComponent, new() => input.Select(Rm); [CommandImplementation("ensure")] public EntityUid Ensure([PipedArgument] EntityUid input) where T: IComponent, new() { EnsureComp(input); return input; } [CommandImplementation("ensure")] public IEnumerable Ensure([PipedArgument] IEnumerable input) where T : IComponent, new() => input.Select(Ensure); [CommandImplementation("has")] public bool Has([PipedArgument] EntityUid input) where T: IComponent { return HasComp(input); } [CommandImplementation("has")] public IEnumerable Has([PipedArgument] IEnumerable input) where T : IComponent => input.Select(Has); }