NHSE/NHSE.Core/Structures/Map/Layers/LayerRoomItem.cs
Kurt b88c518d5c
Update FieldItemEditor for 3.0.0 (#716)
Updates the Field Item Editor to render layers based on the entire map, and the per-patch positioning of each layer.
Import/export will gracefully handle upgrade/downgrade, and viewport import/export will gracefully update tiles rather than a per-acre basis.

Performance has also been slightly improved; no allocation is done anymore when updating the image.
2026-01-25 16:55:38 -06:00

33 lines
996 B
C#

using System;
using System.Collections.Generic;
namespace NHSE.Core;
public sealed record LayerRoomItem : LayerItem
{
public const int SIZE = Width * Height * Item.SIZE;
private const byte Width = 20;
private const byte Height = 20;
public LayerRoomItem(ReadOnlySpan<byte> data) : this(Item.GetArray(data)) { }
public LayerRoomItem(Item[] tiles) : base(tiles, Width, Height) { }
public static LayerRoomItem[] GetArray(ReadOnlySpan<byte> data)
{
var result = new LayerRoomItem[data.Length / SIZE];
for (int i = 0; i < result.Length; i++)
{
var slice = data.Slice(i * SIZE, SIZE);
result[i] = new LayerRoomItem(slice);
}
return result;
}
public static byte[] SetArray(IReadOnlyList<LayerRoomItem> 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;
}
}