Rename enum TileShape to MapGridType

This commit is contained in:
Pavel Penev
2015-10-01 00:48:01 +03:00
parent 06ba175fde
commit bb3aea338a
17 changed files with 63 additions and 71 deletions

View File

@@ -20,7 +20,7 @@ namespace OpenRA
{
public readonly Size Size;
readonly Rectangle bounds;
public readonly TileShape Shape;
public readonly MapGridType GridType;
public event Action<CPos> CellEntryChanged = null;
readonly T[] entries;
@@ -28,28 +28,28 @@ namespace OpenRA
public CellLayer(Map map)
: this(map.Grid.Type, new Size(map.MapSize.X, map.MapSize.Y)) { }
public CellLayer(TileShape shape, Size size)
public CellLayer(MapGridType gridType, Size size)
{
Size = size;
bounds = new Rectangle(0, 0, Size.Width, Size.Height);
Shape = shape;
GridType = gridType;
entries = new T[size.Width * size.Height];
}
public void CopyValuesFrom(CellLayer<T> anotherLayer)
{
if (Size != anotherLayer.Size || Shape != anotherLayer.Shape)
if (Size != anotherLayer.Size || GridType != anotherLayer.GridType)
throw new ArgumentException(
"layers must have a matching size and shape.", "anotherLayer");
"layers must have a matching size and shape (grid type).", "anotherLayer");
if (CellEntryChanged != null)
throw new InvalidOperationException(
"Cannot copy values when there are listeners attached to the CellEntryChanged event.");
Array.Copy(anotherLayer.entries, entries, entries.Length);
}
public static CellLayer<T> CreateInstance(Func<MPos, T> initialCellValueFactory, Size size, TileShape tileShape)
public static CellLayer<T> CreateInstance(Func<MPos, T> initialCellValueFactory, Size size, MapGridType mapGridType)
{
var cellLayer = new CellLayer<T>(tileShape, size);
var cellLayer = new CellLayer<T>(mapGridType, size);
for (var v = 0; v < size.Height; v++)
{
for (var u = 0; u < size.Width; u++)
@@ -65,7 +65,7 @@ namespace OpenRA
// Resolve an array index from cell coordinates
int Index(CPos cell)
{
return Index(cell.ToMPos(Shape));
return Index(cell.ToMPos(GridType));
}
// Resolve an array index from map coordinates
@@ -104,7 +104,7 @@ namespace OpenRA
entries[Index(uv)] = value;
if (CellEntryChanged != null)
CellEntryChanged(uv.ToCPos(Shape));
CellEntryChanged(uv.ToCPos(GridType));
}
}
@@ -130,10 +130,10 @@ namespace OpenRA
// .ToMPos() returns the same result if the X and Y coordinates
// are switched. X < Y is invalid in the Diamond coordinate system,
// so we pre-filter these to avoid returning the wrong result
if (Shape == TileShape.Diamond && cell.X < cell.Y)
if (GridType == MapGridType.Diamond && cell.X < cell.Y)
return false;
return Contains(cell.ToMPos(Shape));
return Contains(cell.ToMPos(GridType));
}
public bool Contains(MPos uv)
@@ -143,7 +143,7 @@ namespace OpenRA
public CPos Clamp(CPos uv)
{
return Clamp(uv.ToMPos(Shape)).ToCPos(Shape);
return Clamp(uv.ToMPos(GridType)).ToCPos(GridType);
}
public MPos Clamp(MPos uv)
@@ -158,7 +158,7 @@ namespace OpenRA
/// <summary>Create a new layer by resizing another layer. New cells are filled with defaultValue.</summary>
public static CellLayer<T> Resize<T>(CellLayer<T> layer, Size newSize, T defaultValue)
{
var result = new CellLayer<T>(layer.Shape, newSize);
var result = new CellLayer<T>(layer.GridType, newSize);
var width = Math.Min(layer.Size.Width, newSize.Width);
var height = Math.Min(layer.Size.Height, newSize.Height);