2using MPewsey.ManiaMap.Exceptions;
3using System.Collections.Generic;
12 [CreateAssetMenu(menuName =
"Mania Map/Room Database")]
16 private List<RoomComponent> _rooms =
new List<RoomComponent>();
20 public List<RoomComponent>
Rooms {
get => _rooms;
set => _rooms = value; }
25 private Dictionary<int, RoomComponent>
RoomsByTemplateId {
get; } =
new Dictionary<int, RoomComponent>();
30 public bool IsDirty {
get;
private set; } =
true;
37 private void OnValidate()
79 foreach (var room
in Rooms)
81 var
id = room.RoomTemplate.Id;
85 else if (room != storedRoom)
86 throw new DuplicateIdException($
"Duplicate room template ID: (ID = {id}, Room1 = {storedRoom}, Room2 = {room}).");
107 var room = layoutPack.
Layout.Rooms[id];
118 var result =
new List<RoomComponent>(layoutPack.
Layout.Rooms.Count);
120 foreach (var room
in layoutPack.Layout.Rooms.Values)
138 z ??= layoutPack.
Layout.Rooms.Values.Select(x => x.Position.Z).First();
139 var result =
new List<RoomComponent>();
141 foreach (var room
in layoutPack.Layout.Rooms.Values)
143 if (room.Position.Z == z)
A manager for maintaining the current map data and state.
A component for creating a room.
static RoomComponent InstantiateRoom(Uid id, LayoutPack layoutPack, GameObject prefab, Transform parent=null, bool assignLayoutPosition=false)
Instantiates and initializes a room and returns it.
A database of room prefabs.
List< RoomComponent > Rooms
A list of room prefabs.
RoomComponent InstantiateRoom(Uid id, LayoutPack layoutPack, Transform parent=null, bool assignLayoutPosition=false)
Instantiates the room with the specified ID.
List< RoomComponent > InstantiateRooms(LayoutPack layoutPack, int? z=null, Transform parent=null)
Instantiates the rooms in a layer of a layout and returns a list of them.
void PopulateRoomsByTemplateId()
Populates the room dictionary.
void PopulateIfDirty()
If the object is dirty, populates the room dictionary.
Dictionary< int, RoomComponent > RoomsByTemplateId
A dictionary of room prefabs by room template ID.
RoomComponent GetRoomPrefab(int id)
Returns the room prefab with the specified template ID.
IReadOnlyDictionary< int, RoomComponent > GetRoomsByTemplateId()
Returns the dictionary of rooms by room template ID.
List< RoomComponent > InstantiateAllRooms(LayoutPack layoutPack, Transform parent=null)
Instantiates all rooms in the layout and returns a list of them.
void MarkDirty()
Sets the object as dirty.
RoomComponent GetRoomPrefab(Uid id, LayoutPack layoutPack)
Returns the room prefab with the specified room ID.
bool IsDirty
If true, the database is dirty and requires population.