3using MPewsey.ManiaMap.Exceptions;
5using System.Collections.Generic;
7using System.Threading.Tasks;
29 private Dictionary<int, RoomTemplateResource>
RoomTemplates {
get; } =
new Dictionary<int, RoomTemplateResource>();
34 public bool IsDirty {
get;
private set; } =
true;
75 foreach (var entry
in group.Entries)
77 var
id = entry.RoomTemplate.Id;
81 else if (
template != entry.RoomTemplate)
82 throw new DuplicateIdException($
"Duplicate room template ID: {id}.");
104 var room = layoutPack.
Layout.Rooms[id];
112 private async Task<Dictionary<int, PackedScene>>
LoadScenesAsync(IEnumerable<Room> rooms,
bool useSubThreads =
false)
114 var tasks =
new Dictionary<int, Task<PackedScene>>();
116 foreach (var room
in rooms)
118 var
id = room.Template.Id;
120 if (!tasks.ContainsKey(
id))
124 await Task.WhenAll(tasks.Values);
125 var result =
new Dictionary<int, PackedScene>(tasks.Count);
127 foreach (var pair
in tasks)
129 result.Add(pair.Key, pair.Value.Result);
143 z ??= layoutPack.
Layout.Rooms.Values.Select(x => x.Position.Z).First();
144 var rooms = layoutPack.
Layout.Rooms.Values.Where(x => x.Position.Z == z).ToList();
146 var result =
new List<RoomNode2D>(rooms.Count);
148 foreach (var room
in rooms)
150 var scene = scenes[room.Template.Id];
164 var rooms = layoutPack.
Layout.Rooms.Values.ToList();
166 var result =
new List<RoomNode3D>(rooms.Count);
168 foreach (var room
in rooms)
170 var scene = scenes[room.Template.Id];
185 z ??= layoutPack.
Layout.Rooms.Values.Select(x => x.Position.Z).First();
186 var result =
new List<RoomNode2D>();
188 foreach (var room
in layoutPack.Layout.Rooms.Values)
190 if (room.Position.Z == z)
207 var result =
new List<RoomNode3D>();
209 foreach (var room
in layoutPack.Layout.Rooms.Values)
Holds the current Layout and LayoutState.
A node serving as the top level of a 2D room.
static RoomNode2D CreateInstance(Uid id, LayoutPack layoutPack, PackedScene scene, Node parent, bool assignLayoutPosition=false)
Creates and initializes an instance of a room. The layout and layout state are assigned to the room b...
A node serving as the top level of a 3D room.
static RoomNode3D CreateInstance(Uid id, LayoutPack layoutPack, PackedScene scene, Node parent, bool assignLayoutPosition=false)
Creates and initializes an instance of a room. The layout and layout state are assigned to the room b...
Provides lookup of RoomTemplateResource by ID and initialization methods for rooms.
List< RoomNode2D > CreateRoom2DInstances(Node parent, LayoutPack layoutPack, int? z=null)
Creates rooms at their layout positions for a layer of the current Layout. Returns a list of the inst...
async Task< RoomNode2D > CreateRoom2DInstanceAsync(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition=false, bool useSubThreads=false)
Asynchronously creates a room from the current Layout. Returns the instantiated room.
RoomNode2D CreateRoom2DInstance(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition=false)
Creates a room from the current Layout. Returns the instantiated room.
IReadOnlyDictionary< int, RoomTemplateResource > GetRoomTemplates()
Returns a read-only dictionary of room templates by ID.
async Task< RoomNode3D > CreateRoom3DInstanceAsync(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition=false, bool useSubThreads=false)
Asynchronously creates a room from the current Layout. Returns the instantiated room.
void PopulateIfDirty()
Populates the lookup dictionary if the room is marked as dirty.
Dictionary< int, RoomTemplateResource > RoomTemplates
A dictionary of room templates by ID.
TemplateGroup[] TemplateGroups
An array of template groups containing the rooms to include in queries.
RoomTemplateResource GetRoomTemplate(Uid id, LayoutPack layoutPack)
Returns the room template for the specified room ID. This method uses the layout from the current Man...
async Task< List< RoomNode3D > > CreateRoom3DInstancesAsync(Node parent, LayoutPack layoutPack, bool useSubThreads=false)
Asynchronously creates rooms at their layout positions for the current Layout. Returns a list of the ...
List< RoomNode3D > CreateRoom3DInstances(Node parent, LayoutPack layoutPack)
Creates rooms at their layout positions for the current Layout. Returns a list of the instantiated ro...
RoomNode3D CreateRoom3DInstance(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition=false)
Creates a room from the current Layout. Returns the instantiated room.
async Task< List< RoomNode2D > > CreateRoom2DInstancesAsync(Node parent, LayoutPack layoutPack, int? z=null, bool useSubThreads=false)
Asynchronously creates rooms at their layout positions for a layer of the current Layout....
async Task< Dictionary< int, PackedScene > > LoadScenesAsync(IEnumerable< Room > rooms, bool useSubThreads=false)
Loads the scenes for the specified rooms asynchronously and returns a dictionary of scenes by templat...
RoomTemplateResource GetRoomTemplate(int id)
Returns the room template for the specified ID.
void PopulateRoomTemplates()
Clears and populates the room templates dictionary.
void SetDirty()
Sets the database as dirty and requiring update.
bool IsDirty
True if the object is currently dirty and requires update.
Provides a reference to a room scene and information for the room required by the procedural generato...
PackedScene LoadScene()
Loads and returns the referenced scene.
Task< PackedScene > LoadSceneAsync(bool useSubThreads=false)
Asynchronously loads and returns the referenced scene.
A group of RoomTemplateResource and their procedural generation constraints.