-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor FabricateCandySystem Into Its Generic Equivalent (#566)
# Description Refactors the nyano shitcode responsible for allowing borgs to dispense candies into a more generic variant, that allows to define what action dispenses what entity, and allowing an arbitrary number of such actions on an entity. Requested by @DangerRevolution <details><summary><h1>Media</h1></summary><p> https://github.com/user-attachments/assets/b4d643e2-c9b0-4367-8b9c-2d0cd4a228b9 </p></details> # Changelog No cl no fun --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com>
- Loading branch information
1 parent
fe84704
commit cf0498e
Showing
9 changed files
with
112 additions
and
75 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
Content.Server/Abilities/Borgs/FabricateActionsComponent.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,19 @@ | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.Abilities.Borgs; | ||
|
||
[RegisterComponent] | ||
public sealed partial class FabricateActionsComponent : Component | ||
{ | ||
/// <summary> | ||
/// IDs of fabrication actions that the entity should receive with this component. | ||
/// </summary> | ||
[DataField] | ||
public List<ProtoId<EntityPrototype>> Actions = new(); | ||
|
||
/// <summary> | ||
/// Action entities added by this component. | ||
/// </summary> | ||
[DataField] | ||
public Dictionary<ProtoId<EntityPrototype>, EntityUid> ActionEntities = new(); | ||
} |
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,53 @@ | ||
using Content.Shared.ActionBlocker; | ||
using Content.Shared.Actions; | ||
using Content.Shared.Actions.Events; | ||
|
||
namespace Content.Server.Abilities.Borgs; | ||
|
||
public sealed partial class FabricateActionsSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; | ||
[Dependency] private readonly SharedActionsSystem _actions = default!; | ||
|
||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<FabricateActionsComponent, ComponentStartup>(OnStartup); | ||
SubscribeLocalEvent<FabricateActionsComponent, ComponentShutdown>(OnShutdown); | ||
SubscribeLocalEvent<FabricateActionsComponent, FabricateActionEvent>(OnFabricate); | ||
} | ||
|
||
|
||
private void OnStartup(Entity<FabricateActionsComponent> entity, ref ComponentStartup args) | ||
{ | ||
foreach (var actionId in entity.Comp.Actions) | ||
{ | ||
EntityUid? actionEntity = null; | ||
if (_actions.AddAction(entity, ref actionEntity, actionId)) | ||
entity.Comp.ActionEntities[actionId] = actionEntity.Value; | ||
} | ||
} | ||
|
||
private void OnShutdown(Entity<FabricateActionsComponent> entity, ref ComponentShutdown args) | ||
{ | ||
foreach (var (actionId, actionEntity) in entity.Comp.ActionEntities) | ||
{ | ||
if (actionEntity is not { Valid: true }) | ||
continue; | ||
|
||
_actions.RemoveAction(entity, actionEntity); | ||
entity.Comp.ActionEntities.Remove(actionId); | ||
} | ||
} | ||
|
||
private void OnFabricate(Entity<FabricateActionsComponent> entity, ref FabricateActionEvent args) | ||
{ | ||
if (args.Handled || !_actionBlocker.CanConsciouslyPerformAction(entity)) | ||
return; | ||
|
||
SpawnNextToOrDrop(args.Fabrication, entity); | ||
args.Handled = true; | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
Content.Server/Nyanotrasen/Abilities/Borgs/FabricateCandyComponent.cs
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
Content.Server/Nyanotrasen/Abilities/Borgs/FabricateCandySystem.cs
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Shared.Actions.Events; | ||
|
||
public sealed partial class FabricateActionEvent : InstantActionEvent | ||
{ | ||
[DataField(required: true)] | ||
public ProtoId<EntityPrototype> Fabrication; | ||
} |
This file was deleted.
Oops, something went wrong.
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