* Make the ComponentToggle remember what entity it gave components to * fix the null problem by just ignoring the null problem * Add documentation to the new datafield + removing the "= null" that is not necessary * small fixes and cleaning the code * whitespace my beloved * wait, I dont need those lines, why did I add them?
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using Content.Shared.Item.ItemToggle.Components;
|
|
|
|
namespace Content.Shared.Item.ItemToggle;
|
|
|
|
/// <summary>
|
|
/// Handles <see cref="ComponentTogglerComponent"/> component manipulation.
|
|
/// </summary>
|
|
public sealed class ComponentTogglerSystem : EntitySystem
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ComponentTogglerComponent, ItemToggledEvent>(OnToggled);
|
|
}
|
|
|
|
private void OnToggled(Entity<ComponentTogglerComponent> ent, ref ItemToggledEvent args)
|
|
{
|
|
if (args.Activated)
|
|
{
|
|
var target = ent.Comp.Parent ? Transform(ent).ParentUid : ent.Owner;
|
|
|
|
if (TerminatingOrDeleted(target))
|
|
return;
|
|
|
|
ent.Comp.Target = target;
|
|
|
|
EntityManager.AddComponents(target, ent.Comp.Components);
|
|
}
|
|
else
|
|
{
|
|
if (ent.Comp.Target == null)
|
|
return;
|
|
|
|
if (TerminatingOrDeleted(ent.Comp.Target.Value))
|
|
return;
|
|
|
|
EntityManager.RemoveComponents(ent.Comp.Target.Value, ent.Comp.RemoveComponents ?? ent.Comp.Components);
|
|
}
|
|
}
|
|
}
|