Files
ss14-wl/Content.Shared/ContainerHeld/ContainerHeldSystem.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.5 KiB
C#

using Robust.Shared.Containers;
using Content.Shared.Item;
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Content.Shared.Toggleable;
namespace Content.Shared.ContainerHeld;
public sealed partial class ContainerHeldSystem : EntitySystem
{
[Dependency] private SharedItemSystem _item = default!;
[Dependency] private SharedAppearanceSystem _appearance = default!;
[Dependency] private SharedStorageSystem _storage = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ContainerHeldComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
SubscribeLocalEvent<ContainerHeldComponent, EntRemovedFromContainerMessage>(OnContainerModified);
}
private void OnContainerModified(EntityUid uid, ContainerHeldComponent comp, ContainerModifiedMessage args)
{
if (!(HasComp<StorageComponent>(uid)
&& TryComp<AppearanceComponent>(uid, out var appearance)
&& TryComp<ItemComponent>(uid, out var item)))
{
return;
}
if (_storage.GetCumulativeItemAreas(uid) >= comp.Threshold)
{
_item.SetHeldPrefix(uid, "full", component: item);
_appearance.SetData(uid, ToggleableVisuals.Enabled, true, appearance);
}
else
{
_item.SetHeldPrefix(uid, "empty", component: item);
_appearance.SetData(uid, ToggleableVisuals.Enabled, false, appearance);
}
}
}