Files
RobustToolbox/Robust.Client/Placement/Modes/AlignWallProper.cs
Pieter-Jan Briers cdd3afaa4c Remove redundant custom math types (#6078)
Vector3, Vector4, Matrix4, and Quaternion are now gone. Use System.Numerics instead.

This commit is just replacing usages, cleaning up using declarations, and moving over the (couple) helpers that are actually important.
2025-07-23 01:15:27 +02:00

60 lines
1.6 KiB
C#

using System.Linq;
using System.Numerics;
using Robust.Shared.Map;
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[]
{
new(0f, 0.5f),
new(0.5f, 0f),
new(0, -0.5f),
new(-0.5f, 0f)
};
var closestNode = offsets
.Select(o => tileCoordinates.Offset(o))
.MinBy(node => node.TryDistance(pManager.EntityManager, MouseCoords, out var distance) ?
distance :
(float?) null);
MouseCoords = closestNode;
}
public override bool IsValidPosition(EntityCoordinates position)
{
if (pManager.CurrentPermission!.IsTile)
{
return false;
}
else if (!RangeCheck(position))
{
return false;
}
return true;
}
}
}