Refactored code to be better separated (Rendering, Logic)

This commit is contained in:
=
2026-04-26 11:33:54 +02:00
parent 798fe23bb6
commit c80367dccd
9 changed files with 191 additions and 85 deletions
+32 -1
View File
@@ -5,6 +5,7 @@ using System.Linq;
using static WFC;
public partial class Layer : Node3D
{
private Node3D decorationRoot;
public Tile[,] tiles;
int layerSize;
Tile tile;
@@ -14,7 +15,11 @@ public partial class Layer : Node3D
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
decorationRoot = new Node3D
{
Name = "Decorations"
};
AddChild(decorationRoot);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
@@ -22,6 +27,17 @@ public partial class Layer : Node3D
{
}
public void ClearDecorations()
{
foreach (var tile in tiles)
{
foreach (Node child in tile.DecorationNode.GetChildren())
{
child.QueueFree();
}
}
}
public void SetupLayer(int layerSize, int level, Dictionary<string, MeshInstance3D> tileMeshes)
{
this.layerSize = layerSize;
@@ -44,6 +60,7 @@ public partial class Layer : Node3D
safetyCounter++;
if (safetyCounter > 1000) break;
}
CreateTileNodes();
}
private void GenerateBaseStructure(Dictionary<string, MeshInstance3D> tileMeshes)
@@ -68,6 +85,20 @@ public partial class Layer : Node3D
}
}
private void CreateTileNodes()
{
foreach (var tile in tiles)
{
var node = new Node3D
{
Position = tile.Position
};
decorationRoot.AddChild(node);
tile.DecorationNode = node;
}
}
private void ResetLayer(Dictionary<string, MeshInstance3D> tileMeshes)
{
for (int x = 0; x < layerSize; x++)