mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Adds directed event for when an entity's BodyType changes. (#1681)
Removes old Anchored C# event.
This commit is contained in:
committed by
GitHub
parent
aacf6522b4
commit
47ad07b3d2
@@ -103,6 +103,7 @@ namespace Robust.Shared.GameObjects
|
||||
return;
|
||||
|
||||
var oldAnchored = _bodyType == BodyType.Static;
|
||||
var oldType = _bodyType;
|
||||
_bodyType = value;
|
||||
|
||||
ResetMassData();
|
||||
@@ -126,9 +127,10 @@ namespace Robust.Shared.GameObjects
|
||||
|
||||
var anchored = value == BodyType.Static;
|
||||
|
||||
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new PhysicsBodyTypeChangedEvent(_bodyType, oldType), false);
|
||||
|
||||
if (oldAnchored != anchored)
|
||||
{
|
||||
AnchoredChanged?.Invoke();
|
||||
SendMessage(new AnchoredChangedMessage(Anchored));
|
||||
}
|
||||
}
|
||||
@@ -851,15 +853,11 @@ namespace Robust.Shared.GameObjects
|
||||
_bodyType = BodyType.Dynamic;
|
||||
}
|
||||
|
||||
AnchoredChanged?.Invoke();
|
||||
SendMessage(new AnchoredChangedMessage(Anchored));
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete("Use AnchoredChangedMessage instead")]
|
||||
public event Action? AnchoredChanged;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Predict
|
||||
{
|
||||
@@ -1296,4 +1294,31 @@ namespace Robust.Shared.GameObjects
|
||||
Anchored = anchored;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Directed event raised when an entity's physics BodyType changes.
|
||||
/// </summary>
|
||||
public class PhysicsBodyTypeChangedEvent : EntityEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// New BodyType of the entity.
|
||||
/// </summary>
|
||||
public BodyType New { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Old BodyType of the entity.
|
||||
/// </summary>
|
||||
public BodyType Old { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the body is "anchored".
|
||||
/// </summary>
|
||||
public bool Anchored => New == BodyType.Static;
|
||||
|
||||
public PhysicsBodyTypeChangedEvent(BodyType newType, BodyType oldType)
|
||||
{
|
||||
New = newType;
|
||||
Old = oldType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user