CellLayer TryGetValue. Return a value if within cell layer bounds.

This commit is contained in:
Sieds Aalberts
2022-06-30 12:27:55 +02:00
committed by Gustas
parent a5ea98ae35
commit e060d6eb05
2 changed files with 28 additions and 11 deletions

View File

@@ -98,6 +98,28 @@ namespace OpenRA
}
}
public bool TryGetValue(CPos cell, out T value)
{
// .ToMPos() returns the same result if the X and Y coordinates
// are switched. X < Y is invalid in the RectangularIsometric coordinate system,
// so we pre-filter these to avoid returning the wrong result
if (GridType == MapGridType.RectangularIsometric && cell.X < cell.Y)
{
value = default(T);
return false;
}
var uv = cell.ToMPos(GridType);
if (Bounds.Contains(uv.U, uv.V))
{
value = Entries[Index(uv)];
return true;
}
value = default(T);
return false;
}
public bool Contains(CPos cell)
{
// .ToMPos() returns the same result if the X and Y coordinates