astar angefangen
This commit is contained in:
@@ -8,7 +8,6 @@ namespace Slimepire.Gameplay;
|
||||
[SceneTree]
|
||||
public partial class BuildGhost : Node2D
|
||||
{
|
||||
public event Action<Vector2>? OnBuild;
|
||||
private Tube? _tube;
|
||||
private readonly Dictionary<Nodule, Tube> _connectedTubes = [];
|
||||
|
||||
@@ -77,7 +76,6 @@ public partial class BuildGhost : Node2D
|
||||
if (@event is InputEventMouseButton { Pressed: false, ButtonIndex: MouseButton.Left })
|
||||
{
|
||||
NoduleManager.Instance.Building = false;
|
||||
OnBuild?.Invoke(GlobalPosition);
|
||||
|
||||
var nodule = Instantiator.Instantiate<Nodule>();
|
||||
|
||||
|
||||
@@ -8,23 +8,26 @@ public partial class NoduleManager
|
||||
{
|
||||
public bool Building { get; set; }
|
||||
|
||||
private AStar2D _aStar = new();
|
||||
private readonly List<Nodule> _nodules = [];
|
||||
private readonly HashSet<NoduleConnection> _connections = [];
|
||||
|
||||
// GFX
|
||||
private readonly Dictionary<NoduleConnection, Tube> _tubeConnections = new();
|
||||
private readonly List<Tube> _tubes = [];
|
||||
|
||||
public void RegisterNodule(Nodule nodule)
|
||||
{
|
||||
_nodules.Add(nodule);
|
||||
_aStar.AddPoint(nodule.Id, nodule.Position);
|
||||
|
||||
UpdateNoduleConnections();
|
||||
UpdateTubes();
|
||||
UpdateTubesAndAstar();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
UpdateNoduleConnections();
|
||||
UpdateTubes();
|
||||
UpdateTubesAndAstar();
|
||||
}
|
||||
|
||||
private void UpdateNoduleConnections()
|
||||
@@ -36,24 +39,22 @@ public partial class NoduleManager
|
||||
_connections.Add(new NoduleConnection(n, c));
|
||||
}
|
||||
}
|
||||
|
||||
GD.Print($"Connections: {_connections.Count}");
|
||||
}
|
||||
|
||||
private void UpdateTubes()
|
||||
private void UpdateTubesAndAstar()
|
||||
{
|
||||
foreach (var c in _connections)
|
||||
{
|
||||
if (!_tubeConnections.ContainsKey(c))
|
||||
{
|
||||
GD.Print("Hello?");
|
||||
var tube = Instantiator.Instantiate<Tube>();
|
||||
_tubes.Add(tube);
|
||||
_tubeConnections.Add(c, tube);
|
||||
// tube.GlobalPosition = c.A.GlobalPosition;
|
||||
c.A.AddChild(tube);
|
||||
|
||||
tube.SetTarget(c.B.Position);
|
||||
|
||||
// TODO: refactor this out of gfx stuff
|
||||
_aStar.ConnectPoints(c.A.Id, c.B.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
using Slimepire.Core;
|
||||
using Slimepire.Data;
|
||||
|
||||
namespace Slimepire.Gameplay.Nodules;
|
||||
@@ -8,6 +6,8 @@ namespace Slimepire.Gameplay.Nodules;
|
||||
[SceneTree]
|
||||
public partial class Nodule : Node2D
|
||||
{
|
||||
public long Id { get; set; } = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
|
||||
|
||||
private bool _mouseInsideClickArea;
|
||||
private bool _clickedInside;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user