Add mechanism events when being added/removed to/from body/parts (#2271)

* Add mechanism events when added/removed to/from body/parts

* Change old usages

* Add TODO
This commit is contained in:
DrSmugleaf
2020-10-16 14:42:33 +02:00
committed by GitHub
parent 435fb2630e
commit bd30a73026
8 changed files with 257 additions and 79 deletions

View File

@@ -43,18 +43,19 @@ namespace Content.Shared.GameObjects.Components.Body.Part
var old = _body;
_body = value;
if (old != null)
{
foreach (var mechanism in _mechanisms)
{
mechanism.RemovedFromBody(old);
}
}
if (value != null)
{
foreach (var mechanism in _mechanisms)
{
mechanism.OnBodyAdd(old, value);
}
}
else if (old != null)
{
foreach (var mechanism in _mechanisms)
{
mechanism.OnBodyRemove(old);
mechanism.AddedToBody();
}
}
}
@@ -113,6 +114,15 @@ namespace Content.Shared.GameObjects.Components.Body.Part
mechanism.Part = this;
SizeUsed += mechanism.Size;
if (Body == null)
{
mechanism.AddedToPart();
}
else
{
mechanism.AddedToPartInBody();
}
Dirty();
}
@@ -122,6 +132,15 @@ namespace Content.Shared.GameObjects.Components.Body.Part
mechanism.Part = null;
SizeUsed -= mechanism.Size;
if (Body == null)
{
mechanism.RemovedFromPart(this);
}
else
{
mechanism.RemovedFromPartInBody(Body, this);
}
Dirty();
}
@@ -305,7 +324,7 @@ namespace Content.Shared.GameObjects.Components.Body.Part
[Serializable, NetSerializable]
public class BodyPartComponentState : ComponentState
{
private List<IMechanism>? _mechanisms;
[NonSerialized] private List<IMechanism>? _mechanisms;
public readonly EntityUid[] MechanismIds;