diff --git a/Content.Shared/Inventory/InventorySystem.Slots.cs b/Content.Shared/Inventory/InventorySystem.Slots.cs index b251720046..c84d24500e 100644 --- a/Content.Shared/Inventory/InventorySystem.Slots.cs +++ b/Content.Shared/Inventory/InventorySystem.Slots.cs @@ -7,10 +7,20 @@ namespace Content.Shared.Inventory; public partial class InventorySystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IViewVariablesManager _vvm = default!; private void InitializeSlots() { SubscribeLocalEvent(OnInit); + + _vvm.GetTypeHandler() + .AddHandler(HandleViewVariablesSlots, ListViewVariablesSlots); + } + + private void ShutdownSlots() + { + _vvm.GetTypeHandler() + .RemoveHandler(HandleViewVariablesSlots, ListViewVariablesSlots); } protected virtual void OnInit(EntityUid uid, InventoryComponent component, ComponentInit args) @@ -99,6 +109,21 @@ public partial class InventorySystem : EntitySystem return _prototypeManager.Index(inventoryComponent.TemplateId).Slots; } + private ViewVariablesPath? HandleViewVariablesSlots(EntityUid uid, InventoryComponent comp, string relativePath) + { + return TryGetSlotEntity(uid, relativePath, out var entity, comp) + ? ViewVariablesPath.FromObject(entity) + : null; + } + + private IEnumerable ListViewVariablesSlots(EntityUid uid, InventoryComponent comp) + { + foreach (var slotDef in GetSlots(uid, comp)) + { + yield return slotDef.Name; + } + } + public struct ContainerSlotEnumerator { private readonly InventorySystem _inventorySystem; diff --git a/Content.Shared/Inventory/InventorySystem.cs b/Content.Shared/Inventory/InventorySystem.cs index b50f17c2d1..b5d1a0f43a 100644 --- a/Content.Shared/Inventory/InventorySystem.cs +++ b/Content.Shared/Inventory/InventorySystem.cs @@ -10,4 +10,10 @@ public partial class InventorySystem InitializeRelay(); InitializeSlots(); } + + public override void Shutdown() + { + base.Shutdown(); + ShutdownSlots(); + } }