diff --git a/scenes/WorldView.cs b/scenes/WorldView.cs index 1acedca..359beae 100644 --- a/scenes/WorldView.cs +++ b/scenes/WorldView.cs @@ -57,11 +57,13 @@ public class WorldView : Spatial private PackedScene _hexTile3DScene = GD.Load("res://scenes/HexTile3D.tscn"); private HexGrid HexGrid = new(); - public SceneTileChunk(Vector2 chunkIndex, int size) + public SceneTileChunk(Vector2 chunkIndex) { - foreach (int i in Enumerable.Range(0, size)) + int chunkSize = global::World.ChunkSize; + + foreach (int i in Enumerable.Range(0, chunkSize)) { - foreach (int j in Enumerable.Range(0, size)) + foreach (int j in Enumerable.Range(0, chunkSize)) { HexTile3D tile3D = (HexTile3D)_hexTile3DScene.Instance(); @@ -96,7 +98,7 @@ public class WorldView : Spatial SceneTileChunk CreateSceneTileChunk(Vector2 chunkIndex) { - SceneTileChunk sceneTileChunk = new SceneTileChunk(chunkIndex, global::World.ChunkSize); + SceneTileChunk sceneTileChunk = new SceneTileChunk(chunkIndex); foreach (HexTile3D hexTile3D in sceneTileChunk.TileNodes) { @@ -107,14 +109,13 @@ public class WorldView : Spatial return sceneTileChunk; } - SceneTileChunk RemoveChunkFromScene(Vector2 chunkIndex) + SceneTileChunk FindSceneTileChunkAtIndex(Vector2 chunkIndex) { foreach (Spatial child in GetChildren()) { SceneTileChunk sceneTileChunk = child as SceneTileChunk; if (sceneTileChunk == null) { - RemoveChild(child); continue; } @@ -168,7 +169,7 @@ public class WorldView : Spatial Array removedChunks = new(); foreach (Vector2 chunkIndex in removedChunkIndices) { - SceneTileChunk chunk = RemoveChunkFromScene(chunkIndex); + SceneTileChunk chunk = FindSceneTileChunkAtIndex(chunkIndex); if (chunk != null) { removedChunks.Add(chunk);