mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Replace TransformComponent.OnMove with component message (#946)
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Robust.Shared.Enums
|
||||
{
|
||||
public class MoveEventArgs : EventArgs
|
||||
{
|
||||
public MoveEventArgs(GridCoordinates oldPos, GridCoordinates newPos)
|
||||
{
|
||||
OldPosition = oldPos;
|
||||
NewPosition = newPos;
|
||||
}
|
||||
|
||||
public GridCoordinates OldPosition { get; }
|
||||
public GridCoordinates NewPosition { get; }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -53,4 +54,16 @@ namespace Robust.Shared.GameObjects
|
||||
OldParent = oldParent;
|
||||
}
|
||||
}
|
||||
|
||||
public class MoveMessage : ComponentMessage
|
||||
{
|
||||
public MoveMessage(GridCoordinates oldPos, GridCoordinates newPos)
|
||||
{
|
||||
OldPosition = oldPos;
|
||||
NewPosition = newPos;
|
||||
}
|
||||
|
||||
public GridCoordinates OldPosition { get; }
|
||||
public GridCoordinates NewPosition { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
@@ -36,7 +37,6 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
Owner.Transform.OnMove += OnTransformMove;
|
||||
UpdatePosition();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
Owner.Transform.OnMove -= OnTransformMove;
|
||||
if (IsSet)
|
||||
{
|
||||
if (_mapManager.TryGetGrid(_lastGrid, out var grid))
|
||||
@@ -58,7 +57,15 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
}
|
||||
}
|
||||
|
||||
void OnTransformMove(object sender, object eventArgs) => UpdatePosition();
|
||||
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
||||
{
|
||||
base.HandleMessage(message, netChannel, component);
|
||||
|
||||
if (message is MoveMessage msg && Running)
|
||||
{
|
||||
UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
|
||||
@@ -40,9 +40,6 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
[Dependency] private readonly IEntityManager _entityManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<MoveEventArgs> OnMove;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Transform";
|
||||
|
||||
@@ -230,7 +227,7 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
if (Running)
|
||||
{
|
||||
RebuildMatrices();
|
||||
OnMove?.Invoke(this, new MoveEventArgs(GridPosition, value));
|
||||
Owner.SendMessage(this, new MoveMessage(GridPosition, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +270,7 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
Dirty();
|
||||
|
||||
RebuildMatrices();
|
||||
OnMove?.Invoke(this, new MoveEventArgs(GridPosition, new GridCoordinates(GetLocalPosition(), GridID)));
|
||||
Owner.SendMessage(this, new MoveMessage(GridPosition, new GridCoordinates(GetLocalPosition(), GridID)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +297,7 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
SetPosition(value);
|
||||
RebuildMatrices();
|
||||
Dirty();
|
||||
OnMove?.Invoke(this, new MoveEventArgs(oldPos, GridPosition));
|
||||
Owner.SendMessage(this, new MoveMessage(oldPos, GridPosition));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,7 +507,7 @@ namespace Robust.Shared.GameObjects.Components.Transform
|
||||
SetPosition(newState.LocalPosition);
|
||||
}
|
||||
|
||||
OnMove?.Invoke(this, new MoveEventArgs(oldPos, GridPosition));
|
||||
Owner.SendMessage(this, new MoveMessage(oldPos, GridPosition));
|
||||
rebuildMatrices = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,12 +59,6 @@ namespace Robust.Shared.Interfaces.GameObjects.Components
|
||||
/// </summary>
|
||||
Matrix3 InvWorldMatrix { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Event that gets invoked every time the position gets modified through properties such as <see cref="LocalRotation" />.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
event EventHandler<MoveEventArgs> OnMove;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the transform of the container of this object if it exists, can be nested several times.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user