decouple ItemToggle from PowerCellDraw (#31392)

* remove ItemToggle from PowerCellDraw query

* add EntityQuery for resolves, make them all optional

* move integration to ToggleCellDraw

* add ToggleCellDraw to almost every PowerCellDraw prototype

* :trollface:

* :trollface:

* :trollface:

* let it disable on mapinit

* set update time on mapinit, make borg power logic consistent now

* :trollface:

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2024-08-25 12:17:03 +00:00
committed by GitHub
parent 42865ae705
commit e1df251cbc
15 changed files with 99 additions and 28 deletions

View File

@@ -1,6 +1,4 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Item.ItemToggle;
using Content.Shared.Item.ItemToggle.Components;
using Content.Shared.PowerCell.Components;
using Content.Shared.Rejuvenate;
using Robust.Shared.Containers;
@@ -13,19 +11,22 @@ public abstract class SharedPowerCellSystem : EntitySystem
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] protected readonly ItemToggleSystem Toggle = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PowerCellDrawComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<PowerCellSlotComponent, RejuvenateEvent>(OnRejuvenate);
SubscribeLocalEvent<PowerCellSlotComponent, EntInsertedIntoContainerMessage>(OnCellInserted);
SubscribeLocalEvent<PowerCellSlotComponent, EntRemovedFromContainerMessage>(OnCellRemoved);
SubscribeLocalEvent<PowerCellSlotComponent, ContainerIsInsertingAttemptEvent>(OnCellInsertAttempt);
}
SubscribeLocalEvent<PowerCellDrawComponent, ItemToggleActivateAttemptEvent>(OnActivateAttempt);
SubscribeLocalEvent<PowerCellDrawComponent, ItemToggledEvent>(OnToggled);
private void OnMapInit(Entity<PowerCellDrawComponent> ent, ref MapInitEvent args)
{
QueueUpdate((ent, ent.Comp));
}
private void OnRejuvenate(EntityUid uid, PowerCellSlotComponent component, RejuvenateEvent args)
@@ -70,16 +71,13 @@ public abstract class SharedPowerCellSystem : EntitySystem
RaiseLocalEvent(uid, new PowerCellChangedEvent(true), false);
}
private void OnActivateAttempt(Entity<PowerCellDrawComponent> ent, ref ItemToggleActivateAttemptEvent args)
/// <summary>
/// Makes the draw logic update in the next tick.
/// </summary>
public void QueueUpdate(Entity<PowerCellDrawComponent?> ent)
{
if (!HasDrawCharge(ent, ent.Comp, user: args.User)
|| !HasActivatableCharge(ent, ent.Comp, user: args.User))
args.Cancelled = true;
}
private void OnToggled(Entity<PowerCellDrawComponent> ent, ref ItemToggledEvent args)
{
ent.Comp.NextUpdateTime = Timing.CurTime;
if (Resolve(ent, ref ent.Comp))
ent.Comp.NextUpdateTime = Timing.CurTime;
}
public void SetDrawEnabled(Entity<PowerCellDrawComponent?> ent, bool enabled)