2021-07-22 11:56:55 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2021-09-04 19:42:32 +02:00
|
|
|
|
using Content.Shared.Storage.Components;
|
2021-07-22 11:56:55 +02:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:05:23 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2021-07-22 11:56:55 +02:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
|
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.Storage.Visualizers
|
|
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class MappedItemVisualizer : AppearanceVisualizer
|
2021-07-22 11:56:55 +02:00
|
|
|
|
{
|
|
|
|
|
|
[DataField("sprite")] private ResourcePath? _rsiPath;
|
|
|
|
|
|
private List<string> _spriteLayers = new();
|
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
public override void InitializeEntity(EntityUid entity)
|
2021-07-22 11:56:55 +02:00
|
|
|
|
{
|
|
|
|
|
|
base.InitializeEntity(entity);
|
|
|
|
|
|
|
2021-12-03 15:53:09 +01:00
|
|
|
|
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ISpriteComponent?>(entity, out var spriteComponent))
|
2021-07-22 11:56:55 +02:00
|
|
|
|
{
|
|
|
|
|
|
_rsiPath ??= spriteComponent.BaseRSI!.Path!;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnChangeData(component);
|
2021-12-05 18:09:01 +01:00
|
|
|
|
|
|
|
|
|
|
var entities = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
if (entities.TryGetComponent(component.Owner, out ISpriteComponent spriteComponent))
|
2021-07-22 11:56:55 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (_spriteLayers.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitLayers(spriteComponent, component);
|
|
|
|
|
|
}
|
2021-09-04 19:42:32 +02:00
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
|
EnableLayers(spriteComponent, component);
|
2021-07-22 11:56:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|