Update trivial components to use auto comp states (#20539)
This commit is contained in:
@@ -3,8 +3,6 @@ using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Shared.Storage.Components;
|
||||
|
||||
@@ -12,7 +10,8 @@ namespace Content.Shared.Storage.Components;
|
||||
/// This is used for things like paper bins, in which
|
||||
/// you can only take off of the top of the bin.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(BinSystem))]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(BinSystem))]
|
||||
public sealed partial class BinComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
@@ -30,42 +29,25 @@ public sealed partial class BinComponent : Component
|
||||
/// i can handle entities being deleted and removed
|
||||
/// out of order by other systems
|
||||
/// </remarks>
|
||||
[DataField("items")]
|
||||
[DataField, AutoNetworkedField]
|
||||
public List<EntityUid> Items = new();
|
||||
|
||||
/// <summary>
|
||||
/// The items that start in the bin. Sorted in order.
|
||||
/// </summary>
|
||||
[DataField("initialContents", customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
|
||||
public List<string> InitialContents = new();
|
||||
[DataField]
|
||||
public List<EntProtoId> InitialContents = new();
|
||||
|
||||
/// <summary>
|
||||
/// A whitelist governing what items can be inserted into the bin.
|
||||
/// </summary>
|
||||
[DataField("whitelist")]
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityWhitelist? Whitelist;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum amount of items
|
||||
/// that can be stored in the bin.
|
||||
/// </summary>
|
||||
[DataField("maxItems")]
|
||||
[DataField, AutoNetworkedField]
|
||||
public int MaxItems = 20;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BinComponentState : ComponentState
|
||||
{
|
||||
public List<NetEntity> Items;
|
||||
|
||||
public EntityWhitelist? Whitelist;
|
||||
|
||||
public int MaxItems;
|
||||
|
||||
public BinComponentState(List<NetEntity> items, EntityWhitelist? whitelist, int maxItems)
|
||||
{
|
||||
Items = items;
|
||||
Whitelist = whitelist;
|
||||
MaxItems = maxItems;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -27,8 +26,6 @@ public sealed class BinSystem : EntitySystem
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<BinComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<BinComponent, ComponentHandleState>(OnHandleState);
|
||||
SubscribeLocalEvent<BinComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<BinComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<BinComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
@@ -36,21 +33,6 @@ public sealed class BinSystem : EntitySystem
|
||||
SubscribeLocalEvent<BinComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, BinComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new BinComponentState(GetNetEntityList(component.Items), component.Whitelist, component.MaxItems);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, BinComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not BinComponentState state)
|
||||
return;
|
||||
|
||||
component.Items = EnsureEntityList<BinComponent>(state.Items, uid);
|
||||
component.Whitelist = state.Whitelist;
|
||||
component.MaxItems = state.MaxItems;
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, BinComponent component, ComponentStartup args)
|
||||
{
|
||||
component.ItemContainer = _container.EnsureContainer<Container>(uid, BinContainerId);
|
||||
|
||||
Reference in New Issue
Block a user