Refactor marker management to use child count for occupancy checks; update road management to handle Marker2D types

This commit is contained in:
2025-08-23 15:48:08 +02:00
parent 608bcc552d
commit cd715a24cb
3 changed files with 10 additions and 28 deletions

View File

@@ -120,9 +120,9 @@ public partial class PopulationVisualizer : Node
} }
else else
{ {
if (marker.IsOccupied) if (marker.GetChildCount() > 0)
{ {
marker.RemoveFollower(); marker.GetChild(0).QueueFree();
needsChange = true; needsChange = true;
} }
} }

View File

@@ -45,15 +45,16 @@ public partial class RoadManager : Node2D
_roadNetwork.ClearPoints(); _roadNetwork.ClearPoints();
var activeMarkers = _markersContainer.GetChildren() var activeMarkers = _markersContainer.GetChildren()
.OfType<FollowerMarker>() .OfType<Marker2D>() // We can just look for any Marker2D
.Where(m => m.IsOccupied && m.FollowerInstance != null && .Select(m => new { Marker = m, Visual = m.GetChildOrNull<ModdableVisual>(0) })
m.FollowerInstance.Tier >= _minimumTierForRoads) .Where(mv => mv.Visual != null && mv.Visual.Tier >= _minimumTierForRoads)
.Select(mv => mv.Marker)
.ToList(); .ToList();
if (activeMarkers.Count < 2) return; if (activeMarkers.Count < 2) return;
var treeNodes = new HashSet<FollowerMarker>(); var treeNodes = new HashSet<Node2D>();
var remainingNodes = new List<FollowerMarker>(activeMarkers); var remainingNodes = new List<Node2D>(activeMarkers);
var edges = new List<(Vector2, Vector2)>(); var edges = new List<(Vector2, Vector2)>();
var startNode = remainingNodes[0]; var startNode = remainingNodes[0];
@@ -62,8 +63,8 @@ public partial class RoadManager : Node2D
while (remainingNodes.Any()) while (remainingNodes.Any())
{ {
FollowerMarker bestSource = null; Node2D bestSource = null;
FollowerMarker bestDest = null; Node2D bestDest = null;
var minDistanceSq = float.MaxValue; var minDistanceSq = float.MaxValue;
foreach (var source in treeNodes) foreach (var source in treeNodes)

View File

@@ -5,23 +5,4 @@ namespace ParasiticGod.Scripts;
[GlobalClass] [GlobalClass]
public partial class FollowerMarker : Marker2D 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;
}
} }