* Revert "Fix chat bubbles (#25643)" This reverts commit23d2c4d924. * Revert "Fixes obsolete Transform warnings in Content. (#25256)" This reverts commitf284b43ff6.
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System.Numerics;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.Shared.Containers;
|
|
|
|
public sealed class ContainerFillSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<ContainerFillComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, ContainerFillComponent component, MapInitEvent args)
|
|
{
|
|
if (!TryComp(uid, out ContainerManagerComponent? containerComp))
|
|
return;
|
|
|
|
var xform = Transform(uid);
|
|
var coords = new EntityCoordinates(uid, Vector2.Zero);
|
|
|
|
foreach (var (contaienrId, prototypes) in component.Containers)
|
|
{
|
|
if (!_containerSystem.TryGetContainer(uid, contaienrId, out var container, containerComp))
|
|
{
|
|
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} is missing a container ({contaienrId}).");
|
|
continue;
|
|
}
|
|
|
|
foreach (var proto in prototypes)
|
|
{
|
|
var ent = Spawn(proto, coords);
|
|
if (!_containerSystem.Insert(ent, container, containerXform: xform))
|
|
{
|
|
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} failed to insert an entity: {ToPrettyString(ent)}.");
|
|
Transform(ent).AttachToGridOrMap();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|