mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-22 10:35:15 -05:00
Merge Field Item back into Item
Different means of expression for the 8 byte item structure's FreeParam Will be expanding the ItemEditor so that it has a checkmark to toggle Extension Item editing behavior. Removes IHeldItem as there's no need to abstract it.
This commit is contained in:
@@ -184,7 +184,7 @@ public void SetAcreBytes(byte[] data)
|
||||
public TerrainTile[] GetTerrainTiles() => TerrainTile.GetArray(Data.Slice(Offsets.LandMakingMap, MapGrid.MapTileCount16x16 * TerrainTile.SIZE));
|
||||
public void SetTerrainTiles(IReadOnlyList<TerrainTile> array) => TerrainTile.SetArray(array).CopyTo(Data, Offsets.LandMakingMap);
|
||||
|
||||
private const int FieldItemLayerSize = MapGrid.MapTileCount32x32 * FieldItem.SIZE;
|
||||
private const int FieldItemLayerSize = MapGrid.MapTileCount32x32 * Item.SIZE;
|
||||
private const int FieldItemFlagSize = MapGrid.MapTileCount32x32 / 8; // bitflags
|
||||
|
||||
private int FieldItemLayer1 => Offsets.FieldItem;
|
||||
@@ -192,11 +192,11 @@ public void SetAcreBytes(byte[] data)
|
||||
public int FieldItemFlag1 => Offsets.FieldItem + (FieldItemLayerSize * 2);
|
||||
public int FieldItemFlag2 => Offsets.FieldItem + (FieldItemLayerSize * 2) + FieldItemFlagSize;
|
||||
|
||||
public FieldItem[] GetFieldItemLayer1() => FieldItem.GetArray(Data.Slice(FieldItemLayer1, FieldItemLayerSize));
|
||||
public void SetFieldItemLayer1(IReadOnlyList<FieldItem> array) => FieldItem.SetArray(array).CopyTo(Data, FieldItemLayer1);
|
||||
public Item[] GetFieldItemLayer1() => Item.GetArray(Data.Slice(FieldItemLayer1, FieldItemLayerSize));
|
||||
public void SetFieldItemLayer1(IReadOnlyList<Item> array) => Item.SetArray(array).CopyTo(Data, FieldItemLayer1);
|
||||
|
||||
public FieldItem[] GetFieldItemLayer2() => FieldItem.GetArray(Data.Slice(FieldItemLayer2, FieldItemLayerSize));
|
||||
public void SetFieldItemLayer2(IReadOnlyList<FieldItem> array) => FieldItem.SetArray(array).CopyTo(Data, FieldItemLayer2);
|
||||
public Item[] GetFieldItemLayer2() => Item.GetArray(Data.Slice(FieldItemLayer2, FieldItemLayerSize));
|
||||
public void SetFieldItemLayer2(IReadOnlyList<Item> array) => Item.SetArray(array).CopyTo(Data, FieldItemLayer2);
|
||||
|
||||
public ushort OutsideFieldTemplateUniqueId
|
||||
{
|
||||
|
||||
@@ -102,17 +102,19 @@ public static string[] GetItemDisplayList(string[] items)
|
||||
return items;
|
||||
}
|
||||
|
||||
public string GetItemName(IHeldItem item)
|
||||
public string GetItemName(Item item)
|
||||
{
|
||||
var index = item.ItemId;
|
||||
if (index == Item.NONE)
|
||||
return itemlist[0];
|
||||
if (index == Item.EXTENSION)
|
||||
return GetItemName(item.ExtensionItemId);
|
||||
var kind = ItemInfo.GetItemKind(index);
|
||||
|
||||
if (kind == ItemKind.Kind_DIYRecipe || kind == ItemKind.Kind_MessageBottle)
|
||||
{
|
||||
var display = itemlistdisplay[index];
|
||||
var recipeID = item.Count;
|
||||
var recipeID = (ushort)item.FreeParam;
|
||||
var isKnown = RecipeList.Recipes.TryGetValue(recipeID, out var result);
|
||||
var makes = isKnown ? GetItemName(result) : recipeID.ToString("000");
|
||||
return $"{display} - {makes}";
|
||||
@@ -121,7 +123,7 @@ public string GetItemName(IHeldItem item)
|
||||
if (kind == ItemKind.Kind_FossilUnknown)
|
||||
{
|
||||
var display = itemlistdisplay[index];
|
||||
var fossilID = item.Count;
|
||||
var fossilID = (ushort)item.FreeParam;
|
||||
var fossilName = GetItemName(fossilID);
|
||||
return $"{display} - {fossilName}";
|
||||
}
|
||||
@@ -129,30 +131,18 @@ public string GetItemName(IHeldItem item)
|
||||
return GetItemName(index);
|
||||
}
|
||||
|
||||
public string GetItemName(FieldItem item)
|
||||
{
|
||||
var index = item.DisplayItemId;
|
||||
if (index == FieldItem.NONE)
|
||||
return itemlist[0];
|
||||
|
||||
var items = itemlistdisplay;
|
||||
if (index >= items.Length)
|
||||
{
|
||||
if (FieldItemList.Items.TryGetValue(index, out var val))
|
||||
return val.Name;
|
||||
return "???";
|
||||
}
|
||||
|
||||
if (item.IsRoot)
|
||||
return GetItemName((IHeldItem)item);
|
||||
return GetItemName(index);
|
||||
}
|
||||
|
||||
public string GetItemName(ushort index)
|
||||
{
|
||||
if (index >= itemlistdisplay.Length)
|
||||
return "???";
|
||||
return GetItemName60000(index);
|
||||
return itemlistdisplay[index];
|
||||
}
|
||||
|
||||
private static string GetItemName60000(ushort index)
|
||||
{
|
||||
if (FieldItemList.Items.TryGetValue(index, out var val))
|
||||
return val.Name;
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ namespace NHSE.Core
|
||||
{
|
||||
public class FieldItemLayer : MapGrid
|
||||
{
|
||||
public readonly FieldItem[] Tiles;
|
||||
public readonly Item[] Tiles;
|
||||
|
||||
public FieldItemLayer(FieldItem[] tiles) : base(32, 32)
|
||||
public FieldItemLayer(Item[] tiles) : base(32, 32)
|
||||
{
|
||||
Tiles = tiles;
|
||||
Debug.Assert(MapTileCount == tiles.Length);
|
||||
}
|
||||
|
||||
public FieldItem GetTile(int x, int y) => this[GetTileIndex(x, y)];
|
||||
public FieldItem GetTile(int acreX, int acreY, int gridX, int gridY) => this[GetTileIndex(acreX, acreY, gridX, gridY)];
|
||||
public FieldItem GetAcreTile(int acreIndex, int tileIndex) => this[GetAcreTileIndex(acreIndex, tileIndex)];
|
||||
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 FieldItem this[int index]
|
||||
public Item this[int index]
|
||||
{
|
||||
get => Tiles[index];
|
||||
set => Tiles[index] = value;
|
||||
@@ -27,27 +27,27 @@ public FieldItemLayer(FieldItem[] tiles) : base(32, 32)
|
||||
public byte[] DumpAcre(int acre)
|
||||
{
|
||||
int count = AcreTileCount;
|
||||
var result = new byte[FieldItem.SIZE * count];
|
||||
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 * FieldItem.SIZE);
|
||||
bytes.CopyTo(result, i * Item.SIZE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] DumpAllAcres()
|
||||
{
|
||||
var result = new byte[Tiles.Length * FieldItem.SIZE];
|
||||
var result = new byte[Tiles.Length * Item.SIZE];
|
||||
for (int i = 0; i < Tiles.Length; i++)
|
||||
Tiles[i].ToBytesClass().CopyTo(result, i * FieldItem.SIZE);
|
||||
Tiles[i].ToBytesClass().CopyTo(result, i * Item.SIZE);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void ImportAllAcres(byte[] data)
|
||||
{
|
||||
var tiles = FieldItem.GetArray(data);
|
||||
var tiles = Item.GetArray(data);
|
||||
for (int i = 0; i < tiles.Length; i++)
|
||||
Tiles[i].CopyFrom(tiles[i]);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public void ImportAllAcres(byte[] data)
|
||||
public void ImportAcre(int acre, byte[] data)
|
||||
{
|
||||
int count = AcreTileCount;
|
||||
var tiles = FieldItem.GetArray(data);
|
||||
var tiles = Item.GetArray(data);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var tile = GetAcreTile(acre, i);
|
||||
@@ -64,7 +64,7 @@ public void ImportAcre(int acre, byte[] data)
|
||||
}
|
||||
|
||||
public int ClearFieldPlanted(Func<FieldItemKind, bool> criteria) => ClearFieldPlanted(0, 0, MapWidth, MapHeight, criteria);
|
||||
public int RemoveAll(Func<FieldItem, bool> criteria) => RemoveAll(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);
|
||||
|
||||
@@ -91,7 +91,7 @@ public int ClearFieldPlanted(int xmin, int ymin, int width, int height, Func<Fie
|
||||
return count;
|
||||
}
|
||||
|
||||
public int RemoveAll(int xmin, int ymin, int width, int height, Func<FieldItem, bool> criteria)
|
||||
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++)
|
||||
@@ -126,9 +126,9 @@ public int RemoveAll(int xmin, int ymin, int width, int height, Func<FieldItem,
|
||||
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 != FieldItem.NONE && !FieldItemList.Items.ContainsKey(z.DisplayItemId));
|
||||
height, z => z.DisplayItemId != Item.NONE && !FieldItemList.Items.ContainsKey(z.DisplayItemId));
|
||||
|
||||
public void DeleteExtensionTiles(FieldItem tile, in int x, in int y)
|
||||
public void DeleteExtensionTiles(Item tile, in int x, in int y)
|
||||
{
|
||||
GetTileWidthHeight(tile, x, y, out var w, out var h);
|
||||
|
||||
@@ -144,7 +144,7 @@ public void DeleteExtensionTiles(FieldItem tile, in int x, in int y)
|
||||
}
|
||||
}
|
||||
|
||||
public void SetExtensionTiles(FieldItem tile, in int x, in int y)
|
||||
public void SetExtensionTiles(Item tile, in int x, in int y)
|
||||
{
|
||||
GetTileWidthHeight(tile, x, y, out var w, out var h);
|
||||
|
||||
@@ -160,7 +160,7 @@ public void SetExtensionTiles(FieldItem tile, in int x, in int y)
|
||||
}
|
||||
}
|
||||
|
||||
private void GetTileWidthHeight(FieldItem tile, int x, int y, out int w, out int h)
|
||||
private void GetTileWidthHeight(Item tile, int x, int y, out int w, out int h)
|
||||
{
|
||||
var type = ItemInfo.GetItemSize(tile);
|
||||
w = type.GetWidth();
|
||||
@@ -185,7 +185,7 @@ private void GetTileWidthHeight(FieldItem tile, int x, int y, out int w, out int
|
||||
/// 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(FieldItem tile, in int x, in int y)
|
||||
public FieldItemPermission IsOccupied(Item tile, in int x, in int y)
|
||||
{
|
||||
var type = ItemInfo.GetItemSize(tile);
|
||||
var w = type.GetWidth();
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace NHSE.Core
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = SIZE, Pack = 1)]
|
||||
public class FieldItem : IHeldItem, ICopyableItem<FieldItem>
|
||||
{
|
||||
public const ushort EXTENSION = 0xFFFD;
|
||||
public const ushort NONE = 0xFFFE;
|
||||
public const int SIZE = 8;
|
||||
|
||||
private const string HeldItem = nameof(HeldItem);
|
||||
private const string ExtensionItem = nameof(ExtensionItem);
|
||||
private const string Derived = nameof(Derived);
|
||||
|
||||
[Category(Derived)] public bool IsNone => ItemType == NONE;
|
||||
[Category(Derived)] public bool IsExtension => ItemType == EXTENSION;
|
||||
[Category(Derived)] public bool IsRoot => ItemType < EXTENSION;
|
||||
[Category(Derived)] public ushort DisplayItemId => IsExtension ? ExtensionItemId : ItemId;
|
||||
[Category(Derived)] public bool IsBuried => (SystemParam & 4) != 0;
|
||||
|
||||
// Item Definition
|
||||
[field: FieldOffset(0)][Category(HeldItem)] public ushort ItemId { get; set; }
|
||||
[field: FieldOffset(2)][Category(HeldItem)] public byte SystemParam { get; set; }
|
||||
[field: FieldOffset(3)][Category(HeldItem)] public byte AdditionalParam { get; set; }
|
||||
[field: FieldOffset(4)] public int FreeParam { get; set; }
|
||||
|
||||
[field: FieldOffset(4)][Category(HeldItem)] public ushort Count { get; set; } // Tree Shake/Fossil Item ID
|
||||
[field: FieldOffset(6)][Category(HeldItem)] public ushort UseCount { get; set; }
|
||||
|
||||
[field: FieldOffset(4)][Category(HeldItem)] public FlowerGene Genes { get; set; } // flowers only
|
||||
|
||||
// Field Item Definition
|
||||
[field: FieldOffset(0)][Category(ExtensionItem)] public ushort ItemType { get; set; }
|
||||
[field: FieldOffset(2)][Category(ExtensionItem)] public byte Rotation { get; set; }
|
||||
[field: FieldOffset(3)][Category(ExtensionItem)] public byte E03 { get; set; }
|
||||
[field: FieldOffset(4)][Category(ExtensionItem)] public ushort ExtensionItemId { get; set; }
|
||||
[field: FieldOffset(6)][Category(ExtensionItem)] public byte ExtensionX { get; set; }
|
||||
[field: FieldOffset(7)][Category(ExtensionItem)] public byte ExtensionY { get; set; }
|
||||
|
||||
public FieldItem() { } // marshalling
|
||||
|
||||
public void CopyFrom(FieldItem item)
|
||||
{
|
||||
ItemType = item.ItemType;
|
||||
Rotation = item.Rotation;
|
||||
E03 = item.E03;
|
||||
ExtensionItemId = item.ExtensionItemId;
|
||||
ExtensionX = item.ExtensionX;
|
||||
ExtensionY = item.ExtensionY;
|
||||
}
|
||||
|
||||
public int Size => SIZE;
|
||||
|
||||
public FieldItem(ushort itemId = NONE, byte flags0 = 0, byte flags1 = 0, byte count = 0, ushort useCount = 0)
|
||||
{
|
||||
ItemId = itemId;
|
||||
SystemParam = flags0;
|
||||
AdditionalParam = flags1;
|
||||
Count = count;
|
||||
UseCount = useCount;
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
ItemId = NONE;
|
||||
SystemParam = AdditionalParam = 0;
|
||||
Count = UseCount = 0;
|
||||
}
|
||||
|
||||
public void CopyFrom(Item item)
|
||||
{
|
||||
ItemId = item.ItemId;
|
||||
SystemParam = item.SystemParam;
|
||||
AdditionalParam = item.AdditionalParam;
|
||||
Count = item.Count;
|
||||
UseCount = item.UseCount;
|
||||
}
|
||||
|
||||
public static FieldItem[] GetArray(byte[] data) => data.GetArray<FieldItem>(SIZE);
|
||||
public static byte[] SetArray(IReadOnlyList<FieldItem> data) => data.SetArray(SIZE);
|
||||
|
||||
public void SetAsExtension(FieldItem tile, byte x, byte y)
|
||||
{
|
||||
ItemType = EXTENSION;
|
||||
Rotation = 0;
|
||||
E03 = 0;
|
||||
ExtensionX = x;
|
||||
ExtensionY = y;
|
||||
ExtensionItemId = tile.ItemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace NHSE.Core
|
||||
{
|
||||
public interface IHeldItem
|
||||
{
|
||||
ushort ItemId { get; set; }
|
||||
byte SystemParam { get; set; }
|
||||
byte AdditionalParam { get; set; }
|
||||
ushort Count { get; set; }
|
||||
ushort UseCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,18 @@
|
||||
namespace NHSE.Core
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = SIZE, Pack = 1)]
|
||||
public class Item : IHeldItem, ICopyableItem<IHeldItem>
|
||||
public class Item : ICopyableItem<Item>
|
||||
{
|
||||
public static readonly Item NO_ITEM = new Item {ItemId = NONE};
|
||||
public const ushort NONE = 0xFFFE;
|
||||
public const ushort EXTENSION = 0xFFFD;
|
||||
|
||||
public const ushort MessageBottle = 0x16A1;
|
||||
public const ushort DIYRecipe = 0x16A2;
|
||||
public const ushort MessageBottleEgg = 0x3100;
|
||||
public const int SIZE = 8;
|
||||
|
||||
private static readonly ushort[] resolvedItemIdArray =
|
||||
private static readonly ushort[] WrappingRedirect =
|
||||
{
|
||||
0x1E13, 0x1E14, 0x1E15, 0x1E16, 0x1E17, 0x1E18, 0x1E19, 0x1E1A,
|
||||
0x1E1B, 0x1E1C, 0x1E1D, 0x1E1E, 0x1E1F, 0x1E20, 0x1E21, 0x1E22
|
||||
@@ -23,6 +27,12 @@ public class Item : IHeldItem, ICopyableItem<IHeldItem>
|
||||
[field: FieldOffset(3)] public byte AdditionalParam { get; set; }
|
||||
[field: FieldOffset(4)] public int FreeParam { get; set; }
|
||||
|
||||
public int Rotation => SystemParam & 3;
|
||||
public bool IsBuried => (SystemParam & 4) != 0;
|
||||
|
||||
public ItemWrapping WrappingType => (ItemWrapping)(AdditionalParam & 3);
|
||||
public int WrappingIndex => (AdditionalParam >> 2) & 0xF;
|
||||
|
||||
#region Stackable Items
|
||||
[field: FieldOffset(4)] public ushort Count { get; set; }
|
||||
[field: FieldOffset(6)] public ushort UseCount { get; set; }
|
||||
@@ -111,36 +121,48 @@ public void Water(bool all = false)
|
||||
|
||||
#endregion
|
||||
|
||||
public ItemType Type => (ItemType) (AdditionalParam & 3);
|
||||
public int ReservedIndex => (AdditionalParam >> 2) & 0xF;
|
||||
#region Item Extensions
|
||||
public ushort DisplayItemId => IsExtension ? ExtensionItemId : ItemId;
|
||||
public bool IsNone => ItemId == NONE;
|
||||
public bool IsExtension => ItemId == EXTENSION;
|
||||
public bool IsRoot => ItemId < EXTENSION;
|
||||
[field: FieldOffset(4)] public ushort ExtensionItemId { get; set; }
|
||||
[field: FieldOffset(6)] public byte ExtensionX { get; set; }
|
||||
[field: FieldOffset(7)] public byte ExtensionY { get; set; }
|
||||
|
||||
public void SetAsExtension(Item tile, byte x, byte y)
|
||||
{
|
||||
ItemId = EXTENSION;
|
||||
SystemParam = 0;
|
||||
AdditionalParam = 0;
|
||||
ExtensionX = x;
|
||||
ExtensionY = y;
|
||||
ExtensionItemId = tile.ItemId;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Item() { } // marshalling
|
||||
|
||||
public Item(ushort itemId = NONE, byte systemParam = 0, byte additionalParam = 0, byte count = 0, ushort useCount = 0)
|
||||
public Item(ushort itemId = NONE)
|
||||
{
|
||||
ItemId = itemId;
|
||||
SystemParam = systemParam;
|
||||
AdditionalParam = additionalParam;
|
||||
Count = count;
|
||||
UseCount = useCount;
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
ItemId = NONE;
|
||||
SystemParam = AdditionalParam = 0;
|
||||
Count = UseCount = 0;
|
||||
FreeParam = 0;
|
||||
}
|
||||
|
||||
public virtual int Size => SIZE;
|
||||
|
||||
public void CopyFrom(IHeldItem item)
|
||||
public void CopyFrom(Item item)
|
||||
{
|
||||
ItemId = item.ItemId;
|
||||
SystemParam = item.SystemParam;
|
||||
AdditionalParam = item.AdditionalParam;
|
||||
Count = item.Count;
|
||||
UseCount = item.UseCount;
|
||||
FreeParam = item.FreeParam;
|
||||
}
|
||||
|
||||
public static Item[] GetArray(byte[] data) => data.GetArray<Item>(SIZE);
|
||||
@@ -148,14 +170,14 @@ public void CopyFrom(IHeldItem item)
|
||||
|
||||
public ushort GetInventoryNameFromFlags()
|
||||
{
|
||||
if (ItemId == 0x16A1 || ItemId == 0x3100)
|
||||
if (ItemId == MessageBottle || ItemId == MessageBottleEgg)
|
||||
return ItemId;
|
||||
|
||||
return Type switch
|
||||
return WrappingType switch
|
||||
{
|
||||
ItemType.Reserved => resolvedItemIdArray[ReservedIndex],
|
||||
ItemType.Present => 0x1180,
|
||||
ItemType.Delivery => 0x1225,
|
||||
ItemWrapping.Reserved => WrappingRedirect[WrappingIndex],
|
||||
ItemWrapping.Present => 0x1180,
|
||||
ItemWrapping.Delivery => 0x1225,
|
||||
_ => ItemId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace NHSE.Core
|
||||
{
|
||||
public class ItemArrayEditor<T> where T : class, IHeldItem, ICopyableItem<T>
|
||||
public class ItemArrayEditor<T> where T : Item, ICopyableItem<T>
|
||||
{
|
||||
public readonly IReadOnlyList<T> Items;
|
||||
public ItemArrayEditor(IReadOnlyList<T> items) => Items = items;
|
||||
|
||||
@@ -5,8 +5,7 @@ public static class ItemInfo
|
||||
private static readonly byte[] ItemKinds = ResourceUtil.GetBinaryResource("item_kind.bin");
|
||||
private static readonly byte[] ItemSizes = ResourceUtil.GetBinaryResource("item_size.bin");
|
||||
|
||||
public static ItemKind GetItemKind(IHeldItem item) => GetItemKind(item.ItemId);
|
||||
public static ItemKind GetItemKind(FieldItem item) => GetItemKind(item.DisplayItemId);
|
||||
public static ItemKind GetItemKind(Item item) => GetItemKind(item.DisplayItemId);
|
||||
|
||||
public static ItemKind GetItemKind(ushort id)
|
||||
{
|
||||
@@ -15,8 +14,7 @@ public static ItemKind GetItemKind(ushort id)
|
||||
return (ItemKind) ItemKinds[id];
|
||||
}
|
||||
|
||||
public static ItemSizeType GetItemSize(IHeldItem item) => GetItemSize(item.ItemId);
|
||||
public static ItemSizeType GetItemSize(FieldItem item) => GetItemSize(item.DisplayItemId);
|
||||
public static ItemSizeType GetItemSize(Item item) => GetItemSize(item.DisplayItemId);
|
||||
|
||||
public static ItemSizeType GetItemSize(ushort id)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace NHSE.Core
|
||||
{
|
||||
public enum ItemType
|
||||
public enum ItemWrapping
|
||||
{
|
||||
Nothing = 0,
|
||||
Reserved = 1,
|
||||
@@ -24,7 +24,7 @@ public sealed class VillagerItem : Item, ICopyableItem<VillagerItem>
|
||||
|
||||
public void CopyFrom(VillagerItem item)
|
||||
{
|
||||
CopyFrom((IHeldItem) item);
|
||||
CopyFrom((Item) item);
|
||||
U08 = item.U08;
|
||||
U0C = item.U0C;
|
||||
U10 = item.U10;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace NHSE.Sprites
|
||||
{
|
||||
public static class FieldItemColor
|
||||
{
|
||||
public static Color GetItemColor(FieldItem item)
|
||||
public static Color GetItemColor(Item item)
|
||||
{
|
||||
var kind = ItemInfo.GetItemKind(item);
|
||||
if (kind == ItemKind.Unknown)
|
||||
@@ -15,10 +15,10 @@ public static Color GetItemColor(FieldItem item)
|
||||
return Colors[(int)kind];
|
||||
}
|
||||
|
||||
private static Color GetItemColor60000(FieldItem item)
|
||||
private static Color GetItemColor60000(Item item)
|
||||
{
|
||||
var id = item.DisplayItemId;
|
||||
if (id == FieldItem.NONE)
|
||||
if (id == Item.NONE)
|
||||
return Color.Transparent;
|
||||
|
||||
if (!FieldItemList.Items.TryGetValue(id, out var def))
|
||||
|
||||
@@ -17,7 +17,7 @@ public static Bitmap GetBitmapItemLayer(FieldItemLayer layer)
|
||||
return ImageUtil.GetBitmap(bmpData, width, height);
|
||||
}
|
||||
|
||||
private static void LoadBitmapLayer(FieldItem[] items, int[] bmpData, int width, int height)
|
||||
private static void LoadBitmapLayer(Item[] items, int[] bmpData, int width, int height)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
@@ -59,7 +59,7 @@ public static Bitmap GetBitmapItemLayerAcre(FieldItemLayer layer, int x0, int y0
|
||||
ImageUtil.ScalePixelImage(acre1, acreScale, w, h, scale);
|
||||
|
||||
if (transparency >> 24 != 0xFF)
|
||||
ImageUtil.SetAllTransparencyTo(acreScale, transparency);
|
||||
ImageUtil.ClampAllTransparencyTo(acreScale, transparency);
|
||||
|
||||
// draw symbols over special items now?
|
||||
DrawDirectionals(acreScale, layer, w, x0, y0, scale);
|
||||
@@ -109,7 +109,7 @@ private static void DrawX(int[] data, int x0, int y0, int scale, int w)
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawDirectional(int[] data, FieldItem tile, int x0, int y0, int scale, int w)
|
||||
private static void DrawDirectional(int[] data, Item tile, int x0, int y0, int scale, int w)
|
||||
{
|
||||
var eX = tile.ExtensionX;
|
||||
var eY = tile.ExtensionY;
|
||||
@@ -155,7 +155,7 @@ public static Bitmap GetBitmapItemLayer(FieldItemLayer layer, int x, int y, int[
|
||||
{
|
||||
LoadBitmapLayer(layer.Tiles, data, layer.MapWidth, layer.MapHeight);
|
||||
if (transparency >> 24 != 0xFF)
|
||||
ImageUtil.SetAllTransparencyTo(data, transparency);
|
||||
ImageUtil.ClampAllTransparencyTo(data, transparency);
|
||||
ImageUtil.SetBitmapData(dest, data);
|
||||
return DrawViewReticle(dest, layer, x, y);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public static class ItemColor
|
||||
private static readonly Color[] Colors = ((KnownColor[])Enum.GetValues(typeof(KnownColor)))
|
||||
.Select(Color.FromKnownColor).Select(z => ColorUtil.Blend(Color.White, z, 0.5d)).ToArray();
|
||||
|
||||
public static Color GetItemColor(IHeldItem item)
|
||||
public static Color GetItemColor(Item item)
|
||||
{
|
||||
if (item.ItemId == Item.NONE)
|
||||
return Color.Transparent;
|
||||
|
||||
@@ -23,16 +23,18 @@ public static void Initialize(string path, string[] itemNames)
|
||||
foreach (var f in files)
|
||||
{
|
||||
var fn = Path.GetFileNameWithoutExtension(f);
|
||||
if (fn == null)
|
||||
continue;
|
||||
FileLookup.Add(fn, f);
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap GetItemMarkup(IHeldItem item, Font font, int width, int height, Bitmap backing)
|
||||
public static Bitmap GetItemMarkup(Item item, Font font, int width, int height, Bitmap backing)
|
||||
{
|
||||
return CreateFake(item, font, width, height, backing);
|
||||
}
|
||||
|
||||
public static Image? GetItemSprite(IHeldItem item)
|
||||
public static Image? GetItemSprite(Item item)
|
||||
{
|
||||
var id = item.ItemId;
|
||||
|
||||
@@ -66,7 +68,7 @@ private static bool GetItemImageSprite(ushort id, out string? path)
|
||||
return FileLookup.TryGetValue(name, out path);
|
||||
}
|
||||
|
||||
public static Bitmap? GetImage(IHeldItem item, Font font, int width, int height)
|
||||
public static Bitmap? GetImage(Item item, Font font, int width, int height)
|
||||
{
|
||||
if (item.ItemId == Item.NONE)
|
||||
return null;
|
||||
@@ -77,25 +79,25 @@ private static bool GetItemImageSprite(ushort id, out string? path)
|
||||
private static readonly StringFormat Center = new StringFormat
|
||||
{ Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
|
||||
|
||||
public static Bitmap CreateFake(IHeldItem item, Font font, int width, int height)
|
||||
public static Bitmap CreateFake(Item item, Font font, int width, int height)
|
||||
{
|
||||
var bmp = new Bitmap(width, height);
|
||||
return CreateFake(item, font, width, height, bmp);
|
||||
}
|
||||
|
||||
private static Bitmap CreateFake(IHeldItem item, Font font, int width, int height, Bitmap bmp)
|
||||
private static Bitmap CreateFake(Item item, Font font, int width, int height, Bitmap bmp)
|
||||
{
|
||||
using var gfx = Graphics.FromImage(bmp);
|
||||
DrawItemAt(gfx, item, font, width, height);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public static void DrawItemAt(Graphics gfx, IHeldItem item, Font font, int width, int height)
|
||||
public static void DrawItemAt(Graphics gfx, Item item, Font font, int width, int height)
|
||||
{
|
||||
DrawInfo(gfx, font, item, width, height, Brushes.Black);
|
||||
}
|
||||
|
||||
private static void DrawInfo(Graphics gfx, Font font, IHeldItem item, int width, int height, Brush brush)
|
||||
private static void DrawInfo(Graphics gfx, Font font, Item item, int width, int height, Brush brush)
|
||||
{
|
||||
if (item.Count != 0)
|
||||
gfx.DrawString(item.Count.ToString(), font, brush, 0, 0);
|
||||
|
||||
@@ -125,17 +125,5 @@ public static void ClampAllTransparencyTo(int[] data, int trans)
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
data[i] &= trans;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a bitwise and of the requested transparency; this is assuming the pixel value is 0xFF_xx_xx_xx. Single operation laziness!
|
||||
/// </summary>
|
||||
public static void SetAllTransparencyTo(int[] data, int color)
|
||||
{
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
if ((data[i] & 0xFF000000) == 0)
|
||||
data[i] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ private void ClickClone(object sender, EventArgs e)
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
||||
private void SetItemSprite(IHeldItem item, PictureBox pb)
|
||||
private void SetItemSprite(Item item, PictureBox pb)
|
||||
{
|
||||
var dw = Sprites.Width;
|
||||
var dh = Sprites.Height;
|
||||
|
||||
@@ -40,7 +40,7 @@ public FieldItemEditor(MainSave sav)
|
||||
LB_Items.Items.Add(obj.ToString());
|
||||
|
||||
ReloadMapBackground();
|
||||
PG_Tile.SelectedObject = new FieldItem();
|
||||
PG_Tile.SelectedObject = new Item();
|
||||
PG_TerrainTile.SelectedObject = new TerrainTile();
|
||||
LB_Items.SelectedIndex = 0;
|
||||
CB_Acre.SelectedIndex = 0;
|
||||
@@ -127,7 +127,7 @@ private void OmniTileTerrain(MouseEventArgs e)
|
||||
OmniTileTerrain(tile);
|
||||
}
|
||||
|
||||
private void OmniTile(FieldItem tile, int x, int y)
|
||||
private void OmniTile(Item tile, int x, int y)
|
||||
{
|
||||
switch (ModifierKeys)
|
||||
{
|
||||
@@ -159,7 +159,7 @@ private void OmniTileTerrain(TerrainTile tile)
|
||||
}
|
||||
}
|
||||
|
||||
private FieldItem GetTile(FieldItemLayer layer, MouseEventArgs e, out int x, out int y)
|
||||
private Item GetTile(FieldItemLayer layer, MouseEventArgs e, out int x, out int y)
|
||||
{
|
||||
SetHoveredItem(e);
|
||||
return layer.GetTile(x = View.X + HoverX, y = View.Y + HoverY);
|
||||
@@ -185,9 +185,9 @@ private void PB_Acre_MouseMove(object sender, MouseEventArgs e)
|
||||
SetCoordinateText(x, y);
|
||||
}
|
||||
|
||||
private void ViewTile(FieldItem tile)
|
||||
private void ViewTile(Item tile)
|
||||
{
|
||||
var pgt = (FieldItem)PG_Tile.SelectedObject;
|
||||
var pgt = (Item)PG_Tile.SelectedObject;
|
||||
pgt.CopyFrom(tile);
|
||||
PG_Tile.SelectedObject = pgt;
|
||||
TC_Editor.SelectedTab = Tab_Item;
|
||||
@@ -201,10 +201,10 @@ private void ViewTile(TerrainTile tile)
|
||||
TC_Editor.SelectedTab = Tab_Terrain;
|
||||
}
|
||||
|
||||
private void SetTile(FieldItem tile, int x, int y)
|
||||
private void SetTile(Item tile, int x, int y)
|
||||
{
|
||||
var l = Map.CurrentLayer;
|
||||
var pgt = (FieldItem)PG_Tile.SelectedObject;
|
||||
var pgt = (Item)PG_Tile.SelectedObject;
|
||||
var permission = l.IsOccupied(pgt, x, y);
|
||||
switch (permission)
|
||||
{
|
||||
@@ -234,7 +234,7 @@ private void SetTile(TerrainTile tile)
|
||||
ReloadBuildingsTerrain();
|
||||
}
|
||||
|
||||
private void DeleteTile(FieldItem tile, int x, int y)
|
||||
private void DeleteTile(Item tile, int x, int y)
|
||||
{
|
||||
if (tile.IsRoot && CHK_AutoExtension.Checked)
|
||||
Map.CurrentLayer.DeleteExtensionTiles(tile, x, y);
|
||||
|
||||
@@ -20,7 +20,7 @@ public static bool ImportToLayerAcreSingle(FieldItemLayer layer, int acreIndex,
|
||||
var path = ofd.FileName;
|
||||
var fi = new FileInfo(path);
|
||||
|
||||
int expect = layer.AcreTileCount * FieldItem.SIZE;
|
||||
int expect = layer.AcreTileCount * Item.SIZE;
|
||||
if (fi.Length != expect)
|
||||
{
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect));
|
||||
@@ -45,7 +45,7 @@ public static bool ImportToLayerAcreAll(FieldItemLayer layer)
|
||||
var path = ofd.FileName;
|
||||
var fi = new FileInfo(path);
|
||||
|
||||
int expect = layer.MapTileCount * FieldItem.SIZE;
|
||||
int expect = layer.MapTileCount * Item.SIZE;
|
||||
if (fi.Length != expect)
|
||||
{
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect));
|
||||
|
||||
Reference in New Issue
Block a user