Trash bag visualizer (#7199)

This commit is contained in:
Alex Evgrashin
2022-03-23 16:14:23 +03:00
committed by GitHub
parent 46ac70a734
commit 74d4adfb96
5 changed files with 115 additions and 18 deletions

View File

@@ -0,0 +1,42 @@
using Content.Server.Storage.Components;
using Content.Shared.Rounding;
using Content.Shared.Storage.Components;
using Robust.Shared.Containers;
namespace Content.Server.Storage.EntitySystems;
public sealed class StorageFillVisualizerSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StorageFillVisualizerComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<StorageFillVisualizerComponent, EntInsertedIntoContainerMessage>(OnInserted);
SubscribeLocalEvent<StorageFillVisualizerComponent, EntRemovedFromContainerMessage>(OnRemoved);
}
private void OnInit(EntityUid uid, StorageFillVisualizerComponent component, ComponentInit args)
{
UpdateAppearance(uid, component: component);
}
private void OnInserted(EntityUid uid, StorageFillVisualizerComponent component, EntInsertedIntoContainerMessage args)
{
UpdateAppearance(uid, component: component);
}
private void OnRemoved(EntityUid uid, StorageFillVisualizerComponent component, EntRemovedFromContainerMessage args)
{
UpdateAppearance(uid, component: component);
}
private void UpdateAppearance(EntityUid uid, ServerStorageComponent? storage = null, AppearanceComponent? appearance = null,
StorageFillVisualizerComponent? component = null)
{
if (!Resolve(uid, ref storage, ref appearance, ref component, false))
return;
var level = ContentHelpers.RoundToEqualLevels(storage.StorageUsed, storage.StorageCapacityMax, component.MaxFillLevels);
appearance.SetData(StorageFillVisuals.FillLevel, level);
}
}