Files
tbd-station-14/Content.Client/Storage/Visualizers/MappedItemVisualizer.cs
Ygg01 3fd28c2565 Added mapped storage for things like crayon belts and tools (#4201)
* Added mapped storage for things like crayon belts and tools

* Attempt to get StorageFillEvent to work

* Managed to get it working with Visualizer logi

* Improved PR and did some light refactoring of components

* Update Content.Client/Storage/Visualizers/MappedItemVisualizer.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Removed event, went with stateful ApperanceData

* Removed ids in favor of whitelist

* Refactor YAML, Moved functionality to Shared and renamed it.

* Changed so insert/remove always send full state.

* Move logic to component

* Fix some issues on MappedVisualizer and few nitpicks

- Fix mapped visualizer only doing init or update layers
- Fixed naming of systems
- Fixed sort of crayons

* Forgot to apply Vera's suggestion

* Fix the data to be more strict and to avoid unnecessary clearing

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2021-07-22 02:56:55 -07:00

72 lines
2.3 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Content.Shared.Storage.ItemCounter;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
namespace Content.Client.Storage.Visualizers
{
[UsedImplicitly]
public class MappedItemVisualizer : AppearanceVisualizer
{
[DataField("sprite")] private ResourcePath? _rsiPath;
private List<string> _spriteLayers = new();
public override void InitializeEntity(IEntity entity)
{
base.InitializeEntity(entity);
if (entity.TryGetComponent<ISpriteComponent>(out var spriteComponent))
{
_rsiPath ??= spriteComponent.BaseRSI!.Path!;
}
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (component.Owner.TryGetComponent<ISpriteComponent>(out var spriteComponent))
{
if (_spriteLayers.Count == 0)
{
InitLayers(spriteComponent, component);
}
EnableLayers(spriteComponent, component);
}
}
private void InitLayers(ISpriteComponent spriteComponent, AppearanceComponent component)
{
if (!component.TryGetData<ShowLayerData>(StorageMapVisuals.InitLayers, out var wrapper))
return;
_spriteLayers.AddRange(wrapper.QueuedEntities);
foreach (var sprite in _spriteLayers)
{
spriteComponent.LayerMapReserveBlank(sprite);
spriteComponent.LayerSetSprite(sprite, new SpriteSpecifier.Rsi(_rsiPath!, sprite));
spriteComponent.LayerSetVisible(sprite, false);
}
}
private void EnableLayers(ISpriteComponent spriteComponent, AppearanceComponent component)
{
if (!component.TryGetData<ShowLayerData>(StorageMapVisuals.LayerChanged, out var wrapper))
return;
foreach (var layerName in _spriteLayers)
{
var show = wrapper.QueuedEntities.Contains(layerName);
spriteComponent.LayerSetVisible(layerName, show);
}
}
}
}