mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Helper to empty a container.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Robust.Shared.Containers
|
||||
@@ -104,6 +106,25 @@ namespace Robust.Shared.Containers
|
||||
return TryRemoveFromContainer(entity, force, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to remove all entities in a container.
|
||||
/// </summary>
|
||||
public static void EmptyContainer(this IContainer container, bool force = false, EntityCoordinates? moveTo = null)
|
||||
{
|
||||
foreach (var entity in container.ContainedEntities.ToArray())
|
||||
{
|
||||
if (entity.Deleted) continue;
|
||||
|
||||
if (force)
|
||||
container.ForceRemove(entity);
|
||||
else
|
||||
container.Remove(entity);
|
||||
|
||||
if (moveTo.HasValue)
|
||||
entity.Transform.Coordinates = moveTo.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AttachParentToContainerOrGrid(this ITransformComponent transform)
|
||||
{
|
||||
if (transform.Parent == null
|
||||
|
||||
Reference in New Issue
Block a user