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
This commit is contained in:
Ygg01
2021-09-04 19:42:32 +02:00
committed by GitHub
parent fc1ddb00cb
commit 53b53c3e0e
22 changed files with 370 additions and 326 deletions

View File

@@ -0,0 +1,54 @@
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);
}
}