HexGrid: allow setting bounds via offset coordinate rectangle.
parent
4c0a2e7714
commit
1ba28ab06c
11
HexGrid.cs
11
HexGrid.cs
|
@ -7,7 +7,8 @@ using AxialCoordDirectionPair = System.Tuple<Godot.Vector2, Godot.Vector3>;
|
||||||
public class HexGrid : Resource
|
public class HexGrid : Resource
|
||||||
{
|
{
|
||||||
private readonly Vector2 _baseHexSize = new(1, Mathf.Sqrt(3) / 2);
|
private readonly Vector2 _baseHexSize = new(1, Mathf.Sqrt(3) / 2);
|
||||||
private Rect2 _boundsAxialCoords;
|
private Rect2 _boundsAxialCoords = new(-Vector2.Inf, Vector2.Inf);
|
||||||
|
private Rect2 _boundsOffsetCoords = new(-Vector2.Inf, Vector2.Inf);
|
||||||
private Vector2 _hexScale = new(1, 1);
|
private Vector2 _hexScale = new(1, 1);
|
||||||
private Vector2 _hexSize = new(1, Mathf.Sqrt(3) / 2);
|
private Vector2 _hexSize = new(1, Mathf.Sqrt(3) / 2);
|
||||||
private Transform2D _hexTransform;
|
private Transform2D _hexTransform;
|
||||||
|
@ -100,6 +101,12 @@ public class HexGrid : Resource
|
||||||
GetHexAtOffset(centerOffset + Vector2.One * size / 2));
|
GetHexAtOffset(centerOffset + Vector2.One * size / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetBoundsOffset(HexCell cellSouthEast, Vector2 size)
|
||||||
|
{
|
||||||
|
_boundsOffsetCoords = new Rect2(cellSouthEast.OffsetCoords, size);
|
||||||
|
_boundsAxialCoords = new Rect2(-Vector2.Inf, Vector2.Inf);
|
||||||
|
}
|
||||||
|
|
||||||
public void AddObstacle(Vector2 axialCoords, float cost = 0)
|
public void AddObstacle(Vector2 axialCoords, float cost = 0)
|
||||||
{
|
{
|
||||||
AddObstacle(new HexCell(axialCoords), cost);
|
AddObstacle(new HexCell(axialCoords), cost);
|
||||||
|
@ -140,6 +147,8 @@ public class HexGrid : Resource
|
||||||
{
|
{
|
||||||
if (!_boundsAxialCoords.HasPoint(axialCoords)) return 0;
|
if (!_boundsAxialCoords.HasPoint(axialCoords)) return 0;
|
||||||
|
|
||||||
|
if (!_boundsOffsetCoords.HasPoint(new HexCell(axialCoords).OffsetCoords)) return 0;
|
||||||
|
|
||||||
float value;
|
float value;
|
||||||
return Obstacles.TryGetValue(axialCoords, out value) ? value : PathCostDefault;
|
return Obstacles.TryGetValue(axialCoords, out value) ? value : PathCostDefault;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue