From cd715a24cbf726658fc63c66b28e0d1bda8be1fa Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 23 Aug 2025 15:48:08 +0200 Subject: [PATCH] Refactor marker management to use child count for occupancy checks; update road management to handle Marker2D types --- Scripts/Components/PopulationVisualizer.cs | 4 ++-- Scripts/Components/RoadManager.cs | 15 ++++++++------- Scripts/FollowerMarker.cs | 19 ------------------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/Scripts/Components/PopulationVisualizer.cs b/Scripts/Components/PopulationVisualizer.cs index a3ef7af..e143926 100644 --- a/Scripts/Components/PopulationVisualizer.cs +++ b/Scripts/Components/PopulationVisualizer.cs @@ -120,9 +120,9 @@ public partial class PopulationVisualizer : Node } else { - if (marker.IsOccupied) + if (marker.GetChildCount() > 0) { - marker.RemoveFollower(); + marker.GetChild(0).QueueFree(); needsChange = true; } } diff --git a/Scripts/Components/RoadManager.cs b/Scripts/Components/RoadManager.cs index 7214849..b3436f7 100644 --- a/Scripts/Components/RoadManager.cs +++ b/Scripts/Components/RoadManager.cs @@ -45,15 +45,16 @@ public partial class RoadManager : Node2D _roadNetwork.ClearPoints(); var activeMarkers = _markersContainer.GetChildren() - .OfType() - .Where(m => m.IsOccupied && m.FollowerInstance != null && - m.FollowerInstance.Tier >= _minimumTierForRoads) + .OfType() // We can just look for any Marker2D + .Select(m => new { Marker = m, Visual = m.GetChildOrNull(0) }) + .Where(mv => mv.Visual != null && mv.Visual.Tier >= _minimumTierForRoads) + .Select(mv => mv.Marker) .ToList(); if (activeMarkers.Count < 2) return; - var treeNodes = new HashSet(); - var remainingNodes = new List(activeMarkers); + var treeNodes = new HashSet(); + var remainingNodes = new List(activeMarkers); var edges = new List<(Vector2, Vector2)>(); var startNode = remainingNodes[0]; @@ -62,8 +63,8 @@ public partial class RoadManager : Node2D while (remainingNodes.Any()) { - FollowerMarker bestSource = null; - FollowerMarker bestDest = null; + Node2D bestSource = null; + Node2D bestDest = null; var minDistanceSq = float.MaxValue; foreach (var source in treeNodes) diff --git a/Scripts/FollowerMarker.cs b/Scripts/FollowerMarker.cs index 59af2f7..8de4ec8 100644 --- a/Scripts/FollowerMarker.cs +++ b/Scripts/FollowerMarker.cs @@ -5,23 +5,4 @@ namespace ParasiticGod.Scripts; [GlobalClass] public partial class FollowerMarker : Marker2D { - public bool IsOccupied { get; private set; } - public Follower FollowerInstance { get; private set; } - - public void PlaceFollower(Follower followerInstance) - { - if (IsOccupied) return; - AddChild(followerInstance); - followerInstance.Position = Vector2.Zero; - IsOccupied = true; - FollowerInstance = followerInstance; - } - - public void RemoveFollower() - { - if (!IsOccupied) return; - FollowerInstance.QueueFree(); - FollowerInstance = null; - IsOccupied = false; - } } \ No newline at end of file