Storage Component ECS (#7530)
Co-authored-by: fishfish458 <fishfish458> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Placeable;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -16,6 +11,42 @@ namespace Content.Shared.Storage
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedStorageComponent : Component, IDraggable
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public readonly List<EntityUid> StoredEntities;
|
||||
public readonly int StorageSizeUsed;
|
||||
public readonly int StorageCapacityMax;
|
||||
|
||||
public StorageBoundUserInterfaceState(List<EntityUid> storedEntities, int storageSizeUsed, int storageCapacityMax)
|
||||
{
|
||||
StoredEntities = storedEntities;
|
||||
StorageSizeUsed = storageSizeUsed;
|
||||
StorageCapacityMax = storageCapacityMax;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageRemoveItemMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public readonly EntityUid InteractedItemUID;
|
||||
public StorageRemoveItemMessage(EntityUid interactedItemUID)
|
||||
{
|
||||
InteractedItemUID = interactedItemUID;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum StorageUiKey
|
||||
{
|
||||
Key,
|
||||
}
|
||||
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
public abstract IReadOnlyList<EntityUid>? StoredEntities { get; }
|
||||
|
||||
@@ -35,75 +66,24 @@ namespace Content.Shared.Storage
|
||||
bool IDraggable.Drop(DragDropEvent eventArgs)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User, eventArgs.Target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var storedEntities = StoredEntities?.ToArray();
|
||||
|
||||
if (storedEntities == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// empty everything out
|
||||
foreach (var storedEntity in storedEntities)
|
||||
{
|
||||
if (Remove(storedEntity))
|
||||
{
|
||||
_entMan.GetComponent<TransformComponent>(storedEntity).WorldPosition = eventArgs.DropLocation.Position;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageComponentState : ComponentState
|
||||
{
|
||||
public readonly EntityUid[] StoredEntities;
|
||||
|
||||
public StorageComponentState(EntityUid[] storedEntities)
|
||||
{
|
||||
StoredEntities = storedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the client component about what entities this storage is holding
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageHeldItemsEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
public readonly int StorageSizeMax;
|
||||
public readonly int StorageSizeUsed;
|
||||
public readonly EntityUid[] StoredEntities;
|
||||
|
||||
public StorageHeldItemsEvent(EntityUid storage, int storageSizeMax, int storageSizeUsed, EntityUid[] storedEntities)
|
||||
{
|
||||
Storage = storage;
|
||||
StorageSizeMax = storageSizeMax;
|
||||
StorageSizeUsed = storageSizeUsed;
|
||||
StoredEntities = storedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for adding an entity to the storage entity.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InsertEntityEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public InsertEntityEvent(EntityUid storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for displaying an animation of entities flying into a storage entity
|
||||
/// </summary>
|
||||
@@ -122,51 +102,6 @@ namespace Content.Shared.Storage
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for removing a contained entity from the storage entity
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class RemoveEntityEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Storage;
|
||||
public EntityUid EntityUid;
|
||||
|
||||
public RemoveEntityEvent(EntityUid storage, EntityUid entityUid)
|
||||
{
|
||||
Storage = storage;
|
||||
EntityUid = entityUid;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for opening the storage UI
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class OpenStorageUIEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public OpenStorageUIEvent(EntityUid storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for closing the storage UI.
|
||||
/// E.g when the player moves too far away from the container.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class CloseStorageUIEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public CloseStorageUIEvent(EntityUid storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable]
|
||||
[Serializable]
|
||||
public enum StorageVisuals
|
||||
|
||||
Reference in New Issue
Block a user