mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Added struct skeleton for EntityCoordinates. * Polish EntityCoordinates, add tests, add EntityCoordinates to Transforms * Doc cleanup * Remove useless code * Return offset 0 when you don't have a parent * Test for making sure EntityCoordinates for entities without parents have offset 0 * Use parent transform's GridId for GetGridId. * Adds various methods, checks and tests * Replace GridCoordinates with EntityCoordinates * EyeManager.WorldToScreen fix * Address reviews * Fix za buildo * Fix one transform test * Fix the remaining tests * Remove duplicate * Remove another merge duplicate * Fix property * Rename most usages of GridCoordinates to EntityCoordinates. * Add WithEntityId method to EntityCoordinates. * Fix EntityCoordinates usage in GetEntitiesInRange * Remove cursed IMapGrid method, change naming. * Makes GridTileLookupSystem use EntityCoordinates Co-authored-by: Acruid <shatter66@gmail.com> Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
61 lines
2.0 KiB
C#
61 lines
2.0 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 class AlignWall : PlacementMode
|
|
{
|
|
public AlignWall(PlacementManager pMan) : base(pMan) { }
|
|
|
|
public override void AlignPlacementMode(ScreenCoordinates mouseScreen)
|
|
{
|
|
MouseCoords = ScreenToCursorGrid(mouseScreen);
|
|
var gridId = MouseCoords.GetGridId(pManager.EntityManager);
|
|
CurrentTile = pManager.MapManager.GetGrid(gridId).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));
|
|
}
|
|
|
|
Vector2 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)
|
|
{
|
|
if (pManager.CurrentPermission!.IsTile)
|
|
{
|
|
return false;
|
|
}
|
|
else if (!RangeCheck(position))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|