-
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.
* cleanup of AddComponentSpecial * add RemoveComponentSpecial * require --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
- Loading branch information
1 parent
d0a2187
commit ed8bcb0
Showing
2 changed files
with
30 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,22 @@ | ||
using Content.Shared.Roles; | ||
using JetBrains.Annotations; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization.Manager; | ||
|
||
namespace Content.Server.Jobs | ||
{ | ||
[UsedImplicitly] | ||
public sealed partial class AddComponentSpecial : JobSpecial | ||
{ | ||
[DataField("components")] | ||
[AlwaysPushInheritance] | ||
public ComponentRegistry Components { get; private set; } = new(); | ||
namespace Content.Server.Jobs; | ||
|
||
public override void AfterEquip(EntityUid mob) | ||
{ | ||
// now its a registry of components, still throws i bet. | ||
// TODO: This is hot garbage and probably needs an engine change to not be a POS. | ||
var factory = IoCManager.Resolve<IComponentFactory>(); | ||
var entityManager = IoCManager.Resolve<IEntityManager>(); | ||
var serializationManager = IoCManager.Resolve<ISerializationManager>(); | ||
public sealed partial class AddComponentSpecial : JobSpecial | ||
{ | ||
[DataField(required: true)] | ||
public ComponentRegistry Components { get; private set; } = new(); | ||
|
||
foreach (var (name, data) in Components) | ||
{ | ||
var component = (Component) factory.GetComponent(name); | ||
/// <summary> | ||
/// If this is true then existing components will be removed and replaced with these ones. | ||
/// </summary> | ||
[DataField] | ||
public bool RemoveExisting = true; | ||
|
||
var temp = (object)component; | ||
serializationManager.CopyTo(data.Component, ref temp); | ||
entityManager.RemoveComponent(mob, temp!.GetType()); | ||
entityManager.AddComponent(mob, (Component)temp); | ||
} | ||
} | ||
public override void AfterEquip(EntityUid mob) | ||
{ | ||
var entMan = IoCManager.Resolve<IEntityManager>(); | ||
entMan.AddComponents(mob, Components, removeExisting: RemoveExisting); | ||
} | ||
} |
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,16 @@ | ||
using Content.Shared.Roles; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.Jobs; | ||
|
||
public sealed partial class RemoveComponentSpecial : JobSpecial | ||
{ | ||
[DataField(required: true)] | ||
public ComponentRegistry Components { get; private set; } = new(); | ||
|
||
public override void AfterEquip(EntityUid mob) | ||
{ | ||
var entMan = IoCManager.Resolve<IEntityManager>(); | ||
entMan.RemoveComponents(mob, Components); | ||
} | ||
} |