mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 04:05:54 +00:00
Door link fix
This commit is contained in:
parent
8c20e6f342
commit
cae1f99949
5 changed files with 86 additions and 33 deletions
|
|
@ -14,7 +14,7 @@ public partial class RogueliteRoom : Node2D
|
|||
public Vector2I GridPosition { get; set; } // Set by dungeon manager
|
||||
|
||||
[Export] public PackedScene DoorPrefab { get; private set; }
|
||||
[Export] public PackedScene WallPrefab { get; private set; }
|
||||
[Export] public PackedScene WallPrefab { get; private set; }
|
||||
|
||||
private static readonly Dictionary<string, Vector2I> DirectionMap = new()
|
||||
{
|
||||
|
|
@ -30,10 +30,26 @@ public partial class RogueliteRoom : Node2D
|
|||
{
|
||||
SpawnEnemies();
|
||||
//HandleDoors(connectionChecker);
|
||||
AddDebugLabel();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void HandleDoors(Func<Vector2I, bool> connectionChecker)
|
||||
private void AddDebugLabel()
|
||||
{
|
||||
for (int i = 0; i < RoomResource.Size.X; i++)
|
||||
{
|
||||
for (int j = 0; j < RoomResource.Size.Y; j++)
|
||||
{
|
||||
var label = new Label();
|
||||
label.Text = $"{GridPosition + new Vector2I(i, j)}";
|
||||
label.ZIndex = 11;
|
||||
label.Position = (new Vector2(i, j) * new Vector2(320, 160)) + new Vector2(160, 80);
|
||||
this.AddChild(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleDoors(Func<Vector2I, Vector2I, RoomConnection> connectionChecker)
|
||||
{
|
||||
if (!HasNode("Doors")) return;
|
||||
var doorsNode = GetNode("Doors");
|
||||
|
|
@ -47,8 +63,10 @@ public partial class RogueliteRoom : Node2D
|
|||
// WallIndex determines the offset *along* the edge of the room
|
||||
Vector2I offset = marker.Direction switch
|
||||
{
|
||||
RoomDirection.North or RoomDirection.South => new Vector2I(marker.WallIndex, 0),
|
||||
RoomDirection.East or RoomDirection.West => new Vector2I(0, marker.WallIndex),
|
||||
RoomDirection.North => new Vector2I(marker.WallIndex, 0),
|
||||
RoomDirection.South => new Vector2I(marker.WallIndex, RoomResource.Size.Y - 1),
|
||||
RoomDirection.East => new Vector2I(RoomResource.Size.X - 1, marker.WallIndex),
|
||||
RoomDirection.West => new Vector2I(0, marker.WallIndex),
|
||||
_ => Vector2I.Zero
|
||||
};
|
||||
|
||||
|
|
@ -56,17 +74,31 @@ public partial class RogueliteRoom : Node2D
|
|||
Vector2I doorEdge = GridPosition + offset;
|
||||
Vector2I neighborPos = doorEdge + baseDir;
|
||||
|
||||
bool connected = connectionChecker.Invoke(neighborPos);
|
||||
|
||||
var connection = connectionChecker.Invoke(doorEdge, neighborPos);
|
||||
|
||||
var connected = connection is not null;
|
||||
|
||||
if (connected)
|
||||
{
|
||||
var door = this.CreateChild<Door>(DoorPrefab, marker.GlobalPosition);
|
||||
|
||||
door.State = DoorState.Open;
|
||||
door.State = DoorState.Closed;
|
||||
|
||||
// var label = new Label();
|
||||
// label.Text = $"Door Edge: {doorEdge}, {connection}";
|
||||
// label.ZIndex = 10;
|
||||
//
|
||||
// door.AddChild(label);
|
||||
}
|
||||
else
|
||||
{
|
||||
var wall = this.CreateChild<Node2D>(WallPrefab, marker.GlobalPosition);
|
||||
|
||||
// var label = new Label();
|
||||
// label.Text = $"Door Edge: {doorEdge}, Neighbor: {neighborPos}";
|
||||
// label.ZIndex = 10;
|
||||
//
|
||||
// marker.AddChild(label);
|
||||
}
|
||||
|
||||
// PackedScene prefab = hasConnection
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue