continuing to switch to MapCell orientation

This commit is contained in:
2026-07-03 02:16:29 -04:00
parent e6355167e3
commit 336b72e4cb
13 changed files with 81 additions and 82 deletions
+14 -12
View File
@@ -41,8 +41,8 @@ public partial class PegController : TurnController
newFriendlyPeg._pegController = this;
List<Vector2I> unoccupied = [.. _playArea._map._bottomRow.Where(c => _pegs.All(e => e._address != c))];
Vector2I randomCell = unoccupied[Globals._rng.Next(unoccupied.Count)];
Dictionary<Vector2I, MapCell> unoccupied = _playArea._map._bottomRow.Where(c => c.Value._occupant == null).ToDictionary();
MapCell randomCell = unoccupied.ElementAt(Globals._rng.Next(unoccupied.Keys.Count)).Value;
SetPeg(newFriendlyPeg, randomCell);
_pegs.Add(newFriendlyPeg);
@@ -62,7 +62,7 @@ public partial class PegController : TurnController
newFriendlyPeg._pegController = this;
SetPeg(newFriendlyPeg, POSITIONS[i]);
SetPeg(newFriendlyPeg, _map._cells[POSITIONS[i]]);
_pegs.Add(newFriendlyPeg);
AddChild(newFriendlyPeg);
_pegsCreated++;
@@ -80,8 +80,8 @@ public partial class PegController : TurnController
newHostilePeg._pegController = this;
List<Vector2I> unoccupied = [.. _playArea._map._bottomRow.Where(c => _pegs.All(e => e._address != c))];
Vector2I randomCell = unoccupied[Globals._rng.Next(unoccupied.Count)];
Dictionary<Vector2I, MapCell> unoccupied = _map._bottomRow.Where(c => c.Value._occupant == null).ToDictionary();
MapCell randomCell = unoccupied.ElementAt(Globals._rng.Next(unoccupied.Count)).Value;
SetPeg(newHostilePeg, randomCell);
_pegs.Add(newHostilePeg);
@@ -100,8 +100,9 @@ public partial class PegController : TurnController
newHostilePeg.Click += HandlePegClick;
newHostilePeg._pegController = this;
newHostilePeg._map = _playArea._map;
SetPeg(newHostilePeg, POSITIONS[i]);
SetPeg(newHostilePeg, _map._cells[POSITIONS[i]]);
_pegs.Add(newHostilePeg);
AddChild(newHostilePeg);
_pegsCreated++;
@@ -162,12 +163,12 @@ public partial class PegController : TurnController
Map map = _playArea._map;
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
List<Vector2I> pl = [.. pathLayer.GetUsedCells()];
List<Vector2I> visible = peg.GetVisibleCells();
Dictionary<Vector2I, MapCell> visible = peg.GetVisibleCells();
for (int i = 0; i < pl.Count; i++)
{
Vector2I cell = pl[i];
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.IndexOf(cell) > -1 ? 1 : 4)));
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.ContainsKey(cell) ? 1 : 4)));
}
}
@@ -180,7 +181,7 @@ public partial class PegController : TurnController
public void HandlePegRemoval(Peg PEG_TO_REMOVE)
{
_pegs.Remove(PEG_TO_REMOVE);
_playArea._map.SetCellPeg(PEG_TO_REMOVE._address, null);
_playArea._map.SetCellPeg(_map._cells[PEG_TO_REMOVE._address], null);
PEG_TO_REMOVE.QueueFree();
_pegsDestroyed++;
}
@@ -246,10 +247,11 @@ public partial class PegController : TurnController
HandlePegTurn();
}
public void SetPeg(Peg PEG, Vector2I CELL)
public void SetPeg(Peg PEG, MapCell CELL)
{
_playArea._map.SetCellPeg(CELL, PEG);
PEG.GlobalPosition = _playArea._map.GetCellPositionFromAddress(CELL);
_map.SetCellPeg(CELL, PEG);
PEG._cell = CELL;
PEG.GlobalPosition = CELL.GlobalPosition;
}
}