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

@@ -6,26 +6,27 @@ namespace Content.Shared.Placeable;
/// <summary>
/// Detects items placed on it that match a whitelist.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(ItemPlacerSystem))]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(ItemPlacerSystem))]
public sealed partial class ItemPlacerComponent : Component
{
/// <summary>
/// The entities that are currently on top of the placer.
/// Guaranteed to have less than <see cref="MaxEntities"/> enitities if it is set.
/// </summary>
[DataField("placedEntities")]
[DataField, AutoNetworkedField]
public HashSet<EntityUid> PlacedEntities = new();
/// <summary>
/// Whitelist for entities that can be placed.
/// </summary>
[DataField("whitelist"), ViewVariables(VVAccess.ReadWrite)]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public EntityWhitelist? Whitelist;
/// <summary>
/// The max amount of entities that can be placed at the same time.
/// If 0, there is no limit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("maxEntities")]
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public uint MaxEntities = 1;
}

View File

@@ -1,8 +1,5 @@
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using System.Linq;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Placeable;
@@ -21,28 +18,6 @@ public sealed class ItemPlacerSystem : EntitySystem
SubscribeLocalEvent<ItemPlacerComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<ItemPlacerComponent, EndCollideEvent>(OnEndCollide);
SubscribeLocalEvent<ItemPlacerComponent, ComponentGetState>(OnPlacerGetState);
SubscribeLocalEvent<ItemPlacerComponent, ComponentHandleState>(OnPlacerHandleState);
}
private void OnPlacerHandleState(EntityUid uid, ItemPlacerComponent component, ref ComponentHandleState args)
{
if (args.Current is not ItemPlacerComponentState state)
return;
component.MaxEntities = state.MaxEntities;
component.PlacedEntities.Clear();
var ents = EnsureEntitySet<ItemPlacerComponent>(state.Entities, uid);
component.PlacedEntities.UnionWith(ents);
}
private void OnPlacerGetState(EntityUid uid, ItemPlacerComponent component, ref ComponentGetState args)
{
args.State = new ItemPlacerComponentState()
{
MaxEntities = component.MaxEntities,
Entities = GetNetEntitySet(component.PlacedEntities),
};
}
private void OnStartCollide(EntityUid uid, ItemPlacerComponent comp, ref StartCollideEvent args)
@@ -81,13 +56,6 @@ public sealed class ItemPlacerSystem : EntitySystem
_placeableSurface.SetPlaceable(uid, true);
}
[Serializable, NetSerializable]
private sealed class ItemPlacerComponentState : ComponentState
{
public uint MaxEntities;
public HashSet<NetEntity> Entities = default!;
}
}
/// <summary>

View File

@@ -1,35 +1,18 @@
using System.Numerics;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Placeable
namespace Content.Shared.Placeable;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(PlaceableSurfaceSystem))]
public sealed partial class PlaceableSurfaceComponent : Component
{
[RegisterComponent, NetworkedComponent]
[Access(typeof(PlaceableSurfaceSystem))]
public sealed partial class PlaceableSurfaceComponent : Component
{
[DataField("isPlaceable")]
public bool IsPlaceable { get; set; } = true;
[DataField, AutoNetworkedField]
public bool IsPlaceable { get; set; } = true;
[DataField("placeCentered")]
public bool PlaceCentered { get; set; }
[DataField, AutoNetworkedField]
public bool PlaceCentered { get; set; }
[DataField("positionOffset")]
public Vector2 PositionOffset { get; set; }
}
[Serializable, NetSerializable]
public sealed class PlaceableSurfaceComponentState : ComponentState
{
public readonly bool IsPlaceable;
public readonly bool PlaceCentered;
public readonly Vector2 PositionOffset;
public PlaceableSurfaceComponentState(bool placeable, bool centered, Vector2 offset)
{
IsPlaceable = placeable;
PlaceCentered = centered;
PositionOffset = offset;
}
}
[DataField, AutoNetworkedField]
public Vector2 PositionOffset { get; set; }
}

View File

@@ -1,8 +1,7 @@
using System.Numerics;
using Content.Shared.Storage.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Robust.Shared.GameStates;
using Content.Shared.Storage.Components;
namespace Content.Shared.Placeable
{
@@ -15,13 +14,6 @@ namespace Content.Shared.Placeable
base.Initialize();
SubscribeLocalEvent<PlaceableSurfaceComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
SubscribeLocalEvent<PlaceableSurfaceComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<PlaceableSurfaceComponent, ComponentHandleState>(OnHandleState);
}
private void OnGetState(EntityUid uid, PlaceableSurfaceComponent component, ref ComponentGetState args)
{
args.State = new PlaceableSurfaceComponentState(component.IsPlaceable, component.PlaceCentered, component.PositionOffset);
}
public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceComponent? surface = null)
@@ -30,7 +22,7 @@ namespace Content.Shared.Placeable
return;
surface.IsPlaceable = isPlaceable;
Dirty(surface);
Dirty(uid, surface);
}
public void SetPlaceCentered(EntityUid uid, bool placeCentered, PlaceableSurfaceComponent? surface = null)
@@ -39,7 +31,7 @@ namespace Content.Shared.Placeable
return;
surface.PlaceCentered = placeCentered;
Dirty(surface);
Dirty(uid, surface);
}
public void SetPositionOffset(EntityUid uid, Vector2 offset, PlaceableSurfaceComponent? surface = null)
@@ -48,7 +40,7 @@ namespace Content.Shared.Placeable
return;
surface.PositionOffset = offset;
Dirty(surface);
Dirty(uid, surface);
}
private void OnAfterInteractUsing(EntityUid uid, PlaceableSurfaceComponent surface, AfterInteractUsingEvent args)
@@ -74,15 +66,5 @@ namespace Content.Shared.Placeable
args.Handled = true;
}
private void OnHandleState(EntityUid uid, PlaceableSurfaceComponent component, ref ComponentHandleState args)
{
if (args.Current is not PlaceableSurfaceComponentState state)
return;
component.IsPlaceable = state.IsPlaceable;
component.PlaceCentered = state.PlaceCentered;
component.PositionOffset = state.PositionOffset;
}
}
}