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!;
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ namespace Content.Server.Entry
|
|||||||
"Clickable",
|
"Clickable",
|
||||||
"Icon",
|
"Icon",
|
||||||
"ClientEntitySpawner",
|
"ClientEntitySpawner",
|
||||||
"CharacterInfo"
|
"CharacterInfo",
|
||||||
|
"ItemCabinetVisuals"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user