Unhardcode some logic related to objects with battery slots. Minor fix to fire helmets. (#11734)

This commit is contained in:
Mervill
2022-10-15 13:15:39 -07:00
committed by GitHub
parent 581a805063
commit c11c11bace
13 changed files with 86 additions and 101 deletions

View File

@@ -1,5 +1,3 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Examine;
using Content.Shared.PowerCell.Components;
using Robust.Shared.Containers;
@@ -7,17 +5,9 @@ namespace Content.Shared.PowerCell;
public abstract class SharedPowerCellSystem : EntitySystem
{
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
public const string CellSlotContainer = "cell_slot";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PowerCellSlotComponent, ComponentInit>(OnCellSlotInit);
SubscribeLocalEvent<PowerCellSlotComponent, ComponentRemove>(OnCellSlotRemove);
SubscribeLocalEvent<PowerCellSlotComponent, EntInsertedIntoContainerMessage>(OnCellInserted);
SubscribeLocalEvent<PowerCellSlotComponent, EntRemovedFromContainerMessage>(OnCellRemoved);
SubscribeLocalEvent<PowerCellSlotComponent, ContainerIsInsertingAttemptEvent>(OnCellInsertAttempt);
@@ -28,7 +18,7 @@ public abstract class SharedPowerCellSystem : EntitySystem
if (!component.Initialized)
return;
if (args.Container.ID != component.CellSlot.ID)
if (args.Container.ID != component.CellSlotId)
return;
if (!HasComp<PowerCellComponent>(args.EntityUid))
@@ -42,7 +32,7 @@ public abstract class SharedPowerCellSystem : EntitySystem
if (!component.Initialized)
return;
if (args.Container.ID != component.CellSlot.ID)
if (args.Container.ID != component.CellSlotId)
return;
RaiseLocalEvent(uid, new PowerCellChangedEvent(false), false);
@@ -50,25 +40,9 @@ public abstract class SharedPowerCellSystem : EntitySystem
private void OnCellRemoved(EntityUid uid, PowerCellSlotComponent component, EntRemovedFromContainerMessage args)
{
if (args.Container.ID != component.CellSlot.ID)
if (args.Container.ID != component.CellSlotId)
return;
RaiseLocalEvent(uid, new PowerCellChangedEvent(true), false);
}
private void OnCellSlotInit(EntityUid uid, PowerCellSlotComponent component, ComponentInit args)
{
_itemSlotsSystem.AddItemSlot(uid, CellSlotContainer, component.CellSlot);
if (string.IsNullOrWhiteSpace(component.CellSlot.Name) &&
!string.IsNullOrWhiteSpace(component.SlotName))
{
component.CellSlot.Name = component.SlotName;
}
}
private void OnCellSlotRemove(EntityUid uid, PowerCellSlotComponent component, ComponentRemove args)
{
_itemSlotsSystem.RemoveItemSlot(uid, component.CellSlot);
}
}