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>
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Robust.Shared.Map;
|
|
using Vector2 = Robust.Shared.Maths.Vector2;
|
|
|
|
namespace Robust.Client.Placement.Modes
|
|
{
|
|
public sealed class AlignWall : PlacementMode
|
|
{
|
|
public AlignWall(PlacementManager pMan) : base(pMan) { }
|
|
|
|
public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
|
|
{
|
|
MouseCoords = ScreenToCursorGrid(mouseScreen);
|
|
CurrentTile = GetTileRef(MouseCoords);
|
|
|
|
if (pManager.CurrentPermission!.IsTile)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var nodes = new List<Vector2>();
|
|
|
|
if (pManager.CurrentPrototype!.MountingPoints != null)
|
|
{
|
|
nodes.AddRange(
|
|
pManager.CurrentPrototype.MountingPoints.Select(
|
|
current => new Vector2(MouseCoords.X, CurrentTile.Y + current)));
|
|
}
|
|
else
|
|
{
|
|
nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 0.5f));
|
|
nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.0f));
|
|
nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.5f));
|
|
}
|
|
|
|
var closestNode = (from Vector2 node in nodes
|
|
orderby (node - MouseCoords.Position).LengthSquared ascending
|
|
select node).First();
|
|
|
|
MouseCoords = new EntityCoordinates(MouseCoords.EntityId,
|
|
closestNode + (pManager.PlacementOffset.X, pManager.PlacementOffset.Y));
|
|
}
|
|
|
|
public override bool IsValidPosition(EntityCoordinates position)
|
|
{
|
|
return !pManager.CurrentPermission!.IsTile && RangeCheck(position);
|
|
}
|
|
}
|
|
}
|