77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace _Project.Scripts.LevelGenerating
|
|
{
|
|
public enum FloorKind
|
|
{
|
|
Generated,
|
|
Special
|
|
}
|
|
|
|
public class FloorData
|
|
{
|
|
public int Index;
|
|
public FloorKind Kind;
|
|
public int Seed;
|
|
public string SpecialId;
|
|
public int SizeModules;
|
|
|
|
public readonly List<Room> Rooms = new List<Room>();
|
|
public readonly Dictionary<Room, int> Depth = new Dictionary<Room, int>();
|
|
|
|
// Отрезки стен и дверные проёмы (заполняет ShellBuilder.Build)
|
|
public readonly List<WallRun> Walls = new List<WallRun>();
|
|
public readonly List<Doorway> Doorways = new List<Doorway>();
|
|
|
|
public Room Start;
|
|
public Room Lift;
|
|
|
|
// ---------- Выборки ----------
|
|
|
|
public IEnumerable<Room> Corridors => Rooms.Where(r => r.rt == RoomType.Corridor);
|
|
public IEnumerable<Room> PlayableRooms => Rooms.Where(r => r.rt != RoomType.Corridor);
|
|
public IEnumerable<Room> UnassignedRooms => Rooms.Where(r => r.rt == RoomType.Undefined);
|
|
public IEnumerable<Room> OfType(RoomType type) => Rooms.Where(r => r.rt == type);
|
|
public int GetDepth(Room room) => Depth.TryGetValue(room, out int d) ? d : -1;
|
|
|
|
// ---------- Изменение ----------
|
|
|
|
public void AddRoom(Room room, int depth)
|
|
{
|
|
Rooms.Add(room);
|
|
Depth[room] = depth;
|
|
|
|
if (room.rt == RoomType.Start) Start = room;
|
|
else if (room.rt == RoomType.Lift) Lift = room;
|
|
}
|
|
|
|
public void AddCorridor(Room corridor) => Rooms.Add(corridor);
|
|
|
|
public void Remove(Room room)
|
|
{
|
|
Rooms.Remove(room);
|
|
Depth.Remove(room);
|
|
if (Start == room) Start = null;
|
|
if (Lift == room) Lift = null;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
Rooms.Clear();
|
|
Depth.Clear();
|
|
Walls.Clear();
|
|
Doorways.Clear();
|
|
Start = null;
|
|
Lift = null;
|
|
}
|
|
|
|
// ---------- Фабрики ----------
|
|
|
|
public static FloorData CreateGenerated(int index, int sizeModules) =>
|
|
new FloorData { Index = index, Kind = FloorKind.Generated, SizeModules = sizeModules };
|
|
|
|
public static FloorData CreateSpecial(int index, string specialId) =>
|
|
new FloorData { Index = index, Kind = FloorKind.Special, SpecialId = specialId };
|
|
}
|
|
} |