Update trivial components to use auto comp states (#20539)

This commit is contained in:
DrSmugleaf
2023-09-28 16:20:29 -07:00
committed by GitHub
parent 14cfe44ece
commit a44fa86b68
158 changed files with 806 additions and 2866 deletions

View File

@@ -1,65 +1,43 @@
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Cabinet;
/// <summary>
/// Used for entities that can be opened, closed, and can hold one item. E.g., fire extinguisher cabinets.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class ItemCabinetComponent : Component
{
/// <summary>
/// Sound to be played when the cabinet door is opened.
/// </summary>
[DataField("doorSound"), ViewVariables(VVAccess.ReadWrite)]
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier? DoorSound;
/// <summary>
/// The <see cref="ItemSlot"/> that stores the actual item. The entity whitelist, sounds, and other
/// behaviours are specified by this <see cref="ItemSlot"/> definition.
/// </summary>
[DataField("cabinetSlot"), ViewVariables]
[DataField, ViewVariables]
public ItemSlot CabinetSlot = new();
/// <summary>
/// Whether the cabinet is currently open or not.
/// </summary>
[DataField("opened")]
[DataField, AutoNetworkedField]
public bool Opened;
/// <summary>
/// The state for when the cabinet is open
/// </summary>
[DataField("openState"), ViewVariables(VVAccess.ReadWrite)]
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public string? OpenState;
/// <summary>
/// The state for when the cabinet is closed
/// </summary>
[DataField("closedState"), ViewVariables(VVAccess.ReadWrite)]
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public string? ClosedState;
}
[Serializable, NetSerializable]
public sealed class ItemCabinetComponentState : ComponentState
{
public SoundSpecifier? DoorSound;
public bool Opened;
public string? OpenState;
public string? ClosedState;
public ItemCabinetComponentState(SoundSpecifier? doorSound, bool opened, string? openState, string? closedState)
{
DoorSound = doorSound;
Opened = opened;
OpenState = openState;
ClosedState = closedState;
}
}

View File

@@ -4,7 +4,6 @@ using Content.Shared.Lock;
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -19,9 +18,6 @@ public abstract class SharedItemCabinetSystem : EntitySystem
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ItemCabinetComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<ItemCabinetComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<ItemCabinetComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<ItemCabinetComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<ItemCabinetComponent, ComponentStartup>(OnComponentStartup);
@@ -35,24 +31,6 @@ public abstract class SharedItemCabinetSystem : EntitySystem
SubscribeLocalEvent<ItemCabinetComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
}
private void OnGetState(EntityUid uid, ItemCabinetComponent component, ref ComponentGetState args)
{
args.State = new ItemCabinetComponentState(component.DoorSound,
component.Opened,
component.OpenState,
component.ClosedState);
}
private void OnHandleState(EntityUid uid, ItemCabinetComponent component, ref ComponentHandleState args)
{
if (args.Current is not ItemCabinetComponentState state)
return;
component.DoorSound = state.DoorSound;
component.Opened = state.Opened;
component.OpenState = state.OpenState;
component.ClosedState = state.ClosedState;
}
private void OnComponentInit(EntityUid uid, ItemCabinetComponent cabinet, ComponentInit args)
{
_itemSlots.AddItemSlot(uid, "ItemCabinet", cabinet.CabinetSlot);