Files
tbd-station-14/Content.Shared/Storage/EntitySystems/SharedItemMapperSystem.cs
Ygg01 53b53c3e0e Cigarette ecs (#4495)
* Reorganized Shared.Storage folder

* Replace StorageCounter with Item Counter

* Change stack visuals setting data

* Fix mirrorcult suggestions

* Fix items from upstream

* Fix type formatting
2021-09-04 10:42:32 -07:00

54 lines
2.2 KiB
C#

using System.Collections.Generic;
using Content.Shared.Storage.Components;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
namespace Content.Shared.Storage.EntitySystems
{
[UsedImplicitly]
public abstract class SharedItemMapperSystem : EntitySystem
{
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ItemMapperComponent, ComponentInit>(InitLayers);
SubscribeLocalEvent<ItemMapperComponent, EntInsertedIntoContainerMessage>(MapperEntityInserted);
SubscribeLocalEvent<ItemMapperComponent, EntRemovedFromContainerMessage>(MapperEntityRemoved);
}
private void InitLayers(EntityUid uid, ItemMapperComponent component, ComponentInit args)
{
if (component.Owner.TryGetComponent(out SharedAppearanceComponent? appearanceComponent))
{
var list = new List<string>(component.MapLayers.Keys);
appearanceComponent.SetData(StorageMapVisuals.InitLayers, new ShowLayerData(list));
}
}
private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper,
EntRemovedFromContainerMessage args)
{
if (itemMapper.Owner.TryGetComponent(out SharedAppearanceComponent? appearanceComponent)
&& TryGetLayers(args, itemMapper, out var containedLayers))
{
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
}
}
private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper,
EntInsertedIntoContainerMessage args)
{
if (itemMapper.Owner.TryGetComponent(out SharedAppearanceComponent? appearanceComponent)
&& TryGetLayers(args, itemMapper, out var containedLayers))
{
appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers));
}
}
protected abstract bool TryGetLayers(ContainerModifiedMessage msg,
ItemMapperComponent itemMapper,
out IReadOnlyList<string> containedLayers);
}
}