Resolves StorageVisualizer is Obsolete (#13910)
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Storage.Visualizers;
|
||||
|
||||
public sealed class EntityStorageVisualizerSystem : VisualizerSystem<EntityStorageVisualsComponent>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EntityStorageVisualsComponent, ComponentInit>(OnComponentInit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the base sprite to this layer. Exists to make the inheritance tree less boilerplate-y.
|
||||
/// </summary>
|
||||
private void OnComponentInit(EntityUid uid, EntityStorageVisualsComponent comp, ComponentInit args)
|
||||
{
|
||||
if (comp.StateBaseClosed == null)
|
||||
return;
|
||||
|
||||
comp.StateBaseOpen ??= comp.StateBaseClosed;
|
||||
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
||||
return;
|
||||
|
||||
sprite.LayerSetState(StorageVisualLayers.Base, comp.StateBaseClosed);
|
||||
}
|
||||
|
||||
protected override void OnAppearanceChange(EntityUid uid, EntityStorageVisualsComponent comp, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null
|
||||
|| !AppearanceSystem.TryGetData<bool>(uid, StorageVisuals.Open, out var open, args.Component))
|
||||
return;
|
||||
|
||||
// Open/Closed state for the storage entity.
|
||||
if (args.Sprite.LayerMapTryGet(StorageVisualLayers.Door, out _))
|
||||
{
|
||||
if (open)
|
||||
{
|
||||
args.Sprite.LayerSetVisible(StorageVisualLayers.Door, true);
|
||||
if (comp.StateDoorOpen != null)
|
||||
args.Sprite.LayerSetState(StorageVisualLayers.Door, comp.StateDoorOpen);
|
||||
|
||||
if (comp.StateBaseOpen != null)
|
||||
args.Sprite.LayerSetState(StorageVisualLayers.Base, comp.StateBaseOpen);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (comp.StateDoorClosed != null)
|
||||
{
|
||||
args.Sprite.LayerSetState(StorageVisualLayers.Door, comp.StateDoorClosed);
|
||||
args.Sprite.LayerSetVisible(StorageVisualLayers.Door, true);
|
||||
}
|
||||
else
|
||||
args.Sprite.LayerSetVisible(StorageVisualLayers.Door, false);
|
||||
|
||||
if (comp.StateBaseClosed != null)
|
||||
args.Sprite.LayerSetState(StorageVisualLayers.Base, comp.StateBaseClosed);
|
||||
}
|
||||
}
|
||||
|
||||
// Lock state for the storage entity. TODO: Split into its own visualizer.
|
||||
if (AppearanceSystem.TryGetData<bool>(uid, StorageVisuals.CanLock, out var canLock, args.Component) && canLock)
|
||||
{
|
||||
if (!AppearanceSystem.TryGetData<bool>(uid, StorageVisuals.Locked, out var locked, args.Component))
|
||||
locked = true;
|
||||
|
||||
args.Sprite.LayerSetVisible(StorageVisualLayers.Lock, !open);
|
||||
if (!open)
|
||||
{
|
||||
args.Sprite.LayerSetState(StorageVisualLayers.Lock, locked ? comp.StateLocked : comp.StateUnlocked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum StorageVisualLayers : byte
|
||||
{
|
||||
Base,
|
||||
Door,
|
||||
Lock
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace Content.Client.Storage.Visualizers;
|
||||
|
||||
[RegisterComponent]
|
||||
[Access(typeof(EntityStorageVisualizerSystem))]
|
||||
public sealed class EntityStorageVisualsComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The RSI state used for the base layer of the storage entity sprite while the storage is closed.
|
||||
/// </summary>
|
||||
[DataField("stateBaseClosed")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? StateBaseClosed;
|
||||
|
||||
/// <summary>
|
||||
/// The RSI state used for the base layer of the storage entity sprite while the storage is open.
|
||||
/// </summary>
|
||||
[DataField("stateBaseOpen")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? StateBaseOpen;
|
||||
|
||||
/// <summary>
|
||||
/// The RSI state used for the door/lid while the storage is open.
|
||||
/// </summary>
|
||||
[DataField("stateDoorOpen")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? StateDoorOpen;
|
||||
|
||||
/// <summary>
|
||||
/// The RSI state used for the door/lid while the storage is closed.
|
||||
/// </summary>
|
||||
[DataField("stateDoorClosed")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? StateDoorClosed;
|
||||
|
||||
/// <summary>
|
||||
/// The RSI state used for the lock indicator while the storage is locked.
|
||||
/// </summary>
|
||||
[DataField("stateLocked")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? StateLocked = "locked";
|
||||
|
||||
/// <summary>
|
||||
/// The RSI state used for the lock indicator while the storage is unlocked.
|
||||
/// </summary>
|
||||
[DataField("stateUnlocked")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? StateUnlocked = "unlocked";
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
using Content.Shared.Storage;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Storage.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class StorageVisualizer : AppearanceVisualizer
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the base sprite to this layer. Exists to make the inheritance tree less boilerplate-y.
|
||||
/// </summary>
|
||||
[DataField("state")]
|
||||
private string? _stateBase;
|
||||
[DataField("state_alt")]
|
||||
private string? _stateBaseAlt;
|
||||
[DataField("state_open")]
|
||||
private string? _stateOpen;
|
||||
[DataField("state_closed")]
|
||||
private string? _stateClosed;
|
||||
|
||||
[Obsolete("Subscribe to your component being initialised instead.")]
|
||||
public override void InitializeEntity(EntityUid entity)
|
||||
{
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out SpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_stateBase != null)
|
||||
{
|
||||
sprite.LayerSetState(0, _stateBase);
|
||||
}
|
||||
|
||||
if (_stateBaseAlt == null)
|
||||
{
|
||||
_stateBaseAlt = _stateBase;
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
if (!entities.TryGetComponent(component.Owner, out SpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.TryGetData(StorageVisuals.Open, out bool open);
|
||||
|
||||
if (sprite.LayerMapTryGet(StorageVisualLayers.Door, out _))
|
||||
{
|
||||
sprite.LayerSetVisible(StorageVisualLayers.Door, true);
|
||||
|
||||
if (open)
|
||||
{
|
||||
if (_stateOpen != null)
|
||||
{
|
||||
sprite.LayerSetState(StorageVisualLayers.Door, _stateOpen);
|
||||
sprite.LayerSetVisible(StorageVisualLayers.Door, true);
|
||||
}
|
||||
|
||||
if (_stateBaseAlt != null)
|
||||
sprite.LayerSetState(0, _stateBaseAlt);
|
||||
}
|
||||
else if (!open)
|
||||
{
|
||||
if (_stateClosed != null)
|
||||
sprite.LayerSetState(StorageVisualLayers.Door, _stateClosed);
|
||||
else
|
||||
{
|
||||
sprite.LayerSetVisible(StorageVisualLayers.Door, false);
|
||||
}
|
||||
|
||||
if (_stateBase != null)
|
||||
sprite.LayerSetState(0, _stateBase);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.LayerSetVisible(StorageVisualLayers.Door, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (component.TryGetData(StorageVisuals.CanLock, out bool canLock) && canLock)
|
||||
{
|
||||
if (!component.TryGetData(StorageVisuals.Locked, out bool locked))
|
||||
{
|
||||
locked = true;
|
||||
}
|
||||
|
||||
sprite.LayerSetVisible(StorageVisualLayers.Lock, !open);
|
||||
if (!open)
|
||||
{
|
||||
sprite.LayerSetState(StorageVisualLayers.Lock, locked ? "locked" : "unlocked");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum StorageVisualLayers : byte
|
||||
{
|
||||
Door,
|
||||
Lock
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user