Convert ItemCabinet to use a VisualizerSystem (#6571)
This commit is contained in:
25
Content.Client/Cabinet/ItemCabinetSystem.cs
Normal file
25
Content.Client/Cabinet/ItemCabinetSystem.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Content.Shared.Cabinet;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Cabinet;
|
||||
|
||||
public sealed class ItemCabinetSystem : VisualizerSystem<ItemCabinetVisualsComponent>
|
||||
{
|
||||
protected override void OnAppearanceChange(EntityUid uid, ItemCabinetVisualsComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (TryComp(uid, out SpriteComponent? sprite)
|
||||
&& args.Component.TryGetData(ItemCabinetVisuals.IsOpen, out bool isOpen)
|
||||
&& args.Component.TryGetData(ItemCabinetVisuals.ContainsItem, out bool contains))
|
||||
{
|
||||
var state = isOpen ? component.OpenState : component.ClosedState;
|
||||
sprite.LayerSetState(ItemCabinetVisualLayers.Door, state);
|
||||
sprite.LayerSetVisible(ItemCabinetVisualLayers.ContainsItem, contains);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ItemCabinetVisualLayers
|
||||
{
|
||||
Door,
|
||||
ContainsItem
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using Content.Shared.Cabinet;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Client.Cabinet
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ItemCabinetVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("openState", required: true)]
|
||||
private string _openState = default!;
|
||||
|
||||
[DataField("closedState", required: true)]
|
||||
private string _closedState = default!;
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
if (entities.TryGetComponent(component.Owner, out SpriteComponent sprite)
|
||||
&& component.TryGetData(ItemCabinetVisuals.IsOpen, out bool isOpen)
|
||||
&& component.TryGetData(ItemCabinetVisuals.ContainsItem, out bool contains))
|
||||
{
|
||||
var state = isOpen ? _openState : _closedState;
|
||||
sprite.LayerSetState(ItemCabinetVisualLayers.Door, state);
|
||||
sprite.LayerSetVisible(ItemCabinetVisualLayers.ContainsItem, contains);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ItemCabinetVisualLayers : byte
|
||||
{
|
||||
Door,
|
||||
ContainsItem
|
||||
//Welded
|
||||
}
|
||||
}
|
||||
11
Content.Client/Cabinet/ItemCabinetVisualsComponent.cs
Normal file
11
Content.Client/Cabinet/ItemCabinetVisualsComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Content.Client.Cabinet;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class ItemCabinetVisualsComponent : Component
|
||||
{
|
||||
[DataField("openState", required: true)]
|
||||
public string OpenState = default!;
|
||||
|
||||
[DataField("closedState", required: true)]
|
||||
public string ClosedState = default!;
|
||||
}
|
||||
Reference in New Issue
Block a user