Update trivial components to use auto comp states (#20539)
This commit is contained in:
@@ -4,18 +4,17 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Body.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(SharedBodySystem))]
|
||||
public sealed partial class BodyComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Relevant template to spawn for this body.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public ProtoId<BodyPrototype>? Prototype;
|
||||
|
||||
/// <summary>
|
||||
@@ -29,35 +28,17 @@ public sealed partial class BodyComponent : Component
|
||||
[ViewVariables]
|
||||
public string RootPartSlot => RootContainer.ID;
|
||||
|
||||
[DataField] public SoundSpecifier GibSound = new SoundCollectionSpecifier("gib");
|
||||
[DataField, AutoNetworkedField]
|
||||
public SoundSpecifier GibSound = new SoundCollectionSpecifier("gib");
|
||||
|
||||
/// <summary>
|
||||
/// The amount of legs required to move at full speed.
|
||||
/// If 0, then legs do not impact speed.
|
||||
/// </summary>
|
||||
[DataField] public int RequiredLegs;
|
||||
[DataField, AutoNetworkedField]
|
||||
public int RequiredLegs;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField]
|
||||
[DataField, AutoNetworkedField]
|
||||
public HashSet<EntityUid> LegEntities = new();
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BodyComponentState : ComponentState
|
||||
{
|
||||
public string? Prototype;
|
||||
public string? RootPartSlot;
|
||||
public SoundSpecifier GibSound;
|
||||
public int RequiredLegs;
|
||||
public HashSet<NetEntity> LegNetEntities;
|
||||
|
||||
public BodyComponentState(string? prototype, string? rootPartSlot, SoundSpecifier gibSound,
|
||||
int requiredLegs, HashSet<NetEntity> legNetEntities)
|
||||
{
|
||||
Prototype = prototype;
|
||||
RootPartSlot = rootPartSlot;
|
||||
GibSound = gibSound;
|
||||
RequiredLegs = requiredLegs;
|
||||
LegNetEntities = legNetEntities;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ using Content.Shared.Body.Part;
|
||||
using Content.Shared.Body.Prototypes;
|
||||
using Content.Shared.DragDrop;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using MapInitEvent = Robust.Shared.GameObjects.MapInitEvent;
|
||||
|
||||
namespace Content.Shared.Body.Systems;
|
||||
|
||||
@@ -30,8 +28,6 @@ public partial class SharedBodySystem
|
||||
SubscribeLocalEvent<BodyComponent, ComponentInit>(OnBodyInit);
|
||||
SubscribeLocalEvent<BodyComponent, MapInitEvent>(OnBodyMapInit);
|
||||
SubscribeLocalEvent<BodyComponent, CanDragEvent>(OnBodyCanDrag);
|
||||
SubscribeLocalEvent<BodyComponent, ComponentGetState>(OnBodyGetState);
|
||||
SubscribeLocalEvent<BodyComponent, ComponentHandleState>(OnBodyHandleState);
|
||||
}
|
||||
|
||||
private void OnBodyInserted(EntityUid uid, BodyComponent component, EntInsertedIntoContainerMessage args)
|
||||
@@ -82,28 +78,6 @@ public partial class SharedBodySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBodyHandleState(EntityUid uid, BodyComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not BodyComponentState state)
|
||||
return;
|
||||
|
||||
component.Prototype = state.Prototype != null ? state.Prototype : null!;
|
||||
component.GibSound = state.GibSound;
|
||||
component.RequiredLegs = state.RequiredLegs;
|
||||
component.LegEntities = EntityManager.EnsureEntitySet<BodyComponent>(state.LegNetEntities, uid);
|
||||
}
|
||||
|
||||
private void OnBodyGetState(EntityUid uid, BodyComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new BodyComponentState(
|
||||
component.Prototype,
|
||||
component.RootPartSlot,
|
||||
component.GibSound,
|
||||
component.RequiredLegs,
|
||||
EntityManager.GetNetEntitySet(component.LegEntities)
|
||||
);
|
||||
}
|
||||
|
||||
private void OnBodyInit(EntityUid bodyId, BodyComponent body, ComponentInit args)
|
||||
{
|
||||
// Setup the initial container.
|
||||
|
||||
Reference in New Issue
Block a user