mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 09:35:55 +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
|
||||
|
|
|
|||
|
|
@ -126,8 +126,6 @@ public partial class RogueliteRoomManager : Node2D
|
|||
break;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
_mainPath.Add(nextPos);
|
||||
|
||||
// Place cursor at bottom of room
|
||||
|
|
@ -174,10 +172,11 @@ public partial class RogueliteRoomManager : Node2D
|
|||
foreach (var roomEntry in _roomGrid)
|
||||
{
|
||||
var room = roomEntry.Value;
|
||||
room.HandleDoors(pos =>
|
||||
room.HandleDoors((doorEdge, pos) =>
|
||||
{
|
||||
var neighborPos = room.GridPosition + pos;
|
||||
return _roomGrid.ContainsKey(neighborPos);
|
||||
//var neighborPos = room.GridPosition + pos;
|
||||
return _connections.FirstOrDefault(x => (x.From == doorEdge && x.To == pos) || (x.From == pos && x.To == doorEdge));
|
||||
//return _roomGrid.ContainsKey(neighborPos);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -413,20 +412,4 @@ public partial class RogueliteRoomManager : Node2D
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RoomConnection
|
||||
{
|
||||
public Vector2I From;
|
||||
public Vector2I To;
|
||||
public bool IsLocked;
|
||||
public bool IsSecret;
|
||||
|
||||
public RoomConnection(Vector2I from, Vector2I to, bool isLocked = false, bool isSecret = false)
|
||||
{
|
||||
From = from;
|
||||
To = to;
|
||||
IsLocked = isLocked;
|
||||
IsSecret = isSecret;
|
||||
}
|
||||
}
|
||||
24
Scripts/Controllers/RoomConnection.cs
Normal file
24
Scripts/Controllers/RoomConnection.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Controllers;
|
||||
|
||||
public class RoomConnection
|
||||
{
|
||||
public Vector2I From;
|
||||
public Vector2I To;
|
||||
public bool IsLocked;
|
||||
public bool IsSecret;
|
||||
|
||||
public RoomConnection(Vector2I from, Vector2I to, bool isLocked = false, bool isSecret = false)
|
||||
{
|
||||
From = from;
|
||||
To = to;
|
||||
IsLocked = isLocked;
|
||||
IsSecret = isSecret;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"From {From} to {To}, IsLocked: {IsLocked}, IsSecret: {IsSecret}";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue