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

@@ -8,31 +8,21 @@ namespace Content.Shared.Teleportation.Components;
/// Represents an entity which is linked to other entities (perhaps portals), and which can be walked through/
/// thrown into to teleport an entity.
/// </summary>
[RegisterComponent, Access(typeof(LinkedEntitySystem)), NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(LinkedEntitySystem))]
public sealed partial class LinkedEntityComponent : Component
{
/// <summary>
/// The entities that this entity is linked to.
/// </summary>
[DataField("linkedEntities")]
[DataField, AutoNetworkedField]
public HashSet<EntityUid> LinkedEntities = new();
/// <summary>
/// Should this entity be deleted if all of its links are removed?
/// </summary>
[DataField("deleteOnEmptyLinks")]
public bool DeleteOnEmptyLinks = false;
}
[Serializable, NetSerializable]
public sealed class LinkedEntityComponentState : ComponentState
{
public HashSet<NetEntity> LinkedEntities;
public LinkedEntityComponentState(HashSet<NetEntity> linkedEntities)
{
LinkedEntities = linkedEntities;
}
[DataField]
public bool DeleteOnEmptyLinks;
}
[Serializable, NetSerializable]

View File

@@ -1,5 +1,4 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Teleportation.Components;
@@ -7,23 +6,12 @@ namespace Content.Shared.Teleportation.Components;
/// Attached to an entity after portal transit to mark that they should not immediately be portaled back
/// at the end destination.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class PortalTimeoutComponent : Component
{
/// <summary>
/// The portal that was entered. Null if coming from a hand teleporter, etc.
/// </summary>
[ViewVariables, DataField("enteredPortal")]
public EntityUid? EnteredPortal = null;
}
[Serializable, NetSerializable]
public sealed class PortalTimeoutComponentState : ComponentState
{
public NetEntity? EnteredPortal;
public PortalTimeoutComponentState(NetEntity? enteredPortal)
{
EnteredPortal = enteredPortal;
}
[ViewVariables, DataField, AutoNetworkedField]
public EntityUid? EnteredPortal;
}

View File

@@ -1,7 +1,6 @@
using Content.Shared.Teleportation.Components;
using Robust.Shared.GameStates;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Teleportation.Components;
namespace Content.Shared.Teleportation.Systems;
@@ -20,22 +19,6 @@ public sealed class LinkedEntitySystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<LinkedEntityComponent, ComponentShutdown>(OnLinkShutdown);
SubscribeLocalEvent<LinkedEntityComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<LinkedEntityComponent, ComponentHandleState>(OnHandleState);
}
private void OnGetState(EntityUid uid, LinkedEntityComponent component, ref ComponentGetState args)
{
args.State = new LinkedEntityComponentState(GetNetEntitySet(component.LinkedEntities));
}
private void OnHandleState(EntityUid uid, LinkedEntityComponent component, ref ComponentHandleState args)
{
if (args.Current is LinkedEntityComponentState state)
{
component.LinkedEntities = EnsureEntitySet<LinkedEntityComponent>(state.LinkedEntities, uid);
}
}
private void OnLinkShutdown(EntityUid uid, LinkedEntityComponent component, ComponentShutdown args)

View File

@@ -1,13 +1,11 @@
using System.Linq;
using Content.Shared.Ghost;
using Content.Shared.Pinpointer;
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
using Content.Shared.Teleportation.Components;
using Content.Shared.Verbs;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Physics.Dynamics;
@@ -42,9 +40,6 @@ public abstract class SharedPortalSystem : EntitySystem
SubscribeLocalEvent<PortalComponent, StartCollideEvent>(OnCollide);
SubscribeLocalEvent<PortalComponent, EndCollideEvent>(OnEndCollide);
SubscribeLocalEvent<PortalComponent, GetVerbsEvent<AlternativeVerb>>(OnGetVerbs);
SubscribeLocalEvent<PortalTimeoutComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<PortalTimeoutComponent, ComponentHandleState>(OnHandleState);
}
private void OnGetVerbs(EntityUid uid, PortalComponent component, GetVerbsEvent<AlternativeVerb> args)
@@ -77,17 +72,6 @@ public abstract class SharedPortalSystem : EntitySystem
});
}
private void OnGetState(EntityUid uid, PortalTimeoutComponent component, ref ComponentGetState args)
{
args.State = new PortalTimeoutComponentState(GetNetEntity(component.EnteredPortal));
}
private void OnHandleState(EntityUid uid, PortalTimeoutComponent component, ref ComponentHandleState args)
{
if (args.Current is PortalTimeoutComponentState state)
component.EnteredPortal = EnsureEntity<PortalTimeoutComponent>(state.EnteredPortal, uid);
}
private bool ShouldCollide(string ourId, string otherId, Fixture our, Fixture other)
{
// most non-hard fixtures shouldn't pass through portals, but projectiles are non-hard as well