From 673ea5859a15bca5357a52875be1b3faeca6ebb4 Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Sun, 25 Jan 2026 10:50:05 +0100 Subject: [PATCH 1/8] Implemented Mine Door rotation Issue Warlander/DeedPlanner3 #7 --- .../Deedplanner/Data/Grounds/DoorDirection.cs | 7 ++ .../Data/Grounds/DoorDirection.cs.meta | 3 + .../Deedplanner/Data/Grounds/Ground.cs | 12 +- .../Deedplanner/Data/Grounds/GroundData.cs | 2 + .../Deedplanner/Data/Grounds/GroundMesh.cs | 108 +++++++++++++++++- Assets/Warlander/Deedplanner/Data/Tile.cs | 55 ++++++++- 6 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs create mode 100644 Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs.meta diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs b/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs new file mode 100644 index 00000000..1726b475 --- /dev/null +++ b/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs @@ -0,0 +1,7 @@ +namespace Warlander.Deedplanner.Data.Grounds +{ + public enum DoorDirection + { + N, E, S, W + } +} diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs.meta b/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs.meta new file mode 100644 index 00000000..cdef26d6 --- /dev/null +++ b/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2e29b5fefd3d456c9267268085d70616 +timeCreated: 1769309513 \ No newline at end of file diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs b/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs index 36e4f833..5256b09e 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs @@ -20,12 +20,14 @@ public RoadDirection RoadDirection { get => roadDirection; set => Tile.Map.CommandManager.AddToActionAndExecute(new RoadDirectionChangeCommand(this, roadDirection, value)); } + public DoorDirection DoorDirection { get; set; } = DoorDirection.N; public Ground(Tile tile, GroundData data) { Tile = tile; Data = data; RoadDirection = RoadDirection.Center; + DoorDirection = tile.UpdateDoorDirection(); } public void Serialize(XmlDocument document, XmlElement localRoot) @@ -90,7 +92,8 @@ public void Execute() if (newData != null) { ground.data = newData; - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); + ground.DoorDirection = ground.Tile.UpdateDoorDirection(); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); } } @@ -99,7 +102,8 @@ public void Undo() if (oldData != null) { ground.data = oldData; - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); + ground.DoorDirection = ground.Tile.UpdateDoorDirection(); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); } } @@ -130,13 +134,13 @@ public RoadDirectionChangeCommand(Ground ground, RoadDirection oldDirection, Roa public void Execute() { ground.roadDirection = newDirection; - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); } public void Undo() { ground.roadDirection = oldDirection; - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); } public void DisposeUndo() diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs index 7962eeb7..c5426429 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs @@ -13,6 +13,7 @@ public class GroundData public TextureReference Tex3d { get; } public bool Diagonal { get; } + public bool IsCaveDoor { get; private set; } = false; public GroundData(string name, string shortName, string[][] categories, TextureReference tex2d, TextureReference tex3d, bool diagonal) { @@ -22,6 +23,7 @@ public GroundData(string name, string shortName, string[][] categories, TextureR Tex2d = tex2d; Tex3d = tex3d; Diagonal = diagonal; + IsCaveDoor = ShortName is "wcaDoor" or "gcaDoor" or "scaDoor" or "mcaDoor"; } public override string ToString() diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs index ce7f4382..a57d8dd8 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs @@ -34,6 +34,7 @@ public class GroundMesh : MonoBehaviour private int[,] slopesArray; private GroundData[,] dataArray; private RoadDirection[,] directionsArray; + private DoorDirection[,] doorDirectionsArray; private Vector3[] renderVertices; private Vector2[] uv2; @@ -82,6 +83,7 @@ public void Initialize(int width, int height, OverlayMesh newOverlayMesh) slopesArray = new int[Width + 1, Height + 1]; dataArray = new GroundData[Width, Height]; directionsArray = new RoadDirection[Width, Height]; + doorDirectionsArray = new DoorDirection[Width, Height]; RenderMesh = new Mesh(); RenderMesh.name = "ground render mesh"; @@ -376,6 +378,53 @@ public int GetSlope(int x, int y) { return this[x, y]; } + + private void ApplyUvRotation(int x, int y, DoorDirection dir) + { + int vertexIndex = (x * Height + y) * VerticesPerRenderTile; + Vector2[] meshUvs = RenderMesh.uv; + + // Corner vectors (DoorDirection.N) + Vector2 v00 = new Vector2(0, 0); + Vector2 v10 = new Vector2(1, 0); + Vector2 v01 = new Vector2(0, 1); + Vector2 v11 = new Vector2(1, 1); + Vector2 vCenter = new Vector2(0.5f, 0.5f); + + // Rotating vectors based on DoorDirection + if (dir == DoorDirection.E) + { + (v00, v10, v11, v01) = (v10, v11, v01, v00); + } + else if (dir == DoorDirection.S) + { + (v00, v11, v10, v01) = (v11, v00, v01, v10); + } + else if (dir == DoorDirection.W) + { + (v00, v01, v11, v10) = (v01, v11, v10, v00); + } + + // Apply vectors + meshUvs[vertexIndex] = v00; + meshUvs[vertexIndex + 1] = v01; + meshUvs[vertexIndex + 2] = vCenter; + + meshUvs[vertexIndex + 3] = v01; + meshUvs[vertexIndex + 4] = v11; + meshUvs[vertexIndex + 5] = vCenter; + + meshUvs[vertexIndex + 6] = v11; + meshUvs[vertexIndex + 7] = v10; + meshUvs[vertexIndex + 8] = vCenter; + + meshUvs[vertexIndex + 9] = v10; + meshUvs[vertexIndex + 10] = v00; + meshUvs[vertexIndex + 11] = vCenter; + + RenderMesh.uv = meshUvs; + } + public void SetSlope(int x, int y, int slope) { @@ -542,20 +591,30 @@ public RoadDirection GetRoadDirection(int x, int y) return directionsArray[x, y]; } - public void SetGroundData(int x, int y, GroundData data, RoadDirection direction) + public void SetGroundData(int x, int y, GroundData data, RoadDirection direction, DoorDirection doorDirection) { if (x < 0 || x >= Width || y < 0 || y >= Height) { return; } - if (dataArray[x, y] == data && directionsArray[x, y] == direction) + if (dataArray[x, y] == data && directionsArray[x, y] == direction && doorDirectionsArray[x, y] == doorDirection) { return; } dataArray[x, y] = data; directionsArray[x, y] = direction; + doorDirectionsArray[x, y] = doorDirection; + + if (data.IsCaveDoor) + { + ApplyUvRotation(x, y, doorDirection); + } + else + { + ApplyUvRotation(x, y, DoorDirection.N); + } UpdateUV2(x, y, true); UpdateUV2(x - 1, y, false); @@ -587,16 +646,53 @@ private void UpdateUV2(int x, int y, bool primaryChangedTile) int vertexIndex = index * VerticesPerRenderTile; RoadDirection roadDirection = directionsArray[x, y]; + DoorDirection doorDir = doorDirectionsArray[x, y]; Vector2Int selfCoords = new Vector2Int(x, y); + int westSlot = vertexIndex; + int northSlot = vertexIndex + 3; + int eastSlot = vertexIndex + 6; + int southSlot = vertexIndex + 9; + + if (data.IsCaveDoor) + { + if (doorDir == DoorDirection.E) + { + Debug.Log("Rotating cave door East."); + westSlot = vertexIndex + 9; + northSlot = vertexIndex; + eastSlot = vertexIndex + 3; + southSlot = vertexIndex + 6; + } + else if (doorDir == DoorDirection.S) + { + Debug.Log("Rotating cave door South."); + westSlot = vertexIndex + 6; + northSlot = vertexIndex + 9; + eastSlot = vertexIndex; + southSlot = vertexIndex + 3; + } + else if (doorDir == DoorDirection.W) + { + Debug.Log("Rotating cave door West."); + westSlot = vertexIndex + 3; + northSlot = vertexIndex + 6; + eastSlot = vertexIndex + 9; + southSlot = vertexIndex; + } + } + bool forceSelfDataWest = roadDirection.IsCenter() || roadDirection.IsWest(); - UpdateUV2Triangle(selfCoords, new Vector2Int(x - 1, y), vertexIndex, primaryChangedTile, forceSelfDataWest); + UpdateUV2Triangle(selfCoords, new Vector2Int(x - 1, y), westSlot, primaryChangedTile, forceSelfDataWest); + bool forceSelfDataNorth = roadDirection.IsCenter() || roadDirection.IsNorth(); - UpdateUV2Triangle(selfCoords, new Vector2Int(x, y + 1), vertexIndex + 3, primaryChangedTile, forceSelfDataNorth); + UpdateUV2Triangle(selfCoords, new Vector2Int(x, y + 1), northSlot, primaryChangedTile, forceSelfDataNorth); + bool forceSelfDataEast = roadDirection.IsCenter() || roadDirection.IsEast(); - UpdateUV2Triangle(selfCoords, new Vector2Int(x + 1, y), vertexIndex + 6, primaryChangedTile, forceSelfDataEast); + UpdateUV2Triangle(selfCoords, new Vector2Int(x + 1, y), eastSlot, primaryChangedTile, forceSelfDataEast); + bool forceSelfDataSouth = roadDirection.IsCenter() || roadDirection.IsSouth(); - UpdateUV2Triangle(selfCoords, new Vector2Int(x, y - 1), vertexIndex + 9, primaryChangedTile, forceSelfDataSouth); + UpdateUV2Triangle(selfCoords, new Vector2Int(x, y - 1), southSlot, primaryChangedTile, forceSelfDataSouth); } private void UpdateUV2Triangle(Vector2Int selfCoords, Vector2Int diagonalCoords, int uvIndex, bool primaryChangedTile, bool forceSelfData) diff --git a/Assets/Warlander/Deedplanner/Data/Tile.cs b/Assets/Warlander/Deedplanner/Data/Tile.cs index 88306c17..e9041932 100644 --- a/Assets/Warlander/Deedplanner/Data/Tile.cs +++ b/Assets/Warlander/Deedplanner/Data/Tile.cs @@ -92,7 +92,46 @@ public Tile(Map map, int x, int y, IOutlineCoordinator outlineCoordinator) // Map.AddEntityToMap(caveObject, -1); // Cave.Initialize(this, Database.DefaultCaveData); } + + public DoorDirection UpdateDoorDirection() + { + if (X <= 0 || X + 1 >= Map.Width || Y <= 0 || Y + 1 >= Map.Height) return DoorDirection.N; + + Tile nwTile = this.Map[X, Y + 1]; + Tile neTile = this.Map[X + 1, Y + 1]; + Tile seTile = this.Map[X + 1, Y]; + + if (nwTile == null || neTile == null || seTile == null) return DoorDirection.N; + + int sw = SurfaceHeight; + int nw = this.Map[X, Y + 1].SurfaceHeight; + int ne = this.Map[X + 1, Y + 1].SurfaceHeight; + int se = this.Map[X + 1, Y].SurfaceHeight; + + float northAvg = (nw + ne) / 2f; + float eastAvg = (ne + se) / 2f; + float southAvg = (se + sw) / 2f; + float westAvg = (sw + nw) / 2f; + + float max = Mathf.Max(northAvg, eastAvg, southAvg, westAvg); + + if (max == northAvg) return DoorDirection.N; + if (max == eastAvg) return DoorDirection.E; + if (max == southAvg) return DoorDirection.S; + if (max == westAvg) return DoorDirection.W; + + return DoorDirection.N; + } + public void RefreshDoorOrientation() + { + if (Ground.Data.IsCaveDoor) + { + Ground.DoorDirection = UpdateDoorDirection(); + Map.Ground.SetGroundData(X, Y, Ground.Data, Ground.RoadDirection, Ground.DoorDirection); + } + } + public void PasteTile(Tile otherTile) { SurfaceHeight = otherTile.SurfaceHeight; @@ -1089,10 +1128,20 @@ public void Undo() private void Refresh() { tile.Map.Ground.SetSlope(tile.X, tile.Y, tile.surfaceHeight); + + Tile t10 = tile.Map.GetRelativeTile(tile, -1, 0); + Tile t01 = tile.Map.GetRelativeTile(tile, 0, -1); + Tile t11 = tile.Map.GetRelativeTile(tile, -1, -1); + tile.RefreshSurfaceEntities(); - tile.Map.GetRelativeTile(tile, -1, 0)?.RefreshSurfaceEntities(); - tile.Map.GetRelativeTile(tile, 0, -1)?.RefreshSurfaceEntities(); - tile.Map.GetRelativeTile(tile, -1, -1)?.RefreshSurfaceEntities(); + t10?.RefreshSurfaceEntities(); + t01?.RefreshSurfaceEntities(); + t11?.RefreshSurfaceEntities(); + + tile.RefreshDoorOrientation(); + t10?.RefreshDoorOrientation(); + t01?.RefreshDoorOrientation(); + t11?.RefreshDoorOrientation(); tile.Map.RecalculateSurfaceHeight(tile.X, tile.Y); } From d4f1512bc7a0acf706c430fc71e0b3b9feb9ed46 Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Mon, 26 Jan 2026 10:51:30 +0100 Subject: [PATCH 2/8] Updated objects.xml with correct logWideWindow mesh name --- Assets/StreamingAssets/objects.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/StreamingAssets/objects.xml b/Assets/StreamingAssets/objects.xml index 585f70ea..c5bd5fca 100644 --- a/Assets/StreamingAssets/objects.xml +++ b/Assets/StreamingAssets/objects.xml @@ -3907,7 +3907,7 @@ - + Logs = 7, @@ -4016,7 +4016,7 @@ - + Logs = 7, @@ -4125,7 +4125,7 @@ - + Logs = 7, @@ -4234,7 +4234,7 @@ - + Logs = 7, @@ -4357,7 +4357,7 @@ - + Logs = 7, @@ -4484,7 +4484,7 @@ - + Logs = 7, @@ -4611,7 +4611,7 @@ - + Logs = 7, @@ -4738,7 +4738,7 @@ - + Logs = 7, From 39f38259651bfd6ff501fc6da3cb30871cc4f16f Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Mon, 26 Jan 2026 10:57:27 +0100 Subject: [PATCH 3/8] Revert "Updated objects.xml with correct logWideWindow mesh name" This reverts commit d4f1512bc7a0acf706c430fc71e0b3b9feb9ed46. --- Assets/StreamingAssets/objects.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/StreamingAssets/objects.xml b/Assets/StreamingAssets/objects.xml index c5bd5fca..585f70ea 100644 --- a/Assets/StreamingAssets/objects.xml +++ b/Assets/StreamingAssets/objects.xml @@ -3907,7 +3907,7 @@ - + Logs = 7, @@ -4016,7 +4016,7 @@ - + Logs = 7, @@ -4125,7 +4125,7 @@ - + Logs = 7, @@ -4234,7 +4234,7 @@ - + Logs = 7, @@ -4357,7 +4357,7 @@ - + Logs = 7, @@ -4484,7 +4484,7 @@ - + Logs = 7, @@ -4611,7 +4611,7 @@ - + Logs = 7, @@ -4738,7 +4738,7 @@ - + Logs = 7, From 20f75c4e45b589299fdc80abd583edad591619dd Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Tue, 27 Jan 2026 03:43:34 +0100 Subject: [PATCH 4/8] Refactored DoorDirection logic --- .../Deedplanner/Data/Grounds/Ground.cs | 13 ++++--------- .../Deedplanner/Data/Grounds/GroundMesh.cs | 17 ++++++++++++++--- Assets/Warlander/Deedplanner/Data/Map.cs | 2 +- Assets/Warlander/Deedplanner/Data/Tile.cs | 3 +-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs b/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs index 5256b09e..0eb4135a 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs @@ -20,14 +20,11 @@ public RoadDirection RoadDirection { get => roadDirection; set => Tile.Map.CommandManager.AddToActionAndExecute(new RoadDirectionChangeCommand(this, roadDirection, value)); } - public DoorDirection DoorDirection { get; set; } = DoorDirection.N; - public Ground(Tile tile, GroundData data) { Tile = tile; Data = data; RoadDirection = RoadDirection.Center; - DoorDirection = tile.UpdateDoorDirection(); } public void Serialize(XmlDocument document, XmlElement localRoot) @@ -92,8 +89,7 @@ public void Execute() if (newData != null) { ground.data = newData; - ground.DoorDirection = ground.Tile.UpdateDoorDirection(); - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); } } @@ -102,8 +98,7 @@ public void Undo() if (oldData != null) { ground.data = oldData; - ground.DoorDirection = ground.Tile.UpdateDoorDirection(); - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); } } @@ -134,13 +129,13 @@ public RoadDirectionChangeCommand(Ground ground, RoadDirection oldDirection, Roa public void Execute() { ground.roadDirection = newDirection; - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); } public void Undo() { ground.roadDirection = oldDirection; - ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection, ground.DoorDirection); + ground.Tile.Map.Ground.SetGroundData(ground.Tile.X, ground.Tile.Y, ground.data, ground.RoadDirection); } public void DisposeUndo() diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs index a57d8dd8..b89e0b37 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs @@ -5,6 +5,7 @@ using Warlander.Deedplanner.Logic; using Warlander.Render; + namespace Warlander.Deedplanner.Data.Grounds { public class GroundMesh : MonoBehaviour @@ -30,11 +31,12 @@ public class GroundMesh : MonoBehaviour public Mesh ColliderMesh { get; private set; } public int Width { get; private set; } public int Height { get; private set; } - + private int[,] slopesArray; private GroundData[,] dataArray; private RoadDirection[,] directionsArray; private DoorDirection[,] doorDirectionsArray; + private Map map; private Vector3[] renderVertices; private Vector2[] uv2; @@ -43,8 +45,9 @@ public class GroundMesh : MonoBehaviour private bool needsVerticesUpdate = false; private bool needsUvUpdate = false; - public void Initialize(int width, int height, OverlayMesh newOverlayMesh) + public void Initialize(Map map, int width, int height, OverlayMesh newOverlayMesh) { + this.map = map; gameObject.layer = LayerMasks.GroundLayer; if (groundTexturesArray == null) { @@ -591,8 +594,16 @@ public RoadDirection GetRoadDirection(int x, int y) return directionsArray[x, y]; } - public void SetGroundData(int x, int y, GroundData data, RoadDirection direction, DoorDirection doorDirection) + public void SetGroundData(int x, int y, GroundData data, RoadDirection direction) { + Tile currentTile = map?[x, y]; + DoorDirection doorDirection = DoorDirection.N; + + if (currentTile != null) + { + doorDirection = currentTile.UpdateDoorDirection(); + } + if (x < 0 || x >= Width || y < 0 || y >= Height) { return; diff --git a/Assets/Warlander/Deedplanner/Data/Map.cs b/Assets/Warlander/Deedplanner/Data/Map.cs index dbbbe839..57b30f2b 100644 --- a/Assets/Warlander/Deedplanner/Data/Map.cs +++ b/Assets/Warlander/Deedplanner/Data/Map.cs @@ -302,7 +302,7 @@ private void PreInitialize(int width, int height) GameObject groundObject = new GameObject("Ground Mesh", typeof(GroundMesh)); Ground = groundObject.GetComponent(); - Ground.Initialize(width, height, surfaceOverlayMesh); + Ground.Initialize(this, width, height, surfaceOverlayMesh); surfaceOverlayMesh.Initialize(Ground.ColliderMesh); AddEntityToMap(groundObject, 0); diff --git a/Assets/Warlander/Deedplanner/Data/Tile.cs b/Assets/Warlander/Deedplanner/Data/Tile.cs index e9041932..d00dd600 100644 --- a/Assets/Warlander/Deedplanner/Data/Tile.cs +++ b/Assets/Warlander/Deedplanner/Data/Tile.cs @@ -127,8 +127,7 @@ public void RefreshDoorOrientation() { if (Ground.Data.IsCaveDoor) { - Ground.DoorDirection = UpdateDoorDirection(); - Map.Ground.SetGroundData(X, Y, Ground.Data, Ground.RoadDirection, Ground.DoorDirection); + Map.Ground.SetGroundData(X, Y, Ground.Data, Ground.RoadDirection); } } From 98e00084a9fb9063ae0969dd4957f3826f2d088c Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Tue, 27 Jan 2026 03:57:06 +0100 Subject: [PATCH 5/8] Added null check to SetGroundData for currenTile --- Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs index b89e0b37..392a8433 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs @@ -597,6 +597,12 @@ public RoadDirection GetRoadDirection(int x, int y) public void SetGroundData(int x, int y, GroundData data, RoadDirection direction) { Tile currentTile = map?[x, y]; + + if (currentTile == null) + { + return; + } + DoorDirection doorDirection = DoorDirection.N; if (currentTile != null) From beb7472f9d7ae7bc24bb41edf4f6a40c648ac627 Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Tue, 27 Jan 2026 05:07:18 +0100 Subject: [PATCH 6/8] Optimisation to SetGroundData method --- .../Deedplanner/Data/Grounds/GroundMesh.cs | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs index 392a8433..4a6339e9 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs @@ -596,25 +596,26 @@ public RoadDirection GetRoadDirection(int x, int y) public void SetGroundData(int x, int y, GroundData data, RoadDirection direction) { - Tile currentTile = map?[x, y]; - - if (currentTile == null) + if (x < 0 || x >= Width || y < 0 || y >= Height) { return; } DoorDirection doorDirection = DoorDirection.N; - if (currentTile != null) - { - doorDirection = currentTile.UpdateDoorDirection(); - } - - if (x < 0 || x >= Width || y < 0 || y >= Height) + if (data.IsCaveDoor) { - return; + Tile currentTile = map?[x, y]; + if (currentTile != null) + { + doorDirection = currentTile.UpdateDoorDirection(); + } } + bool wasDoor = dataArray[x, y] != null && dataArray[x, y].IsCaveDoor; + bool isDoor = data.IsCaveDoor; + bool directionChanged = doorDirectionsArray[x, y] != doorDirection;; + if (dataArray[x, y] == data && directionsArray[x, y] == direction && doorDirectionsArray[x, y] == doorDirection) { return; @@ -624,15 +625,11 @@ public void SetGroundData(int x, int y, GroundData data, RoadDirection direction directionsArray[x, y] = direction; doorDirectionsArray[x, y] = doorDirection; - if (data.IsCaveDoor) - { - ApplyUvRotation(x, y, doorDirection); - } - else + if ((isDoor && directionChanged) || (wasDoor && !isDoor)) { - ApplyUvRotation(x, y, DoorDirection.N); + ApplyUvRotation(x, y, doorDirection); } - + UpdateUV2(x, y, true); UpdateUV2(x - 1, y, false); UpdateUV2(x + 1, y, false); @@ -675,7 +672,6 @@ private void UpdateUV2(int x, int y, bool primaryChangedTile) { if (doorDir == DoorDirection.E) { - Debug.Log("Rotating cave door East."); westSlot = vertexIndex + 9; northSlot = vertexIndex; eastSlot = vertexIndex + 3; @@ -683,7 +679,6 @@ private void UpdateUV2(int x, int y, bool primaryChangedTile) } else if (doorDir == DoorDirection.S) { - Debug.Log("Rotating cave door South."); westSlot = vertexIndex + 6; northSlot = vertexIndex + 9; eastSlot = vertexIndex; @@ -691,7 +686,6 @@ private void UpdateUV2(int x, int y, bool primaryChangedTile) } else if (doorDir == DoorDirection.W) { - Debug.Log("Rotating cave door West."); westSlot = vertexIndex + 3; northSlot = vertexIndex + 6; eastSlot = vertexIndex + 9; From 8654b67a849f45c5c235357c703376979b99378d Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Tue, 27 Jan 2026 09:47:08 +0100 Subject: [PATCH 7/8] Renamed and refactored Door Orientation logic --- .../Warlander/Deedplanner/Data/DataLoader.cs | 4 +- .../{DoorDirection.cs => DoorOrientation.cs} | 2 +- ...ection.cs.meta => DoorOrientation.cs.meta} | 0 .../Deedplanner/Data/Grounds/GroundData.cs | 6 +- .../Deedplanner/Data/Grounds/GroundMesh.cs | 85 +++++++------------ Assets/Warlander/Deedplanner/Data/Tile.cs | 16 ++-- 6 files changed, 47 insertions(+), 66 deletions(-) rename Assets/Warlander/Deedplanner/Data/Grounds/{DoorDirection.cs => DoorOrientation.cs} (71%) rename Assets/Warlander/Deedplanner/Data/Grounds/{DoorDirection.cs.meta => DoorOrientation.cs.meta} (100%) diff --git a/Assets/Warlander/Deedplanner/Data/DataLoader.cs b/Assets/Warlander/Deedplanner/Data/DataLoader.cs index b88d15f2..ed9c042c 100644 --- a/Assets/Warlander/Deedplanner/Data/DataLoader.cs +++ b/Assets/Warlander/Deedplanner/Data/DataLoader.cs @@ -164,6 +164,7 @@ private void LoadGrounds(XmlDocument document) TextureReference tex3d = null; List categories = new List(); bool diagonal = false; + bool caveDoor = false; foreach (XmlElement child in element) { @@ -187,6 +188,7 @@ private void LoadGrounds(XmlDocument document) break; case "category": categories.Add(child.InnerText.Split('/')); + caveDoor = (child.InnerText == "Cave doors") ? true : false; break; case "diagonal": diagonal = true; @@ -199,7 +201,7 @@ private void LoadGrounds(XmlDocument document) Debug.LogWarning("No textures loaded, aborting"); } - GroundData data = new GroundData(name, shortName, categories.ToArray(), tex2d, tex3d, diagonal); + GroundData data = new GroundData(name, shortName, categories.ToArray(), tex2d, tex3d, diagonal, caveDoor); Database.Grounds[shortName] = data; Debug.Log("Ground data " + name + " loaded and ready to use!"); } diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs b/Assets/Warlander/Deedplanner/Data/Grounds/DoorOrientation.cs similarity index 71% rename from Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs rename to Assets/Warlander/Deedplanner/Data/Grounds/DoorOrientation.cs index 1726b475..6245fec9 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/DoorOrientation.cs @@ -1,6 +1,6 @@ namespace Warlander.Deedplanner.Data.Grounds { - public enum DoorDirection + public enum DoorOrientation { N, E, S, W } diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs.meta b/Assets/Warlander/Deedplanner/Data/Grounds/DoorOrientation.cs.meta similarity index 100% rename from Assets/Warlander/Deedplanner/Data/Grounds/DoorDirection.cs.meta rename to Assets/Warlander/Deedplanner/Data/Grounds/DoorOrientation.cs.meta diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs index c5426429..2759c3fc 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundData.cs @@ -13,9 +13,9 @@ public class GroundData public TextureReference Tex3d { get; } public bool Diagonal { get; } - public bool IsCaveDoor { get; private set; } = false; + public bool IsCaveDoor { get; } - public GroundData(string name, string shortName, string[][] categories, TextureReference tex2d, TextureReference tex3d, bool diagonal) + public GroundData(string name, string shortName, string[][] categories, TextureReference tex2d, TextureReference tex3d, bool diagonal, bool isCaveDoor) { Name = name; ShortName = shortName; @@ -23,7 +23,7 @@ public GroundData(string name, string shortName, string[][] categories, TextureR Tex2d = tex2d; Tex3d = tex3d; Diagonal = diagonal; - IsCaveDoor = ShortName is "wcaDoor" or "gcaDoor" or "scaDoor" or "mcaDoor"; + IsCaveDoor = isCaveDoor; } public override string ToString() diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs index 4a6339e9..23d52de3 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs @@ -35,7 +35,7 @@ public class GroundMesh : MonoBehaviour private int[,] slopesArray; private GroundData[,] dataArray; private RoadDirection[,] directionsArray; - private DoorDirection[,] doorDirectionsArray; + private DoorOrientation[,] doorOrientationsArray; private Map map; private Vector3[] renderVertices; @@ -86,7 +86,7 @@ public void Initialize(Map map, int width, int height, OverlayMesh newOverlayMes slopesArray = new int[Width + 1, Height + 1]; dataArray = new GroundData[Width, Height]; directionsArray = new RoadDirection[Width, Height]; - doorDirectionsArray = new DoorDirection[Width, Height]; + doorOrientationsArray = new DoorOrientation[Width, Height]; RenderMesh = new Mesh(); RenderMesh.name = "ground render mesh"; @@ -382,7 +382,7 @@ public int GetSlope(int x, int y) return this[x, y]; } - private void ApplyUvRotation(int x, int y, DoorDirection dir) + private void ApplyUvRotation(int x, int y, DoorOrientation doorOrientation) { int vertexIndex = (x * Height + y) * VerticesPerRenderTile; Vector2[] meshUvs = RenderMesh.uv; @@ -395,18 +395,14 @@ private void ApplyUvRotation(int x, int y, DoorDirection dir) Vector2 vCenter = new Vector2(0.5f, 0.5f); // Rotating vectors based on DoorDirection - if (dir == DoorDirection.E) - { - (v00, v10, v11, v01) = (v10, v11, v01, v00); - } - else if (dir == DoorDirection.S) - { - (v00, v11, v10, v01) = (v11, v00, v01, v10); - } - else if (dir == DoorDirection.W) + + (v00, v10, v01, v11) = (doorOrientation) switch { - (v00, v01, v11, v10) = (v01, v11, v10, v00); - } + DoorOrientation.E => (v10, v11, v00, v01), + DoorOrientation.S => (v11, v01, v10, v00), + DoorOrientation.W => (v01, v00, v11, v10), + _ => (v00, v10, v01, v11), + }; // Apply vectors meshUvs[vertexIndex] = v00; @@ -601,33 +597,33 @@ public void SetGroundData(int x, int y, GroundData data, RoadDirection direction return; } - DoorDirection doorDirection = DoorDirection.N; + DoorOrientation doorOrientation = DoorOrientation.N; if (data.IsCaveDoor) { Tile currentTile = map?[x, y]; if (currentTile != null) { - doorDirection = currentTile.UpdateDoorDirection(); + doorOrientation = currentTile.CalculateDoorOrientation(); } } - bool wasDoor = dataArray[x, y] != null && dataArray[x, y].IsCaveDoor; - bool isDoor = data.IsCaveDoor; - bool directionChanged = doorDirectionsArray[x, y] != doorDirection;; + bool wasCaveDoor = dataArray[x, y] != null && dataArray[x, y].IsCaveDoor; + bool isCaveDoor = data.IsCaveDoor; + bool orientationChanged = doorOrientationsArray[x, y] != doorOrientation;; - if (dataArray[x, y] == data && directionsArray[x, y] == direction && doorDirectionsArray[x, y] == doorDirection) + if (dataArray[x, y] == data && directionsArray[x, y] == direction && doorOrientationsArray[x, y] == doorOrientation) { return; } dataArray[x, y] = data; directionsArray[x, y] = direction; - doorDirectionsArray[x, y] = doorDirection; + doorOrientationsArray[x, y] = doorOrientation; - if ((isDoor && directionChanged) || (wasDoor && !isDoor)) + if ((isCaveDoor && orientationChanged) || (wasCaveDoor && !isCaveDoor)) { - ApplyUvRotation(x, y, doorDirection); + ApplyUvRotation(x, y, doorOrientation); } UpdateUV2(x, y, true); @@ -660,38 +656,21 @@ private void UpdateUV2(int x, int y, bool primaryChangedTile) int vertexIndex = index * VerticesPerRenderTile; RoadDirection roadDirection = directionsArray[x, y]; - DoorDirection doorDir = doorDirectionsArray[x, y]; + DoorOrientation doorOrientation = doorOrientationsArray[x, y]; Vector2Int selfCoords = new Vector2Int(x, y); - - int westSlot = vertexIndex; - int northSlot = vertexIndex + 3; - int eastSlot = vertexIndex + 6; - int southSlot = vertexIndex + 9; - - if (data.IsCaveDoor) + + var (wOffset, nOffset, eOffset, sOffset) = (data.IsCaveDoor ? doorOrientation : DoorOrientation.N) switch { - if (doorDir == DoorDirection.E) - { - westSlot = vertexIndex + 9; - northSlot = vertexIndex; - eastSlot = vertexIndex + 3; - southSlot = vertexIndex + 6; - } - else if (doorDir == DoorDirection.S) - { - westSlot = vertexIndex + 6; - northSlot = vertexIndex + 9; - eastSlot = vertexIndex; - southSlot = vertexIndex + 3; - } - else if (doorDir == DoorDirection.W) - { - westSlot = vertexIndex + 3; - northSlot = vertexIndex + 6; - eastSlot = vertexIndex + 9; - southSlot = vertexIndex; - } - } + DoorOrientation.E => (9, 0, 3, 6), + DoorOrientation.S => (6, 9, 0, 3), + DoorOrientation.W => (3, 6, 9, 0), + _ => (0, 3, 6, 9), + }; + + int westSlot = vertexIndex + wOffset; + int northSlot = vertexIndex + nOffset; + int eastSlot = vertexIndex + eOffset; + int southSlot = vertexIndex + sOffset; bool forceSelfDataWest = roadDirection.IsCenter() || roadDirection.IsWest(); UpdateUV2Triangle(selfCoords, new Vector2Int(x - 1, y), westSlot, primaryChangedTile, forceSelfDataWest); diff --git a/Assets/Warlander/Deedplanner/Data/Tile.cs b/Assets/Warlander/Deedplanner/Data/Tile.cs index d00dd600..3b4e980c 100644 --- a/Assets/Warlander/Deedplanner/Data/Tile.cs +++ b/Assets/Warlander/Deedplanner/Data/Tile.cs @@ -93,15 +93,15 @@ public Tile(Map map, int x, int y, IOutlineCoordinator outlineCoordinator) // Cave.Initialize(this, Database.DefaultCaveData); } - public DoorDirection UpdateDoorDirection() + public DoorOrientation CalculateDoorOrientation() { - if (X <= 0 || X + 1 >= Map.Width || Y <= 0 || Y + 1 >= Map.Height) return DoorDirection.N; + if (X <= 0 || X + 1 >= Map.Width || Y <= 0 || Y + 1 >= Map.Height) return DoorOrientation.N; Tile nwTile = this.Map[X, Y + 1]; Tile neTile = this.Map[X + 1, Y + 1]; Tile seTile = this.Map[X + 1, Y]; - if (nwTile == null || neTile == null || seTile == null) return DoorDirection.N; + if (nwTile == null || neTile == null || seTile == null) return DoorOrientation.N; int sw = SurfaceHeight; int nw = this.Map[X, Y + 1].SurfaceHeight; @@ -115,12 +115,12 @@ public DoorDirection UpdateDoorDirection() float max = Mathf.Max(northAvg, eastAvg, southAvg, westAvg); - if (max == northAvg) return DoorDirection.N; - if (max == eastAvg) return DoorDirection.E; - if (max == southAvg) return DoorDirection.S; - if (max == westAvg) return DoorDirection.W; + if (max == northAvg) return DoorOrientation.N; + if (max == eastAvg) return DoorOrientation.E; + if (max == southAvg) return DoorOrientation.S; + if (max == westAvg) return DoorOrientation.W; - return DoorDirection.N; + return DoorOrientation.N; } public void RefreshDoorOrientation() From 8a6d39daa04af690a84d299828f8110385c7c6df Mon Sep 17 00:00:00 2001 From: Matyas Sunyovszki Date: Tue, 27 Jan 2026 10:04:02 +0100 Subject: [PATCH 8/8] Minor changes to Ground.cs and Groundmesh.cs --- Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs | 1 + Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs b/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs index 0eb4135a..9a8381e8 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/Ground.cs @@ -20,6 +20,7 @@ public RoadDirection RoadDirection { get => roadDirection; set => Tile.Map.CommandManager.AddToActionAndExecute(new RoadDirectionChangeCommand(this, roadDirection, value)); } + public Ground(Tile tile, GroundData data) { Tile = tile; diff --git a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs index 23d52de3..5ed65adb 100644 --- a/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs +++ b/Assets/Warlander/Deedplanner/Data/Grounds/GroundMesh.cs @@ -5,7 +5,6 @@ using Warlander.Deedplanner.Logic; using Warlander.Render; - namespace Warlander.Deedplanner.Data.Grounds { public class GroundMesh : MonoBehaviour