Files
RobustToolbox/Robust.Shared/Toolshed/Commands/Entities/EntitiesCommand.cs
T
Leon FriedrichandGitHub 9af119f57a Toolshed Rejig (#5455)
* Toolshed Rejig

* shorten hint string

* Try fix conflicts. Ill make with work later

* bodge

* Fix ProtoIdTypeParser assert

* comment

* AllEntities

* Remove more linq from WhereCommand

* better help strings

* Add ContainsCommand

* loc strings

* Add contains command description

* Add $self variable

* Errors for writing to readonly variables

* A
2024-12-21 17:49:11 +11:00

37 lines
1008 B
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.GameObjects;
namespace Robust.Shared.Toolshed.Commands.Entities;
[ToolshedCommand]
internal sealed class EntitiesCommand : ToolshedCommand
{
[CommandImplementation]
public IEnumerable<EntityUid> Entities()
{
return new AllEntityEnumerator(EntityManager);
}
public sealed class AllEntityEnumerator(IEntityManager entMan) : IEnumerable<EntityUid>
{
public IEntityManager EntMan { get; } = entMan;
// We create an array as chained commands might modify it.
public EntityUid[]? _arr;
public IEnumerator<EntityUid> GetEnumerator()
{
_arr ??= EntMan.GetEntities().ToArray();
return ((IEnumerable<EntityUid>)_arr).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
_arr ??= EntMan.GetEntities().ToArray();
return _arr.GetEnumerator();
}
}
}