Unhardcode some logic related to objects with battery slots. Minor fix to fire helmets. (#11734)
This commit is contained in:
@@ -12,37 +12,8 @@ public sealed class PowerCellSlotComponent : Component
|
||||
/// Given that <see cref="PowerCellSystem"/> needs to verify that a given cell has the correct cell-size before
|
||||
/// inserting anyways, there is no need to specify a separate entity whitelist. In this slot's yaml definition.
|
||||
/// </remarks>
|
||||
[DataField("cellSlot")]
|
||||
public ItemSlot CellSlot = new();
|
||||
|
||||
/// <summary>
|
||||
/// Name of the item-slot used to store cells. Determines the eject/insert verb text. E.g., "Eject > Power cell".
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is simply used provide a default value for <see cref="CellSlot.Name"/>. If this string is empty or
|
||||
/// whitespace, the verb will instead use the full name of any cell (e.g., "eject > small super-capacity power
|
||||
/// cell").
|
||||
/// </remarks>
|
||||
[DataField("slotName")]
|
||||
public readonly string SlotName = "power-cell-slot-component-slot-name-default"; // gets Loc.GetString()-ed by ItemSlotsSystem
|
||||
|
||||
/// <summary>
|
||||
/// True if we don't want a cell inserted during map init. If a starting item is defined
|
||||
/// in the <see cref="CellSlot"/> yaml definition, that always takes precedence.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If false, the cell will start with a standard cell with a matching cell-size.
|
||||
/// </remarks>
|
||||
[DataField("startEmpty")]
|
||||
public bool StartEmpty = false;
|
||||
|
||||
/// <summary>
|
||||
/// Descriptive text to add to add when examining an entity with a cell slot. If empty or whitespace, will not add
|
||||
/// any text.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("descFormatString")]
|
||||
public string? DescFormatString { get; set; } = "power-cell-slot-component-description-default";
|
||||
[DataField("cellSlotId", required: true)]
|
||||
public string CellSlotId = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Can this entity be inserted directly into a charging station? If false, you need to manually remove the power
|
||||
@@ -50,6 +21,7 @@ public sealed class PowerCellSlotComponent : Component
|
||||
/// </summary>
|
||||
[DataField("fitsInCharger")]
|
||||
public bool FitsInCharger = true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user