mirror of
https://github.com/kwsch/NHSE.git
synced 2026-08-01 23:43:06 -05:00
Add layer support check, add enum for room layer location/type
This commit is contained in:
parent
797cd0e16d
commit
ef3b39e4a0
|
|
@ -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<string> GetUnsupportedTiles()
|
||||
{
|
||||
var lBase = Layers[0];
|
||||
var lSupport = Layers[1];
|
||||
var result = new List<string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
NHSE.Core/Structures/Map/Managers/RoomLayerSurface.cs
Normal file
14
NHSE.Core/Structures/Map/Managers/RoomLayerSurface.cs
Normal file
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user