Storage Standardization [Take 2] (#21270)

This commit is contained in:
Nemanja
2023-10-30 23:55:55 -04:00
committed by GitHub
parent 2c5ea97d9a
commit 0c329ed661
240 changed files with 1365 additions and 1275 deletions

View File

@@ -1,7 +1,6 @@
using Content.Shared.Rounding;
using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
namespace Content.Server.Storage.EntitySystems;
@@ -13,12 +12,12 @@ public sealed class StorageFillVisualizerSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StorageFillVisualizerComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<StorageFillVisualizerComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<StorageFillVisualizerComponent, EntInsertedIntoContainerMessage>(OnInserted);
SubscribeLocalEvent<StorageFillVisualizerComponent, EntRemovedFromContainerMessage>(OnRemoved);
}
private void OnInit(EntityUid uid, StorageFillVisualizerComponent component, ComponentInit args)
private void OnStartup(EntityUid uid, StorageFillVisualizerComponent component, ComponentStartup args)
{
UpdateAppearance(uid, component: component);
}
@@ -42,7 +41,13 @@ public sealed class StorageFillVisualizerSystem : EntitySystem
if (component.MaxFillLevels < 1)
return;
var level = ContentHelpers.RoundToEqualLevels(storage.StorageUsed, storage.StorageCapacityMax, component.MaxFillLevels);
if (!_appearance.TryGetData<int>(uid, StorageVisuals.StorageUsed, out var used, appearance))
return;
if (!_appearance.TryGetData<int>(uid, StorageVisuals.Capacity, out var capacity, appearance))
return;
var level = ContentHelpers.RoundToEqualLevels(used, capacity, component.MaxFillLevels);
_appearance.SetData(uid, StorageFillVisuals.FillLevel, level, appearance);
}
}