mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
* Fix containers that hold entities not on client * Delete from ExpectedEntities when entity removed * Fix ContainerSystem not registering on the server * Move container state to entity system Move client code to client * Fix removal and clean up code * Add test * Add more checks to test * Remove unneeded deletion event handler When the child is deleted, if the entity does not exist on the client, then HandleComponentState runs. If the entity does exist, then HandleEntityInitialized would have run. Either way HandleEntityDeleted is not needed. * Renamed unexpected to removedExpected
69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
|
|
namespace Robust.Shared.Containers
|
|
{
|
|
/// <summary>
|
|
/// Default implementation for containers,
|
|
/// cannot be inherited. If additional logic is needed,
|
|
/// this logic should go on the systems that are holding this container.
|
|
/// For example, inventory containers should be modified only through an inventory component.
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
[SerializedType(ClassName)]
|
|
public sealed class Container : BaseContainer
|
|
{
|
|
private const string ClassName = "Container";
|
|
|
|
/// <summary>
|
|
/// The generic container class uses a list of entities
|
|
/// </summary>
|
|
[DataField("ents")]
|
|
private readonly List<IEntity> _containerList = new();
|
|
|
|
private readonly List<EntityUid> _expectedEntities = new();
|
|
|
|
/// <inheritdoc />
|
|
public override IReadOnlyList<IEntity> ContainedEntities => _containerList;
|
|
|
|
public override List<EntityUid> ExpectedEntities => _expectedEntities;
|
|
|
|
/// <inheritdoc />
|
|
public override string ContainerType => ClassName;
|
|
|
|
/// <inheritdoc />
|
|
protected override void InternalInsert(IEntity toinsert)
|
|
{
|
|
_containerList.Add(toinsert);
|
|
base.InternalInsert(toinsert);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void InternalRemove(IEntity toremove)
|
|
{
|
|
_containerList.Remove(toremove);
|
|
base.InternalRemove(toremove);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool Contains(IEntity contained)
|
|
{
|
|
return _containerList.Contains(contained);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Shutdown()
|
|
{
|
|
base.Shutdown();
|
|
|
|
foreach (var entity in _containerList)
|
|
{
|
|
entity.Delete();
|
|
}
|
|
}
|
|
}
|
|
}
|