Refactoring

move files, abstract some logic for later reuse
This commit is contained in:
Kurt 2020-05-11 22:14:27 -07:00
parent 46d4f4e8c1
commit 60faecdc69
18 changed files with 321 additions and 270 deletions

View File

@ -1,226 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace NHSE.Core
{
public class FieldItemLayer : MapGrid
{
public readonly Item[] Tiles;
public FieldItemLayer(Item[] tiles) : base(32, 32)
{
Tiles = tiles;
Debug.Assert(MapTileCount == tiles.Length);
}
public Item GetTile(int x, int y) => this[GetTileIndex(x, y)];
public Item GetTile(int acreX, int acreY, int gridX, int gridY) => this[GetTileIndex(acreX, acreY, gridX, gridY)];
public Item GetAcreTile(int acreIndex, int tileIndex) => this[GetAcreTileIndex(acreIndex, tileIndex)];
public Item this[int index]
{
get => Tiles[index];
set => Tiles[index] = value;
}
public byte[] DumpAcre(int acre)
{
int count = AcreTileCount;
var result = new byte[Item.SIZE * count];
for (int i = 0; i < count; i++)
{
var tile = GetAcreTile(acre, i);
var bytes = tile.ToBytesClass();
bytes.CopyTo(result, i * Item.SIZE);
}
return result;
}
public byte[] DumpAllAcres()
{
var result = new byte[Tiles.Length * Item.SIZE];
for (int i = 0; i < Tiles.Length; i++)
Tiles[i].ToBytesClass().CopyTo(result, i * Item.SIZE);
return result;
}
public void ImportAllAcres(byte[] data)
{
var tiles = Item.GetArray(data);
for (int i = 0; i < tiles.Length; i++)
Tiles[i].CopyFrom(tiles[i]);
}
public void ImportAcre(int acre, byte[] data)
{
int count = AcreTileCount;
var tiles = Item.GetArray(data);
for (int i = 0; i < count; i++)
{
var tile = GetAcreTile(acre, i);
tile.CopyFrom(tiles[i]);
}
}
public int ClearFieldPlanted(Func<FieldItemKind, bool> criteria) => ClearFieldPlanted(0, 0, MapWidth, MapHeight, criteria);
public int RemoveAll(Func<Item, bool> criteria) => RemoveAll(0, 0, MapWidth, MapHeight, criteria);
public int RemoveAll(HashSet<ushort> items) => RemoveAll(0, 0, MapWidth, MapHeight, z => items.Contains(z.DisplayItemId));
public int RemoveAll(ushort item) => RemoveAll(0, 0, MapWidth, MapHeight, z => z.DisplayItemId == item);
public int ClearFieldPlanted(int xmin, int ymin, int width, int height, Func<FieldItemKind, bool> criteria)
{
int count = 0;
var fi = FieldItemList.Items;
for (int x = xmin; x < xmin + width; x++)
{
for (int y = ymin; y < ymin + height; y++)
{
var t = GetTile(x, y);
var disp = t.DisplayItemId;
if (!fi.TryGetValue(disp, out var val))
continue;
if (!criteria(val.Kind))
continue;
t.Delete();
count++;
}
}
return count;
}
public int RemoveAll(int xmin, int ymin, int width, int height, Func<Item, bool> criteria)
{
int count = 0;
for (int x = xmin; x < xmin + width; x++)
{
for (int y = ymin; y < ymin + height; y++)
{
var t = GetTile(x, y);
if (!criteria(t))
continue;
t.Delete();
count++;
}
}
return count;
}
public int RemoveAllHoles() => ClearFieldPlanted(z => z == FieldItemKind.UnitIconHole);
public int RemoveAllWeeds() => ClearFieldPlanted(z => z.IsWeed());
public int RemoveAllPlants() => ClearFieldPlanted(z => z.IsPlant());
public int RemoveAllFences() => ClearFieldPlanted(z => z.IsFence());
public int RemoveAllObjects() => ClearFieldPlanted(_ => true);
public int RemoveAll() => RemoveAll(_ => true);
public int RemoveAllHoles(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z == FieldItemKind.UnitIconHole);
public int RemoveAllWeeds(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsWeed());
public int RemoveAllPlants(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsPlant());
public int RemoveAllFences(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsFence());
public int RemoveAllFlowers(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsFlower());
public int RemoveAllObjects(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, _ => true);
public int RemoveAll(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, _ => true);
public int RemoveAllShells(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, z => GameLists.Shells.Contains(z.DisplayItemId));
public int RemoveAllBranches(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, z => z.DisplayItemId == 2500);
public int RemoveAllPlacedItems(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width,
height, z => z.DisplayItemId != Item.NONE && !FieldItemList.Items.ContainsKey(z.DisplayItemId));
public void DeleteExtensionTiles(Item tile, in int x, in int y)
{
GetTileWidthHeight(tile, x, y, out var w, out var h);
for (int ix = 0; ix < w; ix++)
{
for (int iy = 0; iy < h; iy++)
{
if (iy == 0 && ix == 0)
continue;
var t = GetTile(x + ix, y + iy);
t.Delete();
}
}
}
public void SetExtensionTiles(Item tile, in int x, in int y)
{
GetTileWidthHeight(tile, x, y, out var w, out var h);
for (byte ix = 0; ix < w; ix++)
{
for (byte iy = 0; iy < h; iy++)
{
if (iy == 0 && ix == 0)
continue;
var t = GetTile(x + ix, y + iy);
t.SetAsExtension(tile, ix, iy);
}
}
}
private void GetTileWidthHeight(Item tile, int x, int y, out int w, out int h)
{
var type = ItemInfo.GetItemSize(tile);
w = type.GetWidth();
h = type.GetHeight();
// Rotation
if ((tile.Rotation & 1) == 1)
{
var tmp = w;
w = h;
h = tmp;
}
// Clamp to grid bounds
if (x + w - 1 >= MapWidth)
w = MapWidth - x;
if (y + h - 1 >= MapHeight)
h = MapHeight - y;
}
/// <summary>
/// Checks if writing the <see cref="tile"/> at the specified <see cref="x"/> and <see cref="y"/> coordinates will overlap with any existing tiles.
/// </summary>
/// <returns>True if any tile will be overwritten, false if nothing is there.</returns>
public FieldItemPermission IsOccupied(Item tile, in int x, in int y)
{
var type = ItemInfo.GetItemSize(tile);
var w = type.GetWidth();
var h = type.GetHeight();
if (x + w - 1 >= MapWidth)
return FieldItemPermission.OutOfBounds;
if (y + h - 1 >= MapHeight)
return FieldItemPermission.OutOfBounds;
if ((tile.Rotation & 1) == 1)
{
var tmp = w;
w = h;
h = tmp;
}
for (byte ix = 0; ix < w; ix++)
{
for (byte iy = 0; iy < h; iy++)
{
var t = GetTile(x + ix, y + iy);
if (!t.IsNone)
return FieldItemPermission.Collision;
}
}
return FieldItemPermission.NoCollision;
}
}
public enum FieldItemPermission
{
NoCollision,
Collision,
OutOfBounds,
}
}

View File

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
namespace NHSE.Core
{
public class FieldItemLayer : ItemLayer
{
public FieldItemLayer(Item[] tiles) : base(tiles, 32 * AcreWidth, 32 * AcreHeight, 32, 32)
{
}
public Item GetTile(int acreX, int acreY, int gridX, int gridY) => this[GetTileIndex(acreX, acreY, gridX, gridY)];
public Item GetAcreTile(int acreIndex, int tileIndex) => this[GetAcreTileIndex(acreIndex, tileIndex)];
public byte[] DumpAcre(int acre)
{
int count = AcreTileCount;
var result = new byte[Item.SIZE * count];
for (int i = 0; i < count; i++)
{
var tile = GetAcreTile(acre, i);
var bytes = tile.ToBytesClass();
bytes.CopyTo(result, i * Item.SIZE);
}
return result;
}
public void ImportAcre(int acre, byte[] data)
{
int count = AcreTileCount;
var tiles = Item.GetArray(data);
for (int i = 0; i < count; i++)
{
var tile = GetAcreTile(acre, i);
tile.CopyFrom(tiles[i]);
}
}
public int ClearFieldPlanted(Func<FieldItemKind, bool> criteria) => ClearFieldPlanted(0, 0, MapWidth, MapHeight, criteria);
public int RemoveAll(Func<Item, bool> criteria) => RemoveAll(0, 0, MapWidth, MapHeight, criteria);
public int RemoveAll(HashSet<ushort> items) => RemoveAll(0, 0, MapWidth, MapHeight, z => items.Contains(z.DisplayItemId));
public int RemoveAll(ushort item) => RemoveAll(0, 0, MapWidth, MapHeight, z => z.DisplayItemId == item);
public int ClearFieldPlanted(int xmin, int ymin, int width, int height, Func<FieldItemKind, bool> criteria)
{
int count = 0;
var fi = FieldItemList.Items;
for (int x = xmin; x < xmin + width; x++)
{
for (int y = ymin; y < ymin + height; y++)
{
var t = GetTile(x, y);
var disp = t.DisplayItemId;
if (!fi.TryGetValue(disp, out var val))
continue;
if (!criteria(val.Kind))
continue;
t.Delete();
count++;
}
}
return count;
}
public int RemoveAllHoles(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z == FieldItemKind.UnitIconHole);
public int RemoveAllWeeds(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsWeed());
public int RemoveAllPlants(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsPlant());
public int RemoveAllFences(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsFence());
public int RemoveAllFlowers(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, z => z.IsFlower());
public int RemoveAllObjects(int xmin, int ymin, int width, int height) => ClearFieldPlanted(xmin, ymin, width, height, _ => true);
public int RemoveAll(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, _ => true);
public int RemoveAllShells(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, z => GameLists.Shells.Contains(z.DisplayItemId));
public int RemoveAllBranches(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width, height, z => z.DisplayItemId == 2500);
public int RemoveAllPlacedItems(int xmin, int ymin, int width, int height) => RemoveAll(xmin, ymin, width,
height, z => z.DisplayItemId != Item.NONE && !FieldItemList.Items.ContainsKey(z.DisplayItemId));
}
}

View File

@ -0,0 +1,146 @@
using System;
using System.Diagnostics;
namespace NHSE.Core
{
public abstract class ItemLayer : MapGrid
{
public readonly Item[] Tiles;
protected ItemLayer(Item[] tiles, int w, int h) : this(tiles, w, h, w, h) { }
protected ItemLayer(Item[] tiles, int w, int h, int gw, int gh) : base(gw, gh, w, h)
{
Tiles = tiles;
Debug.Assert(MaxWidth * MaxHeight == tiles.Length);
}
public Item GetTile(int x, int y) => this[GetTileIndex(x, y)];
public Item this[int index]
{
get => Tiles[index];
set => Tiles[index] = value;
}
public byte[] DumpAll()
{
var result = new byte[Tiles.Length * Item.SIZE];
for (int i = 0; i < Tiles.Length; i++)
Tiles[i].ToBytesClass().CopyTo(result, i * Item.SIZE);
return result;
}
public void ImportAll(byte[] data)
{
var tiles = Item.GetArray(data);
for (int i = 0; i < tiles.Length; i++)
Tiles[i].CopyFrom(tiles[i]);
}
public int RemoveAll(int xmin, int ymin, int width, int height, Func<Item, bool> criteria)
{
int count = 0;
for (int x = xmin; x < xmin + width; x++)
{
for (int y = ymin; y < ymin + height; y++)
{
var t = GetTile(x, y);
if (!criteria(t))
continue;
t.Delete();
count++;
}
}
return count;
}
public void DeleteExtensionTiles(Item tile, in int x, in int y)
{
GetTileWidthHeight(tile, x, y, out var w, out var h);
for (int ix = 0; ix < w; ix++)
{
for (int iy = 0; iy < h; iy++)
{
if (iy == 0 && ix == 0)
continue;
var t = GetTile(x + ix, y + iy);
t.Delete();
}
}
}
public void SetExtensionTiles(Item tile, in int x, in int y)
{
GetTileWidthHeight(tile, x, y, out var w, out var h);
for (byte ix = 0; ix < w; ix++)
{
for (byte iy = 0; iy < h; iy++)
{
if (iy == 0 && ix == 0)
continue;
var t = GetTile(x + ix, y + iy);
t.SetAsExtension(tile, ix, iy);
}
}
}
private void GetTileWidthHeight(Item tile, int x, int y, out int w, out int h)
{
var type = ItemInfo.GetItemSize(tile);
w = type.GetWidth();
h = type.GetHeight();
// Rotation
if ((tile.Rotation & 1) == 1)
{
var tmp = w;
w = h;
h = tmp;
}
// Clamp to grid bounds
if (x + w - 1 >= MaxWidth)
w = MaxWidth - x;
if (y + h - 1 >= MaxHeight)
h = MaxHeight - y;
}
/// <summary>
/// Checks if writing the <see cref="tile"/> at the specified <see cref="x"/> and <see cref="y"/> coordinates will overlap with any existing tiles.
/// </summary>
/// <returns>True if any tile will be overwritten, false if nothing is there.</returns>
public PlacedItemPermission IsOccupied(Item tile, in int x, in int y)
{
var type = ItemInfo.GetItemSize(tile);
var w = type.GetWidth();
var h = type.GetHeight();
if (x + w - 1 >= MaxWidth)
return PlacedItemPermission.OutOfBounds;
if (y + h - 1 >= MaxHeight)
return PlacedItemPermission.OutOfBounds;
if ((tile.Rotation & 1) == 1)
{
var tmp = w;
w = h;
h = tmp;
}
for (byte ix = 0; ix < w; ix++)
{
for (byte iy = 0; iy < h; iy++)
{
var t = GetTile(x + ix, y + iy);
if (!t.IsNone)
return PlacedItemPermission.Collision;
}
}
return PlacedItemPermission.NoCollision;
}
}
}

View File

@ -0,0 +1,33 @@
using System.Collections.Generic;
namespace NHSE.Core
{
public class RoomItemLayer : ItemLayer
{
public const int SIZE = Width * Height * Item.SIZE;
private const int Width = 20;
private const int Height = 20;
public RoomItemLayer(byte[] data) : this(Item.GetArray(data)) { }
public RoomItemLayer(Item[] tiles) : base(tiles, Width, Height) { }
public static RoomItemLayer[] GetArray(byte[] data)
{
var result = new RoomItemLayer[data.Length / SIZE];
for (int i = 0; i < result.Length; i++)
{
var slice = data.Slice(i * SIZE, SIZE);
result[i] = new RoomItemLayer(slice);
}
return result;
}
public static byte[] SetArray(IReadOnlyList<RoomItemLayer> data)
{
var result = new byte[data.Count * SIZE];
for (int i = 0; i < data.Count; i++)
data[i].DumpAll().CopyTo(result, i * SIZE);
return result;
}
}
}

View File

@ -2,12 +2,12 @@
namespace NHSE.Core
{
public class TerrainManager : MapGrid
public class TerrainLayer : MapGrid
{
public readonly TerrainTile[] Tiles;
public readonly byte[] BaseAcres;
public TerrainManager(TerrainTile[] tiles, byte[] acres) : base(16, 16)
public TerrainLayer(TerrainTile[] tiles, byte[] acres) : base(16, 16, AcreWidth * 16, AcreHeight * 16)
{
BaseAcres = acres;
Tiles = tiles;
@ -24,7 +24,7 @@ public TerrainManager(TerrainTile[] tiles, byte[] acres) : base(16, 16)
set => Tiles[index] = value;
}
public byte[] DumpAllAcres()
public byte[] DumpAll()
{
var result = new byte[Tiles.Length * TerrainTile.SIZE];
for (int i = 0; i < Tiles.Length; i++)
@ -45,7 +45,7 @@ public byte[] DumpAcre(int acre)
return result;
}
public void ImportAllAcres(byte[] data)
public void ImportAll(byte[] data)
{
var tiles = TerrainTile.GetArray(data);
for (int i = 0; i < tiles.Length; i++)

View File

@ -9,14 +9,18 @@ public abstract class MapGrid
{
public static readonly AcreCoordinate[] Acres = AcreCoordinate.GetGrid(AcreWidth, AcreHeight);
protected MapGrid(int gw, int gh)
protected MapGrid(int gw, int gh, int mw, int mh)
{
GridWidth = gw;
GridHeight = gh;
MaxWidth = mw;
MaxHeight = mh;
}
public readonly int GridWidth;
public readonly int GridHeight;
public readonly int MaxWidth;
public readonly int MaxHeight;
public const int AcreWidth = 7;
public const int AcreHeight = 6;
@ -30,7 +34,7 @@ protected MapGrid(int gw, int gh)
public const int MapTileCount16x16 = 16 * 16 * AcreCount;
public const int MapTileCount32x32 = 32 * 32 * AcreCount;
protected int GetTileIndex(int x, int y) => (MapHeight * x) + y;
protected int GetTileIndex(int x, int y) => (MaxHeight * x) + y;
protected int GetTileIndex(int acreX, int acreY, int gridX, int gridY)
{
@ -74,5 +78,11 @@ public void GetViewAnchorCoordinates(int acre, out int x, out int y)
x = (acre % AcreWidth) * GridWidth;
y = (acre / AcreWidth) * GridHeight;
}
public void ClampCoordinates(ref int x, ref int y)
{
x = Math.Max(0, Math.Min(x, MapWidth - 1));
y = Math.Max(0, Math.Min(y, MapHeight - 1));
}
}
}

View File

@ -0,0 +1,9 @@
namespace NHSE.Core
{
public enum PlacedItemPermission
{
NoCollision,
Collision,
OutOfBounds,
}
}

View File

@ -18,7 +18,7 @@ public MapManager(MainSave sav) : base(sav)
public class MapTerrainStructure
{
public readonly TerrainManager Terrain;
public readonly TerrainLayer Terrain;
public readonly IReadOnlyList<Building> Buildings;
public uint PlazaX { get; set; }
@ -26,7 +26,7 @@ public class MapTerrainStructure
public MapTerrainStructure(MainSave sav)
{
Terrain = new TerrainManager(sav.GetTerrainTiles(), sav.GetAcreBytes());
Terrain = new TerrainLayer(sav.GetTerrainTiles(), sav.GetAcreBytes());
Buildings = sav.Buildings;
PlazaX = sav.EventPlazaLeftUpX;
PlazaY = sav.EventPlazaLeftUpZ;

View File

@ -3,12 +3,12 @@
namespace NHSE.Sprites
{
public static class FieldItemSpriteDrawer
public static class ItemLayerSprite
{
public static Bitmap GetBitmapItemLayer(FieldItemLayer layer)
public static Bitmap GetBitmapItemLayer(ItemLayer layer)
{
var items = layer.Tiles;
var height = layer.MapHeight;
var height = layer.MaxHeight;
var width = items.Length / height;
var bmpData = new int[width * height];
@ -31,7 +31,7 @@ private static void LoadBitmapLayer(Item[] items, int[] bmpData, int width, int
}
}
private static void LoadPixelsFromLayer(FieldItemLayer layer, int x0, int y0, int width, int[] bmpData)
private static void LoadPixelsFromLayer(ItemLayer layer, int x0, int y0, int width, int[] bmpData)
{
var stride = layer.GridWidth;
@ -49,7 +49,7 @@ private static void LoadPixelsFromLayer(FieldItemLayer layer, int x0, int y0, in
}
// non-allocation image generator
public static Bitmap GetBitmapItemLayerAcre(FieldItemLayer layer, int x0, int y0, int scale, int[] acre1, int[] acreScale, Bitmap dest, int transparency = -1)
public static Bitmap GetBitmapItemLayerViewGrid(ItemLayer layer, int x0, int y0, int scale, int[] acre1, int[] acreScale, Bitmap dest, int transparency = -1, int gridlineColor = 0)
{
var w = layer.GridWidth;
var h = layer.GridHeight;
@ -65,7 +65,6 @@ public static Bitmap GetBitmapItemLayerAcre(FieldItemLayer layer, int x0, int y0
DrawDirectionals(acreScale, layer, w, x0, y0, scale);
// Slap on a grid
const int gridlineColor = 0; // let the underlying image grid show instead
DrawGrid(acreScale, w, h, scale, gridlineColor);
// Return final data
@ -73,7 +72,7 @@ public static Bitmap GetBitmapItemLayerAcre(FieldItemLayer layer, int x0, int y0
return dest;
}
private static void DrawDirectionals(int[] data, FieldItemLayer layer, int w, int x0, int y0, int scale)
private static void DrawDirectionals(int[] data, ItemLayer layer, int w, int x0, int y0, int scale)
{
for (int x = x0; x < x0 + layer.GridWidth; x++)
{
@ -171,9 +170,9 @@ public static void DrawGrid(int[] data, int w, int h, int scale, int gridlineCol
}
}
public static Bitmap GetBitmapItemLayer(FieldItemLayer layer, int x, int y, int[] data, Bitmap dest, int transparency = -1)
public static Bitmap GetBitmapItemLayer(ItemLayer layer, int x, int y, int[] data, Bitmap dest, int transparency = -1)
{
LoadBitmapLayer(layer.Tiles, data, layer.MapWidth, layer.MapHeight);
LoadBitmapLayer(layer.Tiles, data, layer.MaxWidth, layer.MaxHeight);
if (transparency >> 24 != 0xFF)
ImageUtil.ClampAllTransparencyTo(data, transparency);
ImageUtil.SetBitmapData(dest, data);

View File

@ -1,9 +1,8 @@
using System;
using System.Drawing;
using NHSE.Core;
using NHSE.Sprites;
namespace NHSE.WinForms
namespace NHSE.Sprites
{
public sealed class MapViewer : MapView, IDisposable
{
@ -59,7 +58,7 @@ public Bitmap GetBackgroundTerrain(int index = -1)
private Bitmap GetLayerAcre(int topX, int topY, int t)
{
var layer = Map.CurrentLayer;
return FieldItemSpriteDrawer.GetBitmapItemLayerAcre(layer, topX, topY, AcreScale, PixelsItemAcre1, PixelsItemAcreX, ScaleAcre, t);
return ItemLayerSprite.GetBitmapItemLayerViewGrid(layer, topX, topY, AcreScale, PixelsItemAcre1, PixelsItemAcreX, ScaleAcre, t);
}
public Bitmap GetBackgroundAcre(Font f, byte tbuild, byte tterrain, int index = -1)
@ -69,7 +68,7 @@ public Bitmap GetBackgroundAcre(Font f, byte tbuild, byte tterrain, int index =
private Bitmap GetMapWithReticle(int topX, int topY, int t, FieldItemLayer layer)
{
return FieldItemSpriteDrawer.GetBitmapItemLayer(layer, topX, topY, PixelsItemMap, MapReticle, t);
return ItemLayerSprite.GetBitmapItemLayer(layer, topX, topY, PixelsItemMap, MapReticle, t);
}
}
}

View File

@ -17,7 +17,7 @@ public static class TerrainSprite
private const int PlazaWidth = 6 * 2;
private const int PlazaHeight = 5 * 2;
public static void CreateMap(TerrainManager mgr, int[] pixels)
public static void CreateMap(TerrainLayer mgr, int[] pixels)
{
int i = 0;
for (int y = 0; y < mgr.MapHeight; y++)
@ -29,7 +29,7 @@ public static void CreateMap(TerrainManager mgr, int[] pixels)
}
}
public static Bitmap CreateMap(TerrainManager mgr, int scale, int x, int y, int[] scale1, int[] scaleX, Bitmap map)
public static Bitmap CreateMap(TerrainLayer mgr, int scale, int x, int y, int[] scale1, int[] scaleX, Bitmap map)
{
CreateMap(mgr, scale1);
ImageUtil.ScalePixelImage(scale1, scaleX, map.Width, map.Height, scale);
@ -37,7 +37,7 @@ public static Bitmap CreateMap(TerrainManager mgr, int scale, int x, int y, int[
return DrawReticle(map, mgr, x, y, scale);
}
public static Bitmap CreateMap(TerrainManager mgr, int[] scale1, int[] scaleX, Bitmap map, int scale, int acreIndex = -1)
public static Bitmap CreateMap(TerrainLayer mgr, int[] scale1, int[] scaleX, Bitmap map, int scale, int acreIndex = -1)
{
CreateMap(mgr, scale1);
ImageUtil.ScalePixelImage(scale1, scaleX, map.Width, map.Height, scale);
@ -74,7 +74,7 @@ public static Bitmap GetMapWithBuildings(MapTerrainStructure m, Font? f, int[] s
return map;
}
private static void DrawPlaza(this Graphics gfx, TerrainManager g, ushort px, ushort py, int scale)
private static void DrawPlaza(this Graphics gfx, TerrainLayer g, ushort px, ushort py, int scale)
{
g.GetBuildingCoordinate(px, py, scale, out var x, out var y);
@ -84,7 +84,7 @@ private static void DrawPlaza(this Graphics gfx, TerrainManager g, ushort px, us
gfx.FillRectangle(Plaza, x, y, width, height);
}
private static void DrawBuildings(this Graphics gfx, TerrainManager g, IReadOnlyList<Building> buildings, Font? f, int scale, int index = -1)
private static void DrawBuildings(this Graphics gfx, TerrainLayer g, IReadOnlyList<Building> buildings, Font? f, int scale, int index = -1)
{
for (int i = 0; i < buildings.Count; i++)
{
@ -109,13 +109,13 @@ private static void DrawBuilding(Graphics gfx, Font? f, int scale, Brush pen, in
}
}
private static void SetAcreTerrainPixels(int x, int y, TerrainManager t, int[] data, int[] scaleX, int scale)
private static void SetAcreTerrainPixels(int x, int y, TerrainLayer t, int[] data, int[] scaleX, int scale)
{
GetAcre1(x, y, t, data);
ImageUtil.ScalePixelImage(data, scaleX, 16 * scale, 16 * scale, scale);
}
private static void GetAcre1(int topX, int topY, TerrainManager t, int[] data)
private static void GetAcre1(int topX, int topY, TerrainLayer t, int[] data)
{
int index = 0;
for (int y = 0; y < 16; y++)
@ -157,8 +157,8 @@ public static Bitmap GetAcre(MapView m, Font f, int[] scale1, int[] scaleX, Bitm
}
ImageUtil.GetBitmapData(acre, scaleX);
FieldItemSpriteDrawer.DrawGrid(scaleX, acre.Width, acre.Height, m.AcreScale, grid1);
FieldItemSpriteDrawer.DrawGrid(scaleX, acre.Width, acre.Height, m.TerrainScale, grid2);
ItemLayerSprite.DrawGrid(scaleX, acre.Width, acre.Height, m.AcreScale, grid1);
ItemLayerSprite.DrawGrid(scaleX, acre.Width, acre.Height, m.TerrainScale, grid2);
ImageUtil.SetBitmapData(acre, scaleX);
foreach (var b in buildings)
@ -176,7 +176,7 @@ public static Bitmap GetAcre(MapView m, Font f, int[] scale1, int[] scaleX, Bitm
return acre;
}
private static void DrawTerrainTileNames(int topX, int topY, Graphics gfx, TerrainManager t, Font f, int scale, byte transparency)
private static void DrawTerrainTileNames(int topX, int topY, Graphics gfx, TerrainLayer t, Font f, int scale, byte transparency)
{
var pen= transparency != byte.MaxValue ? new SolidBrush(Color.FromArgb(transparency, Color.Black)) : Tile;
@ -196,7 +196,7 @@ private static void DrawTerrainTileNames(int topX, int topY, Graphics gfx, Terra
}
}
private static void DrawAcrePlaza(this Graphics gfx, TerrainManager g, int topX, int topY, ushort px, ushort py, int scale, byte transparency)
private static void DrawAcrePlaza(this Graphics gfx, TerrainLayer g, int topX, int topY, ushort px, ushort py, int scale, byte transparency)
{
g.GetBuildingRelativeCoordinates(topX, topY, scale, px, py, out var x, out var y);

View File

@ -4,6 +4,7 @@
using System.Linq;
using System.Windows.Forms;
using NHSE.Core;
using NHSE.Sprites;
namespace NHSE.WinForms
{
@ -290,8 +291,8 @@ private void ViewTile(Item tile, int x, int y)
if (CHK_RedirectExtensionLoad.Checked && tile.IsExtension)
{
var l = Map.CurrentLayer;
var rx = Math.Max(0, Math.Min(l.MapWidth - 1, x - tile.ExtensionX));
var ry = Math.Max(0, Math.Min(l.MapHeight - 1, y - tile.ExtensionY));
var rx = Math.Max(0, Math.Min(l.MaxWidth - 1, x - tile.ExtensionX));
var ry = Math.Max(0, Math.Min(l.MaxHeight - 1, y - tile.ExtensionY));
var redir = l.GetTile(rx, ry);
if (redir.IsRoot && redir.ItemId == tile.ExtensionItemId)
tile = redir;
@ -322,8 +323,8 @@ private void SetTile(Item tile, int x, int y)
var permission = l.IsOccupied(pgt, x, y);
switch (permission)
{
case FieldItemPermission.OutOfBounds:
case FieldItemPermission.Collision when CHK_NoOverwrite.Checked:
case PlacedItemPermission.OutOfBounds:
case PlacedItemPermission.Collision when CHK_NoOverwrite.Checked:
System.Media.SystemSounds.Asterisk.Play();
return;
}

View File

@ -53,7 +53,7 @@ public static bool ImportToLayerAcreAll(FieldItemLayer layer)
}
var data = File.ReadAllBytes(path);
layer.ImportAllAcres(data);
layer.ImportAll(data);
return true;
}
@ -83,11 +83,11 @@ public static void DumpLayerAcreAll(FieldItemLayer layer)
return;
var path = sfd.FileName;
var data = layer.DumpAllAcres();
var data = layer.DumpAll();
File.WriteAllBytes(path, data);
}
public static bool ImportTerrainAcre(TerrainManager m, int acreIndex, string acre)
public static bool ImportTerrainAcre(TerrainLayer m, int acreIndex, string acre)
{
using var ofd = new OpenFileDialog
{
@ -112,7 +112,7 @@ public static bool ImportTerrainAcre(TerrainManager m, int acreIndex, string acr
return true;
}
public static bool ImportTerrainAll(TerrainManager m)
public static bool ImportTerrainAll(TerrainLayer m)
{
using var ofd = new OpenFileDialog
{
@ -133,11 +133,11 @@ public static bool ImportTerrainAll(TerrainManager m)
}
var data = File.ReadAllBytes(path);
m.ImportAllAcres(data);
m.ImportAll(data);
return true;
}
public static void DumpTerrainAcre(TerrainManager m, int acreIndex, string acre)
public static void DumpTerrainAcre(TerrainLayer m, int acreIndex, string acre)
{
using var sfd = new SaveFileDialog
{
@ -152,7 +152,7 @@ public static void DumpTerrainAcre(TerrainManager m, int acreIndex, string acre)
File.WriteAllBytes(path, data);
}
public static void DumpTerrainAll(TerrainManager m)
public static void DumpTerrainAll(TerrainLayer m)
{
using var sfd = new SaveFileDialog
{
@ -163,7 +163,7 @@ public static void DumpTerrainAll(TerrainManager m)
return;
var path = sfd.FileName;
var data = m.DumpAllAcres();
var data = m.DumpAll();
File.WriteAllBytes(path, data);
}