Fix the component toggler (#37309)
* 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?
This commit is contained in:
@@ -16,13 +16,26 @@ public sealed class ComponentTogglerSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnToggled(Entity<ComponentTogglerComponent> ent, ref ItemToggledEvent args)
|
private void OnToggled(Entity<ComponentTogglerComponent> ent, ref ItemToggledEvent args)
|
||||||
{
|
{
|
||||||
var target = ent.Comp.Parent ? Transform(ent).ParentUid : ent.Owner;
|
|
||||||
if (TerminatingOrDeleted(target))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (args.Activated)
|
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);
|
EntityManager.AddComponents(target, ent.Comp.Components);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
EntityManager.RemoveComponents(target, ent.Comp.RemoveComponents ?? ent.Comp.Components);
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,10 @@ public sealed partial class ComponentTogglerComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public bool Parent;
|
public bool Parent;
|
||||||
|
|
||||||
|
// <summary>
|
||||||
|
// It holds the entity that the component gave the component to, so it can remove from it even if it changes parent.
|
||||||
|
// </summary>
|
||||||
|
[DataField]
|
||||||
|
public EntityUid? Target;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user