using Content.Shared.Storage.Components; using JetBrains.Annotations; using Robust.Shared.Containers; namespace Content.Shared.Storage.EntitySystems { /// /// ItemMapperSystem is a system that on each initialization, insertion, removal of an entity from /// given (with appropriate storage attached) will check each stored item to see /// if its tags/component, and overall quantity match . /// [UsedImplicitly] public abstract class SharedItemMapperSystem : EntitySystem { /// public override void Initialize() { base.Initialize(); SubscribeLocalEvent(InitLayers); SubscribeLocalEvent(MapperEntityInserted); SubscribeLocalEvent(MapperEntityRemoved); } private void InitLayers(EntityUid uid, ItemMapperComponent component, ComponentInit args) { if (EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent)) { var list = new List(component.MapLayers.Keys); appearanceComponent.SetData(StorageMapVisuals.InitLayers, new ShowLayerData(list)); } } private void MapperEntityRemoved(EntityUid uid, ItemMapperComponent itemMapper, EntRemovedFromContainerMessage args) { if (EntityManager.TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent) && TryGetLayers(args, itemMapper, out var containedLayers)) { appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers)); } } private void MapperEntityInserted(EntityUid uid, ItemMapperComponent itemMapper, EntInsertedIntoContainerMessage args) { if (EntityManager.TryGetComponent(itemMapper.Owner, out AppearanceComponent? appearanceComponent) && TryGetLayers(args, itemMapper, out var containedLayers)) { appearanceComponent.SetData(StorageMapVisuals.LayerChanged, new ShowLayerData(containedLayers)); } } /// /// Method that iterates over storage of the entity in and sets according to /// definition. It will have O(n*m) time behavior (n - number of entities in container, and m - number of /// definitions in . /// /// event with EntityUid used to search the storage /// component that contains definition used to map whitelist in /// mapLayers to string. /// /// list of layers that should be visible /// false if msg.Container.Owner is not a storage, true otherwise. protected abstract bool TryGetLayers(ContainerModifiedMessage msg, ItemMapperComponent itemMapper, out IReadOnlyList containedLayers); } }