-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic Clothing Equip Functions (#1407)
# Description This PR was originally going to be called "Psionic Refactor V3 Part 2, Items Of Power", but I began getting shakes and started vomiting when I saw the list of Components that make items do things when equipped, and I had a conniption about how much code there is constantly being repeated. So instead of this PR adding Items Of Power, I added a universal modular generic system for making clothing items do things when equipped and unequipped. Which hooks into the library of TraitFunctions that we've previously created. I also added a few "Inverse" versions of trait functions that can be used by these new clothing functions. <!-- # Changelog :cl: - add: Added a universal modular system for making clothing items DO things when equipped and unequipped. This will be used for "Psionic Artifacts" in conjunction with the Psionic Refactor V3. -->
- Loading branch information
Showing
5 changed files
with
111 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
using Content.Shared.Clothing.Components; | ||
using Content.Shared.Clothing.EntitySystems; | ||
using Content.Shared.Inventory.Events; | ||
using Robust.Shared.Serialization.Manager; | ||
|
||
namespace Content.Server.Clothing; | ||
|
||
public sealed class ServerClothingSystem : ClothingSystem | ||
{ | ||
[Dependency] private readonly IComponentFactory _componentFactory = default!; | ||
[Dependency] private readonly ISerializationManager _serializationManager = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<ClothingComponent, DidEquipEvent>(OnClothingEquipped); | ||
SubscribeLocalEvent<ClothingComponent, DidUnequipEvent>(OnClothingUnequipped); | ||
} | ||
|
||
private void OnClothingEquipped(EntityUid uid, ClothingComponent clothingComponent, DidEquipEvent args) | ||
{ | ||
// Yes, this is using the trait system functions. I'm not going to write an entire third function library to do this. | ||
// They're generic for a reason. | ||
foreach (var function in clothingComponent.OnEquipFunctions) | ||
function.OnPlayerSpawn(uid, _componentFactory, EntityManager, _serializationManager); | ||
} | ||
|
||
private void OnClothingUnequipped(EntityUid uid, ClothingComponent clothingComponent, DidUnequipEvent args) | ||
{ | ||
// Yes, this is using the trait system functions. I'm not going to write an entire third function library to do this. | ||
// They're generic for a reason. | ||
foreach (var function in clothingComponent.OnUnequipFunctions) | ||
function.OnPlayerSpawn(uid, _componentFactory, EntityManager, _serializationManager); | ||
} | ||
} |
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