ItemMapper ECS (#9867)
This commit is contained in:
65
Content.Client/Storage/Systems/ItemMapperSystem.cs
Normal file
65
Content.Client/Storage/Systems/ItemMapperSystem.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Content.Shared.Storage.EntitySystems;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Storage.Systems;
|
||||
|
||||
public sealed class ItemMapperSystem : SharedItemMapperSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ItemMapperComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<ItemMapperComponent, AppearanceChangeEvent>(OnAppearance);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, ItemMapperComponent component, ComponentStartup args)
|
||||
{
|
||||
if (TryComp<SpriteComponent>(uid, out var sprite))
|
||||
{
|
||||
component.RSIPath ??= sprite.BaseRSI!.Path!;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAppearance(EntityUid uid, ItemMapperComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (TryComp<SpriteComponent>(component.Owner, out var spriteComponent))
|
||||
{
|
||||
if (component.SpriteLayers.Count == 0)
|
||||
{
|
||||
InitLayers(component, spriteComponent, args.Component);
|
||||
}
|
||||
|
||||
EnableLayers(component, spriteComponent, args.Component);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitLayers(ItemMapperComponent component, SpriteComponent spriteComponent, AppearanceComponent appearance)
|
||||
{
|
||||
if (!appearance.TryGetData<ShowLayerData>(StorageMapVisuals.InitLayers, out var wrapper))
|
||||
return;
|
||||
|
||||
component.SpriteLayers.AddRange(wrapper.QueuedEntities);
|
||||
|
||||
foreach (var sprite in component.SpriteLayers)
|
||||
{
|
||||
spriteComponent.LayerMapReserveBlank(sprite);
|
||||
spriteComponent.LayerSetSprite(sprite, new SpriteSpecifier.Rsi(component.RSIPath!, sprite));
|
||||
spriteComponent.LayerSetVisible(sprite, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnableLayers(ItemMapperComponent component, SpriteComponent spriteComponent, AppearanceComponent appearance)
|
||||
{
|
||||
if (!appearance.TryGetData<ShowLayerData>(StorageMapVisuals.LayerChanged, out var wrapper))
|
||||
return;
|
||||
|
||||
foreach (var layerName in component.SpriteLayers)
|
||||
{
|
||||
var show = wrapper.QueuedEntities.Contains(layerName);
|
||||
spriteComponent.LayerSetVisible(layerName, show);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Shared.Storage;
|
||||
using Content.Client.Animations;
|
||||
using Content.Client.Animations;
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Client.Storage;
|
||||
namespace Content.Client.Storage.Systems;
|
||||
|
||||
// TODO kill this is all horrid.
|
||||
public sealed class StorageSystem : EntitySystem
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Storage.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Storage.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class MappedItemVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("sprite")] private ResourcePath? _rsiPath;
|
||||
private List<string> _spriteLayers = new();
|
||||
|
||||
public override void InitializeEntity(EntityUid entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<ISpriteComponent?>(entity, out var spriteComponent))
|
||||
{
|
||||
_rsiPath ??= spriteComponent.BaseRSI!.Path!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
if (entities.TryGetComponent(component.Owner, out ISpriteComponent? 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user