-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 **
*
* let it disable on mapinit * set update time on mapinit, make borg power logic consistent now *
--------- Co-authored-by: deltanedas <@deltanedas:kde.org>
- Loading branch information
1 parent
42865ae
commit e1df251
Showing
15 changed files
with
99 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Content.Shared/PowerCell/Components/ToggleCellDrawComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.PowerCell.Components; | ||
|
||
/// <summary> | ||
/// Integrate PowerCellDraw and ItemToggle. | ||
/// Make toggling this item require power, and deactivates the item when power runs out. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class ToggleCellDrawComponent : Component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Content.Shared.Item.ItemToggle; | ||
using Content.Shared.Item.ItemToggle.Components; | ||
using Content.Shared.PowerCell.Components; | ||
|
||
namespace Content.Shared.PowerCell; | ||
|
||
/// <summary> | ||
/// Handles events to integrate PowerCellDraw with ItemToggle | ||
/// </summary> | ||
public sealed class ToggleCellDrawSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ItemToggleSystem _toggle = default!; | ||
[Dependency] private readonly SharedPowerCellSystem _cell = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<ToggleCellDrawComponent, MapInitEvent>(OnMapInit); | ||
SubscribeLocalEvent<ToggleCellDrawComponent, ItemToggleActivateAttemptEvent>(OnActivateAttempt); | ||
SubscribeLocalEvent<ToggleCellDrawComponent, ItemToggledEvent>(OnToggled); | ||
SubscribeLocalEvent<ToggleCellDrawComponent, PowerCellSlotEmptyEvent>(OnEmpty); | ||
} | ||
|
||
private void OnMapInit(Entity<ToggleCellDrawComponent> ent, ref MapInitEvent args) | ||
{ | ||
_cell.SetDrawEnabled(ent.Owner, _toggle.IsActivated(ent.Owner)); | ||
} | ||
|
||
private void OnActivateAttempt(Entity<ToggleCellDrawComponent> ent, ref ItemToggleActivateAttemptEvent args) | ||
{ | ||
if (!_cell.HasDrawCharge(ent, user: args.User) | ||
|| !_cell.HasActivatableCharge(ent, user: args.User)) | ||
args.Cancelled = true; | ||
} | ||
|
||
private void OnToggled(Entity<ToggleCellDrawComponent> ent, ref ItemToggledEvent args) | ||
{ | ||
var uid = ent.Owner; | ||
var draw = Comp<PowerCellDrawComponent>(uid); | ||
_cell.QueueUpdate((uid, draw)); | ||
_cell.SetDrawEnabled((uid, draw), args.Activated); | ||
} | ||
|
||
private void OnEmpty(Entity<ToggleCellDrawComponent> ent, ref PowerCellSlotEmptyEvent args) | ||
{ | ||
_toggle.TryDeactivate(ent.Owner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
- type: PowerCellDraw | ||
drawRate: 0 | ||
useRate: 20 | ||
- type: ToggleCellDraw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters