Files
ss14-wl/Content.Shared/Containers/ContainerCompSystem.cs
Pieter-Jan BriersandGitHub 5168b5f3d4 IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

44 lines
1.4 KiB
C#

using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared.Containers;
/// <summary>
/// Applies / removes an entity prototype from a child entity when it's inserted into a container.
/// </summary>
public sealed partial class ContainerCompSystem : EntitySystem
{
[Dependency] private IGameTiming _timing = default!;
[Dependency] private IPrototypeManager _proto = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ContainerCompComponent, EntInsertedIntoContainerMessage>(OnConInsert);
SubscribeLocalEvent<ContainerCompComponent, EntRemovedFromContainerMessage>(OnConRemove);
}
private void OnConRemove(Entity<ContainerCompComponent> ent, ref EntRemovedFromContainerMessage args)
{
if (args.Container.ID != ent.Comp.Container || _timing.ApplyingState)
return;
if (_proto.Resolve(ent.Comp.Proto, out var entProto))
{
EntityManager.RemoveComponents(args.Entity, entProto.Components);
}
}
private void OnConInsert(Entity<ContainerCompComponent> ent, ref EntInsertedIntoContainerMessage args)
{
if (args.Container.ID != ent.Comp.Container || _timing.ApplyingState)
return;
if (_proto.Resolve(ent.Comp.Proto, out var entProto))
{
EntityManager.AddComponents(args.Entity, entProto.Components);
}
}
}