Files
tbd-station-14/Content.Server/Storage/EntitySystems/StorageFillVisualizerSystem.cs
Kara 2d5ec7f85c Id[entity] 2.0 (real) (#9612)
* starter API

* network ID cards

* Port more stuff from old identity

* Re-implement identity representation + name updating

* move

* proper name returning for `IdentityName`

* move everything important to server, give in to  temptation

* shared / server / client split sadly. move ensure to shared and spawn to server

* identity update queueing + identityblocker

* fixes

* and just like that it's usable for admins

* huge identity pass

* pass dos

* jesus christ

* figs :D

* fuck u

* fix bad merge.

Co-authored-by: Moony <moonheart08@users.noreply.github.com>
2022-07-10 20:36:53 -05:00

46 lines
1.7 KiB
C#

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;
if (component.MaxFillLevels < 1)
return;
var level = ContentHelpers.RoundToEqualLevels(storage.StorageUsed, storage.StorageCapacityMax, component.MaxFillLevels);
appearance.SetData(StorageFillVisuals.FillLevel, level);
}
}