Candy Bucket for Halloween (#21257)
* Added candy bucket and component to update appearance of held containers akin to it * cleanup newline * newline was load-bearing * moved component to Shared, cleanup * newline is spooky * You build and run without errors, stop pretending otherwise * Updated for new storage system in master branch
This commit is contained in:
43
Content.Shared/ContainerHeld/ContainerHeldSystem.cs
Normal file
43
Content.Shared/ContainerHeld/ContainerHeldSystem.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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 class ContainerHeldSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedItemSystem _item = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly 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 (!(TryComp<StorageComponent>(uid, out var storage)
|
||||
&& TryComp<AppearanceComponent>(uid, out var appearance)
|
||||
&& TryComp<ItemComponent>(uid, out var item)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_storage.GetCumulativeItemSizes(uid, storage) >= comp.Threshold)
|
||||
{
|
||||
_item.SetHeldPrefix(uid, "full", item);
|
||||
_appearance.SetData(uid, ToggleVisuals.Toggled, true, appearance);
|
||||
}
|
||||
else
|
||||
{
|
||||
_item.SetHeldPrefix(uid, "empty", item);
|
||||
_appearance.SetData(uid, ToggleVisuals.Toggled, false, appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user