Content update for NetEntities (#18935)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
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;
|
||||
|
||||
@@ -19,6 +21,28 @@ 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)
|
||||
@@ -57,16 +81,23 @@ 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>
|
||||
/// Raised on the <see cref="ItemPlacer"/> when an item is placed and it is under the item limit.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct ItemPlacedEvent(EntityUid OtherEntity);
|
||||
public readonly record struct ItemPlacedEvent(EntityUid OtherEntity);
|
||||
|
||||
/// <summary>
|
||||
/// Raised on the <see cref="ItemPlacer"/> when an item is removed from it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct ItemRemovedEvent(EntityUid OtherEntity);
|
||||
public readonly record struct ItemRemovedEvent(EntityUid OtherEntity);
|
||||
|
||||
Reference in New Issue
Block a user