2021-07-30 19:22:06 +02:00
|
|
|
using Content.Shared.Storage;
|
2020-12-08 11:56:10 +01:00
|
|
|
using JetBrains.Annotations;
|
2019-05-05 18:52:06 +02:00
|
|
|
using Robust.Client.GameObjects;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-05-05 18:52:06 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Storage.Visualizers
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
2020-12-08 11:56:10 +01:00
|
|
|
[UsedImplicitly]
|
2020-07-23 00:56:53 +02:00
|
|
|
public sealed class StorageVisualizer : AppearanceVisualizer
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("state")]
|
2021-03-10 14:48:29 +01:00
|
|
|
private string? _stateBase;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("state_open")]
|
2021-03-10 14:48:29 +01:00
|
|
|
private string? _stateOpen;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("state_closed")]
|
2021-03-10 14:48:29 +01:00
|
|
|
private string? _stateClosed;
|
2019-05-05 18:52:06 +02:00
|
|
|
|
2020-05-22 15:44:49 +02:00
|
|
|
public override void InitializeEntity(IEntity entity)
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
if (!entity.TryGetComponent(out ISpriteComponent? sprite))
|
2020-05-22 15:44:49 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_stateBase != null)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(0, _stateBase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-05 18:52:06 +02:00
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
{
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
component.TryGetData(StorageVisuals.Open, out bool open);
|
2020-11-14 01:08:00 +11:00
|
|
|
var state = open ? _stateOpen ?? $"{_stateBase}_open" : _stateClosed ?? $"{_stateBase}_door";
|
|
|
|
|
|
|
|
|
|
sprite.LayerSetState(StorageVisualLayers.Door, state);
|
2020-05-25 13:58:56 +02:00
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
if (component.TryGetData(StorageVisuals.CanWeld, out bool canWeld) && canWeld)
|
2020-05-25 13:58:56 +02:00
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
if (component.TryGetData(StorageVisuals.Welded, out bool weldedVal))
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetVisible(StorageVisualLayers.Welded, weldedVal);
|
|
|
|
|
}
|
2020-05-25 13:58:56 +02:00
|
|
|
}
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 11:57:33 +01:00
|
|
|
public enum StorageVisualLayers : byte
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
2020-05-25 13:58:56 +02:00
|
|
|
Door,
|
|
|
|
|
Welded,
|
|
|
|
|
Lock
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
|
|
|
|
}
|