InventoryComponent type handler for entities in inv slots (#12026)
This commit is contained in:
committed by
GitHub
parent
d4c092a373
commit
d05b2a8e71
@@ -7,10 +7,20 @@ namespace Content.Shared.Inventory;
|
|||||||
public partial class InventorySystem : EntitySystem
|
public partial class InventorySystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly IViewVariablesManager _vvm = default!;
|
||||||
|
|
||||||
private void InitializeSlots()
|
private void InitializeSlots()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<InventoryComponent, ComponentInit>(OnInit);
|
SubscribeLocalEvent<InventoryComponent, ComponentInit>(OnInit);
|
||||||
|
|
||||||
|
_vvm.GetTypeHandler<InventoryComponent>()
|
||||||
|
.AddHandler(HandleViewVariablesSlots, ListViewVariablesSlots);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShutdownSlots()
|
||||||
|
{
|
||||||
|
_vvm.GetTypeHandler<InventoryComponent>()
|
||||||
|
.RemoveHandler(HandleViewVariablesSlots, ListViewVariablesSlots);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnInit(EntityUid uid, InventoryComponent component, ComponentInit args)
|
protected virtual void OnInit(EntityUid uid, InventoryComponent component, ComponentInit args)
|
||||||
@@ -99,6 +109,21 @@ public partial class InventorySystem : EntitySystem
|
|||||||
return _prototypeManager.Index<InventoryTemplatePrototype>(inventoryComponent.TemplateId).Slots;
|
return _prototypeManager.Index<InventoryTemplatePrototype>(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<string> ListViewVariablesSlots(EntityUid uid, InventoryComponent comp)
|
||||||
|
{
|
||||||
|
foreach (var slotDef in GetSlots(uid, comp))
|
||||||
|
{
|
||||||
|
yield return slotDef.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public struct ContainerSlotEnumerator
|
public struct ContainerSlotEnumerator
|
||||||
{
|
{
|
||||||
private readonly InventorySystem _inventorySystem;
|
private readonly InventorySystem _inventorySystem;
|
||||||
|
|||||||
@@ -10,4 +10,10 @@ public partial class InventorySystem
|
|||||||
InitializeRelay();
|
InitializeRelay();
|
||||||
InitializeSlots();
|
InitializeSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
base.Shutdown();
|
||||||
|
ShutdownSlots();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user