using Godot; using Godot.Collections; namespace DungeonSystem; [GlobalClass] public partial class Room : Node2D { public enum RoomType { Start, Combat, Shop, Treasure, Boss } [Export] public RoomType Type { get; set; } = RoomType.Combat; [Export] public RoomEncounterConfig? EncounterConfig { get; set; } public Area2D? RoomBounds => GetNodeOrNull("RoomBounds"); public CollisionShape2D? CollisionShape => GetNodeOrNull("RoomBounds/CollisionShape2D"); public Node2D? DoorsContainer => GetNodeOrNull("Doors"); public Array GetOpenDoors() { var openDoors = new Array(); var doors = DoorsContainer; if (doors == null) { GD.PrintErr($"[Room.cs] Missing 'Doors' child node in room scene: '{Name}' ({SceneFilePath})!"); return openDoors; } foreach (Node child in doors.GetChildren()) { // NEW: Only add the door if it is VISIBLE (Eye icon is open) if (child is Marker2D door && door.Visible) { bool isConnected = door.HasMeta("connected") && door.GetMeta("connected").AsBool(); if (!isConnected) { openDoors.Add(door); } } } return openDoors; } /// /// Dynamically calculates the room's global bounding rectangle directly from its TileMapLayer. /// public Rect2 GetRoomRect() { var tileMapLayer = GetNodeOrNull("TileMapLayer"); if (tileMapLayer == null || tileMapLayer.TileSet == null) { GD.PrintErr($"[Room.cs] Missing 'TileMapLayer' or 'TileSet' in scene: '{Name}'!"); return new Rect2(GlobalPosition, Vector2.Zero); } // Get the used rectangle in tile cell coordinates (e.g., Position = (-5, -5), Size = (10, 10)) Rect2I usedCellsRect = tileMapLayer.GetUsedRect(); Vector2 tileSize = tileMapLayer.TileSet.TileSize; // Find the top-left pixel position of the top-left tile Vector2 topLeftCellCenter = tileMapLayer.MapToLocal(usedCellsRect.Position); Vector2 topLeftPixelLocal = topLeftCellCenter - (tileSize / 2.0f); // Convert local pixel bounds to global world coordinates Vector2 globalPos = tileMapLayer.ToGlobal(topLeftPixelLocal); Vector2 globalSize = usedCellsRect.Size * tileSize; return new Rect2(globalPos, globalSize); } }