Refactor marker management to use child count for occupancy checks; update road management to handle Marker2D types
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -45,15 +45,16 @@ public partial class RoadManager : Node2D
|
||||
_roadNetwork.ClearPoints();
|
||||
|
||||
var activeMarkers = _markersContainer.GetChildren()
|
||||
.OfType<FollowerMarker>()
|
||||
.Where(m => m.IsOccupied && m.FollowerInstance != null &&
|
||||
m.FollowerInstance.Tier >= _minimumTierForRoads)
|
||||
.OfType<Marker2D>() // We can just look for any Marker2D
|
||||
.Select(m => new { Marker = m, Visual = m.GetChildOrNull<ModdableVisual>(0) })
|
||||
.Where(mv => mv.Visual != null && mv.Visual.Tier >= _minimumTierForRoads)
|
||||
.Select(mv => mv.Marker)
|
||||
.ToList();
|
||||
|
||||
if (activeMarkers.Count < 2) return;
|
||||
|
||||
var treeNodes = new HashSet<FollowerMarker>();
|
||||
var remainingNodes = new List<FollowerMarker>(activeMarkers);
|
||||
var treeNodes = new HashSet<Node2D>();
|
||||
var remainingNodes = new List<Node2D>(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)
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user