Convert ItemCabinet to use a VisualizerSystem (#6571)

This commit is contained in:
mirrorcult
2022-02-09 18:53:44 -07:00
committed by GitHub
parent 47c31fac47
commit b96cee4fd5
8 changed files with 46 additions and 55 deletions

View 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
}

View File

@@ -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
}
}

View 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!;
}

View File

@@ -62,7 +62,7 @@ public sealed partial class TriggerSystem
EntityManager.EnsureComponent<AnimationPlayerComponent>(uid); EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
} }
private void OnProxAppChange(EntityUid uid, TriggerOnProximityComponent component, AppearanceChangeEvent args) private void OnProxAppChange(EntityUid uid, TriggerOnProximityComponent component, ref AppearanceChangeEvent args)
{ {
OnChangeData(uid, component, args.Component); OnChangeData(uid, component, args.Component);
} }

View File

@@ -1,8 +1,5 @@
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Sound; using Content.Shared.Sound;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Cabinet namespace Content.Server.Cabinet
{ {
@@ -10,7 +7,7 @@ namespace Content.Server.Cabinet
/// Used for entities that can be opened, closed, and can hold one item. E.g., fire extinguisher cabinets. /// Used for entities that can be opened, closed, and can hold one item. E.g., fire extinguisher cabinets.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public class ItemCabinetComponent : Component public sealed class ItemCabinetComponent : Component
{ {
/// <summary> /// <summary>
/// Sound to be played when the cabinet door is opened. /// Sound to be played when the cabinet door is opened.

View File

@@ -15,7 +15,8 @@ namespace Content.Server.Entry
"Clickable", "Clickable",
"Icon", "Icon",
"ClientEntitySpawner", "ClientEntitySpawner",
"CharacterInfo" "CharacterInfo",
"ItemCabinetVisuals"
}; };
} }
} }

View File

@@ -26,8 +26,7 @@
doorSound: doorSound:
path: /Audio/Machines/machine_switch.ogg path: /Audio/Machines/machine_switch.ogg
- type: Appearance - type: Appearance
visuals: - type: ItemCabinetVisuals
- type: ItemCabinetVisualizer
openState: open openState: open
closedState: closed closedState: closed
placement: placement:

View File

@@ -24,10 +24,9 @@
doorSound: doorSound:
path: /Audio/Machines/machine_switch.ogg path: /Audio/Machines/machine_switch.ogg
- type: Appearance - type: Appearance
visuals: - type: ItemCabinetVisuals
- type: ItemCabinetVisualizer
closedState: glass
openState: glass-up openState: glass-up
closedState: glass
placement: placement:
mode: SnapgridCenter mode: SnapgridCenter