namespace Content.Shared.Procedural;
///
/// Procedurally generated dungeon data.
///
public sealed class Dungeon
{
public static Dungeon Empty = new Dungeon();
private List _rooms;
private HashSet _allTiles = new();
public IReadOnlyList Rooms => _rooms;
///
/// Hashset of the tiles across all rooms.
///
public readonly HashSet RoomTiles = new();
public readonly HashSet RoomExteriorTiles = new();
public readonly HashSet CorridorTiles = new();
public readonly HashSet CorridorExteriorTiles = new();
public readonly HashSet Entrances = new();
public IReadOnlySet AllTiles => _allTiles;
public Dungeon() : this(new List())
{
}
public Dungeon(List rooms)
{
// This reftype is mine now.
_rooms = rooms;
foreach (var room in _rooms)
{
InternalAddRoom(room);
}
RefreshAllTiles();
}
public void RefreshAllTiles()
{
_allTiles.Clear();
_allTiles.UnionWith(RoomTiles);
_allTiles.UnionWith(RoomExteriorTiles);
_allTiles.UnionWith(CorridorTiles);
_allTiles.UnionWith(CorridorExteriorTiles);
_allTiles.UnionWith(Entrances);
}
public void Rebuild()
{
_allTiles.Clear();
RoomTiles.Clear();
RoomExteriorTiles.Clear();
Entrances.Clear();
foreach (var room in _rooms)
{
InternalAddRoom(room, false);
}
RefreshAllTiles();
}
public void AddRoom(DungeonRoom room)
{
_rooms.Add(room);
InternalAddRoom(room);
}
private void InternalAddRoom(DungeonRoom room, bool refreshAll = true)
{
Entrances.UnionWith(room.Entrances);
RoomTiles.UnionWith(room.Tiles);
RoomExteriorTiles.UnionWith(room.Exterior);
if (refreshAll)
RefreshAllTiles();
}
}