Content ecs containers (#22484)

This commit is contained in:
TemporalOroboros
2023-12-27 21:30:03 -08:00
committed by GitHub
parent 1d06539432
commit 7a77d6d5dd
72 changed files with 172 additions and 160 deletions

View File

@@ -187,7 +187,7 @@ public sealed class ActionContainerSystem : EntitySystem
DebugTools.AssertOwner(uid, comp);
comp ??= EnsureComp<ActionsContainerComponent>(uid);
if (!comp.Container.Insert(actionId))
if (!_container.Insert(actionId, comp.Container))
{
Log.Error($"Failed to insert action {ToPrettyString(actionId)} into {ToPrettyString(uid)}");
return false;
@@ -239,7 +239,7 @@ public sealed class ActionContainerSystem : EntitySystem
if (_timing.ApplyingState && component.NetSyncEnabled)
return; // The game state should handle the container removal & action deletion.
component.Container.Shutdown();
_container.ShutdownContainer(component.Container);
}
private void OnEntityInserted(EntityUid uid, ActionsContainerComponent component, EntInsertedIntoContainerMessage args)

View File

@@ -161,7 +161,7 @@ public partial class SharedBodySystem
var partSlot = CreatePartSlot(parentEntity, connection, childPartComponent.PartType, parentPartComponent);
var cont = Containers.GetContainer(parentEntity, GetPartSlotContainerId(connection));
if (partSlot == null || !cont.Insert(childPart))
if (partSlot == null || !Containers.Insert(childPart, cont))
{
Log.Error($"Could not create slot for connection {connection} in body {prototype.ID}");
QueueDel(childPart);

View File

@@ -98,7 +98,7 @@ public partial class SharedBodySystem
if (!Containers.TryGetContainer(partId, containerId, out var container))
return false;
return container.Insert(organId);
return Containers.Insert(organId, container);
}
/// <summary>
@@ -114,7 +114,7 @@ public partial class SharedBodySystem
if (!HasComp<BodyPartComponent>(parent))
return false;
return container.Remove(organId);
return Containers.Remove(organId, container);
}
/// <summary>

View File

@@ -396,7 +396,7 @@ public partial class SharedBodySystem
return false;
}
return body.RootContainer.Insert(partId);
return Containers.Insert(partId, body.RootContainer);
}
#endregion
@@ -446,7 +446,7 @@ public partial class SharedBodySystem
return false;
}
return container.Insert(partId);
return Containers.Insert(partId, container);
}
#endregion

View File

@@ -36,7 +36,7 @@ public abstract class SharedCartridgeLoaderSystem : EntitySystem
{
_itemSlotsSystem.RemoveItemSlot(uid, loader.CartridgeSlot);
if (_container.TryGetContainer(uid, InstalledContainerId, out var cont))
cont.Shutdown(EntityManager, _netMan);
_container.ShutdownContainer(cont);
}
protected virtual void OnItemInserted(EntityUid uid, CartridgeLoaderComponent loader, EntInsertedIntoContainerMessage args)

View File

@@ -143,7 +143,7 @@ public sealed class ToggleableClothingSystem : EntitySystem
if (!_inventorySystem.TryUnequip(Transform(uid).ParentUid, toggleCom.Slot, force: true))
return;
toggleCom.Container.Insert(uid, EntityManager);
_containerSystem.Insert(uid, toggleCom.Container);
args.Handled = true;
}
@@ -229,8 +229,8 @@ public sealed class ToggleableClothingSystem : EntitySystem
// As unequipped gets called in the middle of container removal, we cannot call a container-insert without causing issues.
// So we delay it and process it during a system update:
if (toggleComp.ClothingUid != null)
toggleComp.Container?.Insert(toggleComp.ClothingUid.Value);
if (toggleComp.ClothingUid != null && toggleComp.Container != null)
_containerSystem.Insert(toggleComp.ClothingUid.Value, toggleComp.Container);
}
/// <summary>
@@ -302,7 +302,7 @@ public sealed class ToggleableClothingSystem : EntitySystem
var attachedClothing = EnsureComp<AttachedClothingComponent>(component.ClothingUid.Value);
attachedClothing.AttachedUid = uid;
Dirty(component.ClothingUid.Value, attachedClothing);
component.Container.Insert(component.ClothingUid.Value, EntityManager, ownerTransform: xform);
_containerSystem.Insert(component.ClothingUid.Value, component.Container, containerXform: xform);
Dirty(uid, component);
}

View File

@@ -77,7 +77,7 @@ public sealed class PartAssemblySystem : EntitySystem
return false;
component.CurrentAssembly = assemblyId;
component.PartsContainer.Insert(part);
_container.Insert(part, component.PartsContainer);
var ev = new PartAssemblyPartInsertedEvent();
RaiseLocalEvent(uid, ev);
return true;

View File

@@ -33,7 +33,7 @@ public sealed class ContainerFillSystem : EntitySystem
foreach (var proto in prototypes)
{
var ent = Spawn(proto, coords);
if (!container.Insert(ent, EntityManager, null, xform))
if (!_containerSystem.Insert(ent, container, containerXform: xform))
{
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} failed to insert an entity: {ToPrettyString(ent)}.");
Transform(ent).AttachToGridOrMap();

View File

@@ -68,7 +68,8 @@ namespace Content.Shared.Containers.ItemSlots
continue;
var item = EntityManager.SpawnEntity(slot.StartingItem, EntityManager.GetComponent<TransformComponent>(uid).Coordinates);
slot.ContainerSlot?.Insert(item);
if (slot.ContainerSlot != null)
_containers.Insert(item, slot.ContainerSlot);
}
}
@@ -115,7 +116,7 @@ namespace Content.Shared.Containers.ItemSlots
if (Terminating(uid) || slot.ContainerSlot == null)
return;
slot.ContainerSlot.Shutdown();
_containers.ShutdownContainer(slot.ContainerSlot);
// Don't log missing resolves. when an entity has all of its components removed, the ItemSlotsComponent may
// have been removed before some other component that added an item slot (and is now trying to remove it).
@@ -228,7 +229,7 @@ namespace Content.Shared.Containers.ItemSlots
/// Useful for predicted interactions</param>
private void Insert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
{
var inserted = slot.ContainerSlot?.Insert(item);
bool? inserted = slot.ContainerSlot != null ? _containers.Insert(item, slot.ContainerSlot) : null;
// ContainerSlot automatically raises a directed EntInsertedIntoContainerMessage
// Logging
@@ -350,7 +351,7 @@ namespace Content.Shared.Containers.ItemSlots
/// Useful for predicted interactions</param>
private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
{
var ejected = slot.ContainerSlot?.Remove(item);
bool? ejected = slot.ContainerSlot != null ? _containers.Remove(item, slot.ContainerSlot) : null;
// ContainerSlot automatically raises a directed EntRemovedFromContainerMessage
// Logging

View File

@@ -384,7 +384,7 @@ namespace Content.Shared.Cuffs
var container = cuffable.Container;
var entity = container.ContainedEntities[^1];
container.Remove(entity);
_container.Remove(entity, container);
_transform.SetWorldPosition(entity, _transform.GetWorldPosition(owner));
}
@@ -448,7 +448,7 @@ namespace Content.Shared.Cuffs
// Success!
_hands.TryDrop(user, handcuff);
component.Container.Insert(handcuff);
_container.Insert(handcuff, component.Container);
UpdateHeldItems(target, handcuff, component);
return true;
}
@@ -634,7 +634,7 @@ namespace Content.Shared.Cuffs
_audio.PlayPredicted(cuff.EndUncuffSound, target, user);
cuffable.Container.Remove(cuffsToRemove);
_container.Remove(cuffsToRemove, cuffable.Container);
if (_net.IsServer)
{

View File

@@ -17,7 +17,7 @@ public abstract class SharedDevourSystem : EntitySystem
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] protected readonly SharedContainerSystem ContainerSystem = default!;
public override void Initialize()
{
@@ -31,7 +31,7 @@ public abstract class SharedDevourSystem : EntitySystem
{
//Devourer doesn't actually chew, since he sends targets right into his stomach.
//I did it mom, I added ERP content into upstream. Legally!
component.Stomach = _containerSystem.EnsureContainer<Container>(uid, "stomach");
component.Stomach = ContainerSystem.EnsureContainer<Container>(uid, "stomach");
_actionsSystem.AddAction(uid, ref component.DevourActionEntity, component.DevourAction);
}

View File

@@ -120,7 +120,7 @@ public abstract partial class SharedHandsSystem
if (!isInContainer
|| !ContainerSystem.TryGetContainingContainer(userXform.ParentUid, uid, out var container, skipExistCheck: true)
|| !container.Insert(entity, EntityManager, itemXform))
|| !ContainerSystem.Insert((entity, itemXform), container))
TransformSystem.AttachToGridOrMap(entity, itemXform);
return true;
}
@@ -148,7 +148,7 @@ public abstract partial class SharedHandsSystem
return false;
DoDrop(uid, hand, false, handsComp);
targetContainer.Insert(entity);
ContainerSystem.Insert(entity, targetContainer);
return true;
}
@@ -189,7 +189,7 @@ public abstract partial class SharedHandsSystem
if (TerminatingOrDeleted(uid) || TerminatingOrDeleted(entity))
return;
if (!hand.Container.Remove(entity, EntityManager))
if (!ContainerSystem.Remove(entity, hand.Container))
{
Log.Error($"Failed to remove {ToPrettyString(entity)} from users hand container when dropping. User: {ToPrettyString(uid)}. Hand: {hand.Name}.");
return;

View File

@@ -217,7 +217,7 @@ public abstract partial class SharedHandsSystem : EntitySystem
if (handContainer == null || handContainer.ContainedEntity != null)
return;
if (!handContainer.Insert(entity, EntityManager))
if (!ContainerSystem.Insert(entity, handContainer))
{
Log.Error($"Failed to insert {ToPrettyString(entity)} into users hand container when picking up. User: {ToPrettyString(uid)}. Hand: {hand.Name}.");
return;

View File

@@ -73,7 +73,8 @@ public abstract partial class SharedHandsSystem
handsComp.SortedHands.Remove(hand.Name);
TryDrop(uid, hand, null, false, true, handsComp);
hand.Container?.Shutdown();
if (hand.Container != null)
ContainerSystem.ShutdownContainer(hand.Container);
if (handsComp.ActiveHand == hand)
TrySetActiveHand(uid, handsComp.SortedHands.FirstOrDefault(), handsComp);

View File

@@ -63,10 +63,11 @@ public abstract class SharedImplanterSystem : EntitySystem
var implantedComp = EnsureComp<ImplantedComponent>(target);
var implantContainer = implantedComp.ImplantContainer;
component.ImplanterSlot.ContainerSlot?.Remove(implant.Value);
if (component.ImplanterSlot.ContainerSlot != null)
_container.Remove(implant.Value, component.ImplanterSlot.ContainerSlot);
implantComp.ImplantedEntity = target;
implantContainer.OccludesLight = false;
implantContainer.Insert(implant.Value);
_container.Insert(implant.Value, implantContainer);
if (component.CurrentMode == ImplanterToggleMode.Inject && !component.ImplantOnly)
DrawMode(implanter, component);
@@ -140,9 +141,9 @@ public abstract class SharedImplanterSystem : EntitySystem
continue;
}
implantContainer.Remove(implant);
_container.Remove(implant, implantContainer);
implantComp.ImplantedEntity = null;
implanterContainer.Insert(implant);
_container.Insert(implant, implanterContainer);
permanentFound = implantComp.Permanent;
var ev = new TransferDnaEvent { Donor = target, Recipient = implanter };

View File

@@ -48,7 +48,7 @@ public abstract class SharedSubdermalImplantSystem : EntitySystem
{
if (_tag.HasTag(implant, "MicroBomb"))
{
implantContainer.Remove(implant);
_container.Remove(implant, implantContainer);
QueueDel(implant);
}
}
@@ -124,7 +124,7 @@ public abstract class SharedSubdermalImplantSystem : EntitySystem
var implantContainer = implantedComp.ImplantContainer;
component.ImplantedEntity = target;
implantContainer.Insert(implant);
_container.Insert(implant, implantContainer);
}
/// <summary>
@@ -140,7 +140,7 @@ public abstract class SharedSubdermalImplantSystem : EntitySystem
var implantContainer = implanted.ImplantContainer;
implantContainer.Remove(implant);
_container.Remove(implant, implantContainer);
QueueDel(implant);
}

View File

@@ -190,7 +190,7 @@ public abstract partial class InventorySystem
return false;
}
if (!slotContainer.Insert(itemUid))
if (!_containerSystem.Insert(itemUid, slotContainer))
{
if(!silent && _gameTiming.IsFirstTimePredicted)
_popup.PopupCursor(Loc.GetString("inventory-component-can-unequip-cannot"));
@@ -374,7 +374,7 @@ public abstract partial class InventorySystem
}
}
if (!slotContainer.Remove(removedItem.Value, force: force))
if (!_containerSystem.Remove(removedItem.Value, slotContainer, force: force))
return false;
// TODO: Inventory needs a hot cleanup hoo boy

View File

@@ -26,7 +26,7 @@ public abstract class SharedMaterialReclaimerSystem : EntitySystem
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] protected readonly SharedAmbientSoundSystem AmbientSound = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] protected readonly SharedContainerSystem Container = default!;
public const string ActiveReclaimerContainerId = "active-material-reclaimer-container";
@@ -79,7 +79,7 @@ public abstract class SharedMaterialReclaimerSystem : EntitySystem
private void OnActiveStartup(EntityUid uid, ActiveMaterialReclaimerComponent component, ComponentStartup args)
{
component.ReclaimingContainer = _container.EnsureContainer<Container>(uid, ActiveReclaimerContainerId);
component.ReclaimingContainer = Container.EnsureContainer<Container>(uid, ActiveReclaimerContainerId);
}
private void OnActiveUnpaused(EntityUid uid, ActiveMaterialReclaimerComponent component, ref EntityUnpausedEvent args)
@@ -107,7 +107,7 @@ public abstract class SharedMaterialReclaimerSystem : EntitySystem
if (component.Blacklist is {} blacklist && blacklist.IsValid(item))
return false;
if (_container.TryGetContainingContainer(item, out _) && !_container.TryRemoveFromContainer(item))
if (Container.TryGetContainingContainer(item, out _) && !Container.TryRemoveFromContainer(item))
return false;
if (user != null)
@@ -133,7 +133,7 @@ public abstract class SharedMaterialReclaimerSystem : EntitySystem
var active = EnsureComp<ActiveMaterialReclaimerComponent>(uid);
active.Duration = duration;
active.EndTime = Timing.CurTime + duration;
active.ReclaimingContainer.Insert(item);
Container.Insert(item, active.ReclaimingContainer);
return true;
}

View File

@@ -220,7 +220,7 @@ public abstract class SharedMechSystem : EntitySystem
return;
equipmentComponent.EquipmentOwner = uid;
component.EquipmentContainer.Insert(toInsert, EntityManager);
_container.Insert(toInsert, component.EquipmentContainer);
var ev = new MechEquipmentInsertedEvent(uid);
RaiseLocalEvent(toInsert, ref ev);
UpdateUserInterface(uid, component);
@@ -258,7 +258,7 @@ public abstract class SharedMechSystem : EntitySystem
CycleEquipment(uid, component);
equipmentComponent.EquipmentOwner = null;
component.EquipmentContainer.Remove(toRemove, EntityManager);
_container.Remove(toRemove, component.EquipmentContainer);
UpdateUserInterface(uid, component);
}
@@ -364,7 +364,7 @@ public abstract class SharedMechSystem : EntitySystem
return false;
SetupUser(uid, toInsert.Value);
component.PilotSlot.Insert(toInsert.Value, EntityManager);
_container.Insert(toInsert.Value, component.PilotSlot);
UpdateAppearance(uid, component);
return true;
}

View File

@@ -76,7 +76,7 @@ public abstract partial class SharedCryoPodSystem: EntitySystem
return false;
var xform = Transform(target);
cryoPodComponent.BodyContainer.Insert(target, transform: xform);
_containerSystem.Insert((target, xform), cryoPodComponent.BodyContainer);
EnsureComp<InsideCryoPodComponent>(target);
_standingStateSystem.Stand(target, force: true); // Force-stand the mob so that the cryo pod sprite overlays it fully
@@ -117,7 +117,7 @@ public abstract partial class SharedCryoPodSystem: EntitySystem
if (cryoPodComponent.BodyContainer.ContainedEntity is not {Valid: true} contained)
return null;
cryoPodComponent.BodyContainer.Remove(contained);
_containerSystem.Remove(contained, cryoPodComponent.BodyContainer);
// InsideCryoPodComponent is removed automatically in its EntGotRemovedFromContainerMessage listener
// RemComp<InsideCryoPodComponent>(contained);

View File

@@ -134,7 +134,7 @@ public sealed partial class EncryptionKeySystem : EntitySystem
return;
}
if (component.KeyContainer.Insert(args.Used))
if (_container.Insert(args.Used, component.KeyContainer))
{
_popup.PopupClient(Loc.GetString("encryption-key-successfully-installed"), uid, args.User);
_audio.PlayPredicted(component.KeyInsertionSound, args.Target, args.User);

View File

@@ -138,7 +138,7 @@ public sealed class BinSystem : EntitySystem
if (component.Whitelist != null && !component.Whitelist.IsValid(toInsert))
return false;
component.ItemContainer.Insert(toInsert);
_container.Insert(toInsert, component.ItemContainer);
component.Items.Add(toInsert);
Dirty(component);
return true;
@@ -162,7 +162,7 @@ public sealed class BinSystem : EntitySystem
if (toRemove == null || toRemove != component.Items.LastOrDefault())
return false;
if (!component.ItemContainer.Remove(toRemove.Value))
if (!_container.Remove(toRemove.Value, component.ItemContainer))
return false;
component.Items.Remove(toRemove.Value);

View File

@@ -263,7 +263,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
}
_joints.RecursiveClearJoints(toInsert);
if (!component.Contents.Insert(toInsert, EntityManager))
if (!_container.Insert(toInsert, component.Contents))
return false;
var inside = EnsureComp<InsideEntityStorageComponent>(toInsert);
@@ -280,7 +280,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
return false;
RemComp<InsideEntityStorageComponent>(toRemove);
component.Contents.Remove(toRemove, EntityManager);
_container.Remove(toRemove, component.Contents);
var pos = TransformSystem.GetWorldPosition(xform) + TransformSystem.GetWorldRotation(xform).RotateVec(component.EnteringOffset);
TransformSystem.SetWorldPosition(toRemove, pos);
return true;

View File

@@ -48,7 +48,7 @@ public abstract partial class SharedGunSystem
return;
component.Entities.Add(args.Used);
component.Container.Insert(args.Used);
Containers.Insert(args.Used, component.Container);
// Not predicted so
Audio.PlayPredicted(component.SoundInsert, uid, args.User);
args.Handled = true;
@@ -241,7 +241,7 @@ public abstract partial class SharedGunSystem
args.Ammo.Add((entity, EnsureShootable(entity)));
component.Entities.RemoveAt(component.Entities.Count - 1);
component.Container.Remove(entity);
Containers.Remove(entity, component.Container);
}
else if (component.UnspawnedCount > 0)
{

View File

@@ -290,7 +290,7 @@ public abstract partial class SharedGunSystem
if (entity == null)
return false;
container.Remove(entity.Value);
Containers.Remove(entity.Value, container);
return true;
}
@@ -316,7 +316,7 @@ public abstract partial class SharedGunSystem
{
return Containers.TryGetContainer(uid, ChamberSlot, out var container) &&
container is ContainerSlot slot &&
slot.Insert(ammo);
Containers.Insert(ammo, slot);
}
private void OnChamberAmmoCount(EntityUid uid, ChamberMagazineAmmoProviderComponent component, ref GetAmmoCountEvent args)

View File

@@ -28,7 +28,7 @@ public partial class SharedGunSystem
var ent = container.ContainedEntities[0];
if (_netManager.IsServer)
container.Remove(ent);
Containers.Remove(ent, container);
args.Ammo.Add((ent, EnsureShootable(ent)));
}

View File

@@ -132,7 +132,7 @@ public partial class SharedGunSystem
}
component.AmmoSlots[index] = ent.Value;
component.AmmoContainer.Insert(ent.Value, EntityManager);
Containers.Insert(ent.Value, component.AmmoContainer);
if (ev.Ammo.Count == 0)
break;
@@ -160,7 +160,7 @@ public partial class SharedGunSystem
}
component.AmmoSlots[index] = uid;
component.AmmoContainer.Insert(uid);
Containers.Insert(uid, component.AmmoContainer);
Audio.PlayPredicted(component.SoundInsert, revolverUid, user);
Popup(Loc.GetString("gun-revolver-insert"), revolverUid, user);
UpdateRevolverAppearance(revolverUid, component);
@@ -283,7 +283,7 @@ public partial class SharedGunSystem
else
{
component.AmmoSlots[i] = null;
component.AmmoContainer.Remove(slot.Value);
Containers.Remove(slot.Value, component.AmmoContainer);
if (!_netManager.IsClient)
EjectCartridge(slot.Value);
@@ -366,7 +366,7 @@ public partial class SharedGunSystem
continue;
}
component.AmmoContainer.Remove(ent.Value);
Containers.Remove(ent.Value, component.AmmoContainer);
component.AmmoSlots[index] = null;
args.Ammo.Add((ent.Value, EnsureShootable(ent.Value)));
TransformSystem.SetCoordinates(ent.Value, args.Coordinates);