Add some map item code

no functions, just exploration
This commit is contained in:
Kurt 2020-04-02 08:08:05 -07:00
parent 9988e72182
commit e70d2b71d8
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace NHSE.Core
{
[StructLayout(LayoutKind.Sequential)]
public class MapItem : Item
{
public new const int SIZE = 0x10;
public ushort X1, X2, X3, X4;
public new static MapItem[] GetArray(byte[] data) => data.GetArray<MapItem>(SIZE);
public static byte[] SetArray(IReadOnlyList<MapItem> data) => data.SetArray(SIZE);
}
}

View File

@ -34,7 +34,7 @@ public Bitmap CreateFake(Item item, Font font, bool slash = false)
return bmp;
}
private static void DrawItemAt(Graphics gfx, Item item, Font font, int x1, int y1, int x2, int y2, bool slash = false)
public static void DrawItemAt(Graphics gfx, Item item, Font font, int x1, int y1, int x2, int y2, bool slash = false)
{
var color = GetItemColor(item);
using var brush = new SolidBrush(color);
@ -89,5 +89,22 @@ public static Color Blend(Color color, Color backColor, double amount)
}
private static readonly KnownColor[] Colors = (KnownColor[])Enum.GetValues(typeof(KnownColor));
public Bitmap GetItemArray(Item[] items, int height, Font f)
{
//var items = MapItem.GetArray(SAV.Main.Data.Slice(0x20191C, 0xA8000));
var width = items.Length / height;
var png = new Bitmap(width * Width, height * Height);
var gfx = Graphics.FromImage(png);
for (int i = 0; i < items.Length; i++)
{
var x = Height * (i / height);
var y = Width * (i % height);
DrawItemAt(gfx, items[i], f, x, y, x + Width - 1, y + Height - 1);
}
return png;
}
}
}

View File

@ -21,5 +21,13 @@ public void VillagerItemMarshal()
var bytes = item.ToBytesClass();
bytes.Length.Should().Be(VillagerItem.SIZE);
}
[Fact]
public void MapItemMarshal()
{
var item = new MapItem();
var bytes = item.ToBytesClass();
bytes.Length.Should().Be(MapItem.SIZE);
}
}
}