From ef3b39e4a04f4e4275df06476127278cbd550cdf Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 12 May 2020 19:47:31 -0700 Subject: [PATCH] Add layer support check, add enum for room layer location/type --- .../Map/Managers/RoomItemManager.cs | 49 ++++++++++++++----- .../Map/Managers/RoomLayerSurface.cs | 14 ++++++ .../Subforms/Map/PlayerHouseEditor.cs | 3 ++ 3 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 NHSE.Core/Structures/Map/Managers/RoomLayerSurface.cs diff --git a/NHSE.Core/Structures/Map/Managers/RoomItemManager.cs b/NHSE.Core/Structures/Map/Managers/RoomItemManager.cs index 4865826..e6f689d 100644 --- a/NHSE.Core/Structures/Map/Managers/RoomItemManager.cs +++ b/NHSE.Core/Structures/Map/Managers/RoomItemManager.cs @@ -1,31 +1,56 @@ -using System.Diagnostics; +using System; +using System.Collections.Generic; +using System.Diagnostics; namespace NHSE.Core { public class RoomItemManager { - // Layer 1: Base Layer Placed Items - // Layer 2: Supported Layer Placed Items - // Layer 3: North Wall - // Layer 4: ??? - // Layer 5: ??? - // Layer 6: ??? - // Layer 7: Rug - // Layer 8: ??? - public readonly RoomItemLayer[] Layers; public readonly PlayerRoom Room; + private const int LayerCount = 8; public RoomItemManager(PlayerRoom room) { Layers = room.GetItemLayers(); Room = room; - Debug.Assert(Layers.Length == 8); + Debug.Assert(Layers.Length == LayerCount); } public void Save() => Room.SetItemLayers(Layers); - // public bool IsOccupied(int x, int y) => Layers.Any(z => !z.GetTile(x, y).IsNone); + public bool IsOccupied(int layer, int x, int y) + { + if ((uint)layer >= LayerCount) + throw new ArgumentOutOfRangeException(nameof(layer)); + + var l = Layers[layer]; + var tile = l.GetTile(x, y); + return !tile.IsNone || (layer == 1 && IsOccupied(0, x, y)); + } + + public List GetUnsupportedTiles() + { + var lBase = Layers[0]; + var lSupport = Layers[1]; + var result = new List(); + for (int x = 0; x < lBase.MaxWidth; x++) + { + for (int y = 0; y < lBase.MaxHeight; y++) + { + var tile = lSupport.GetTile(x, y); + if (tile.IsNone) + continue; + + var support = lBase.GetTile(x, y); + if (!support.IsNone) + continue; // dunno how to check if the tile can actually have an item put on top of it... + + result.Add($"{x:000},{y:000}"); + } + } + return result; + } } } diff --git a/NHSE.Core/Structures/Map/Managers/RoomLayerSurface.cs b/NHSE.Core/Structures/Map/Managers/RoomLayerSurface.cs new file mode 100644 index 0000000..7457169 --- /dev/null +++ b/NHSE.Core/Structures/Map/Managers/RoomLayerSurface.cs @@ -0,0 +1,14 @@ +namespace NHSE.Core +{ + public enum RoomLayerSurface + { + Floor = 0, + FloorSupported = 1, + WallNorth = 2, + WallWest = 3, + WallSouth = 4, + WallEast = 5, + Rugs = 6, + Ceiling = 7, + } +} diff --git a/NHSE.WinForms/Subforms/Map/PlayerHouseEditor.cs b/NHSE.WinForms/Subforms/Map/PlayerHouseEditor.cs index 9f4dcad..c5c4137 100644 --- a/NHSE.WinForms/Subforms/Map/PlayerHouseEditor.cs +++ b/NHSE.WinForms/Subforms/Map/PlayerHouseEditor.cs @@ -150,6 +150,9 @@ private void ChangeRoom(PlayerHouse house) private void ReloadManager(PlayerHouse house) { + var unsupported = Manager.GetUnsupportedTiles(); + if (unsupported.Count != 0) + WinFormsUtil.Alert(MessageStrings.MsgFieldItemUnsupportedLayer2Tile); var room = house.GetRoom(RoomIndex); Manager = new RoomItemManager(room); }