mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System.Linq;
|
|
using Robust.Shared.Map;
|
|
using Vector2 = Robust.Shared.Maths.Vector2;
|
|
|
|
namespace Robust.Client.Placement.Modes
|
|
{
|
|
/// <summary>
|
|
/// Snaps in edge on one axis, center in the other.
|
|
/// </summary>
|
|
public sealed class AlignWallProper : PlacementMode
|
|
{
|
|
public AlignWallProper(PlacementManager pMan) : base(pMan)
|
|
{
|
|
}
|
|
|
|
public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
|
|
{
|
|
MouseCoords = ScreenToCursorGrid(mouseScreen);
|
|
CurrentTile = GetTileRef(MouseCoords);
|
|
|
|
if (pManager.CurrentPermission!.IsTile)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var tileCoordinates = new EntityCoordinates(MouseCoords.EntityId, CurrentTile.GridIndices);
|
|
|
|
var offsets = new Vector2[]
|
|
{
|
|
(0f, 0.5f),
|
|
(0.5f, 0f),
|
|
(0, -0.5f),
|
|
(-0.5f, 0f)
|
|
};
|
|
|
|
var closestNode = offsets
|
|
.Select(o => tileCoordinates.Offset(o))
|
|
.OrderBy(node => node.TryDistance(pManager.EntityManager, MouseCoords, out var distance) ? distance : (float?) null)
|
|
.First();
|
|
|
|
MouseCoords = closestNode;
|
|
}
|
|
|
|
public override bool IsValidPosition(EntityCoordinates position)
|
|
{
|
|
if (pManager.CurrentPermission!.IsTile)
|
|
{
|
|
return false;
|
|
}
|
|
else if (!RangeCheck(position))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|