diff --git a/addons/mpewsey.maniamap/scripts/runtime/IDoorNodeExtensions.cs b/addons/mpewsey.maniamap/scripts/runtime/IDoorNodeExtensions.cs index 3ebad1a..b9424cf 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/IDoorNodeExtensions.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/IDoorNodeExtensions.cs @@ -23,10 +23,11 @@ public static bool DoorExists(this IDoorNode door) public static DoorConnection FindDoorConnection(this IDoorNode door) { var roomId = door.RoomNode.RoomLayout.Id; + var doorConnections = door.RoomNode.LayoutPack.GetDoorConnections(roomId); var position = new Vector2DInt(door.Row, door.Column); var direction = door.DoorDirection; - foreach (var connection in door.RoomNode.DoorConnections) + foreach (var connection in doorConnections) { if (connection.ContainsDoor(roomId, position, direction)) return connection; diff --git a/addons/mpewsey.maniamap/scripts/runtime/IRoomNode.cs b/addons/mpewsey.maniamap/scripts/runtime/IRoomNode.cs index 8dfd994..551fb98 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/IRoomNode.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/IRoomNode.cs @@ -1,5 +1,4 @@ using MPewsey.ManiaMap; -using System.Collections.Generic; namespace MPewsey.ManiaMapGodot { @@ -29,14 +28,9 @@ public interface IRoomNode public Godot.Collections.Array> ActiveCells { get; set; } /// - /// The current layout. + /// The current layout pack. /// - public Layout Layout { get; } - - /// - /// The current layout state. - /// - public LayoutState LayoutState { get; } + public LayoutPack LayoutPack { get; } /// /// This room's layout. @@ -48,11 +42,6 @@ public interface IRoomNode /// public RoomState RoomState { get; } - /// - /// A list of door connections for the room. - /// - public IReadOnlyList DoorConnections { get; } - /// /// True if the room has been initialized. /// diff --git a/addons/mpewsey.maniamap/scripts/runtime/ManiaMapManager.cs b/addons/mpewsey.maniamap/scripts/runtime/LayoutPack.cs similarity index 57% rename from addons/mpewsey.maniamap/scripts/runtime/ManiaMapManager.cs rename to addons/mpewsey.maniamap/scripts/runtime/LayoutPack.cs index af00b76..2ac52b7 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/ManiaMapManager.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/LayoutPack.cs @@ -8,54 +8,49 @@ namespace MPewsey.ManiaMapGodot /// /// Holds the current `Layout` and `LayoutState`. /// - public partial class ManiaMapManager : GodotObject + public class LayoutPack { /// - /// The current manager. + /// The layout. /// - public static ManiaMapManager Current { get; private set; } + public Layout Layout { get; } /// - /// The current layout. + /// The layout state. /// - public Layout Layout { get; private set; } + public LayoutState LayoutState { get; } /// - /// The current layout state. + /// The settings. /// - public LayoutState LayoutState { get; private set; } - - /// - /// The current settings. - /// - public ManiaMapSettings Settings { get; private set; } + public ManiaMapSettings Settings { get; } /// /// A dictionary of door connections by room ID. /// - private Dictionary> RoomConnections { get; set; } = new Dictionary>(); + private Dictionary> RoomConnections { get; } = new Dictionary>(); /// - /// Initializes a new manager and sets it as the current manager. + /// Initializes a new layout pack. /// /// The layout. /// The layout state. /// The path to the ManiaMapSettings resource. - public static ManiaMapManager Initialize(Layout layout, LayoutState state, string settingsPath) + public LayoutPack(Layout layout, LayoutState state, string settingsPath) + : this(layout, state, ResourceLoader.Load(settingsPath)) { - var settings = ResourceLoader.Load(settingsPath); - return Initialize(layout, state, settings); + } /// - /// Initializes a new manager and sets it as the current manager. + /// Initializes a new layout pack. /// /// The layout. /// The layout state. /// The settings resource. If null, a new default instance of the settings will be used. /// Thrown if the layout or layout state is null. /// Thrown if the layout and layout state ID's do not match. - public static ManiaMapManager Initialize(Layout layout, LayoutState state, ManiaMapSettings settings = null) + public LayoutPack(Layout layout, LayoutState state, ManiaMapSettings settings = null) { ArgumentNullException.ThrowIfNull(layout, nameof(layout)); ArgumentNullException.ThrowIfNull(state, nameof(state)); @@ -63,24 +58,10 @@ public static ManiaMapManager Initialize(Layout layout, LayoutState state, Mania if (layout.Id != state.Id) throw new ArgumentException($"Layout and layout state ID's do not match: (Layout ID = {layout.Id}, Layout State ID = {state.Id})"); - var manager = new ManiaMapManager() - { - Layout = layout, - LayoutState = state, - Settings = settings ?? new ManiaMapSettings(), - RoomConnections = layout.GetRoomConnections(), - }; - - manager.SetAsCurrent(); - return manager; - } - - /// - /// Assigns the manager to the current manager static property. - /// - private void SetAsCurrent() - { - Current = this; + Layout = layout; + LayoutState = state; + Settings = settings; + RoomConnections = layout.GetRoomConnections(); } /// diff --git a/addons/mpewsey.maniamap/scripts/runtime/RoomNode2D.cs b/addons/mpewsey.maniamap/scripts/runtime/RoomNode2D.cs index b5c89f9..bade796 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/RoomNode2D.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/RoomNode2D.cs @@ -2,7 +2,6 @@ using MPewsey.ManiaMap; using MPewsey.ManiaMapGodot.Exceptions; using System; -using System.Collections.Generic; namespace MPewsey.ManiaMapGodot { @@ -59,10 +58,7 @@ public partial class RoomNode2D : Node2D, IRoomNode [Export] public Godot.Collections.Array> ActiveCells { get; set; } = new Godot.Collections.Array>(); /// - public Layout Layout { get; private set; } - - /// - public LayoutState LayoutState { get; private set; } + public LayoutPack LayoutPack { get; private set; } /// public Room RoomLayout { get; private set; } @@ -70,9 +66,6 @@ public partial class RoomNode2D : Node2D, IRoomNode /// public RoomState RoomState { get; private set; } - /// - public IReadOnlyList DoorConnections { get; private set; } = Array.Empty(); - /// public bool IsInitialized { get; private set; } @@ -182,19 +175,16 @@ private static bool MouseIsInsideMainScreen() /// The layout and layout state are assigned to the room based on the current ManiaMapManager. /// /// The room ID. + /// The layout pack. /// The room scene. /// The node to which the room will be added as a child. /// If true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position. - public static RoomNode2D CreateInstance(Uid id, PackedScene scene, Node parent, bool assignLayoutPosition = false) + public static RoomNode2D CreateInstance(Uid id, LayoutPack layoutPack, PackedScene scene, Node parent, bool assignLayoutPosition = false) { - var manager = ManiaMapManager.Current; - var layout = manager.Layout; - var layoutState = manager.LayoutState; - var roomLayout = layout.Rooms[id]; - var roomState = layoutState.RoomStates[id]; - var doorConnections = manager.GetDoorConnections(id); - var collisionMask = manager.Settings.CellCollisionMask; - return CreateInstance(scene, parent, layout, layoutState, roomLayout, roomState, doorConnections, collisionMask, assignLayoutPosition); + var roomLayout = layoutPack.Layout.Rooms[id]; + var roomState = layoutPack.LayoutState.RoomStates[id]; + var collisionMask = layoutPack.Settings.CellCollisionMask; + return CreateInstance(scene, parent, layoutPack, roomLayout, roomState, collisionMask, assignLayoutPosition); } /// @@ -202,19 +192,16 @@ public static RoomNode2D CreateInstance(Uid id, PackedScene scene, Node parent, /// /// The room scene. /// The node to which the room will be added as a child. - /// The full layout. - /// The full layout state. + /// The layout pack.. /// The room's layout. /// The room's state. - /// The room's door connections. /// The cell collision mask. /// If true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position. - public static RoomNode2D CreateInstance(PackedScene scene, Node parent, Layout layout, LayoutState layoutState, - Room roomLayout, RoomState roomState, IReadOnlyList doorConnections, - uint cellCollisionMask, bool assignLayoutPosition) + public static RoomNode2D CreateInstance(PackedScene scene, Node parent, LayoutPack layoutPack, + Room roomLayout, RoomState roomState, uint cellCollisionMask, bool assignLayoutPosition) { var room = scene.Instantiate(); - room.Initialize(layout, layoutState, roomLayout, roomState, doorConnections, cellCollisionMask, assignLayoutPosition); + room.Initialize(layoutPack, roomLayout, roomState, cellCollisionMask, assignLayoutPosition); parent.AddChild(room); return room; } @@ -226,24 +213,20 @@ public static RoomNode2D CreateInstance(PackedScene scene, Node parent, Layout l /// If the room has already been initialized, no action is taken, and this method returns false. /// Othwerwise, it returns true. /// - /// The full layout. - /// The full layout state. + /// The layout pack. /// The room's layout. /// The room's state. - /// The room's door connections. /// The cell collision mask. /// If true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position. - public bool Initialize(Layout layout, LayoutState layoutState, Room roomLayout, RoomState roomState, - IReadOnlyList doorConnections, uint cellCollisionMask, bool assignLayoutPosition) + public bool Initialize(LayoutPack layoutPack, Room roomLayout, RoomState roomState, + uint cellCollisionMask, bool assignLayoutPosition) { if (IsInitialized) return false; - Layout = layout; - LayoutState = layoutState; + LayoutPack = layoutPack; RoomLayout = roomLayout; RoomState = roomState; - DoorConnections = doorConnections; if (assignLayoutPosition) MoveToLayoutPosition(); diff --git a/addons/mpewsey.maniamap/scripts/runtime/RoomNode3D.cs b/addons/mpewsey.maniamap/scripts/runtime/RoomNode3D.cs index ab31396..e466c00 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/RoomNode3D.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/RoomNode3D.cs @@ -2,7 +2,6 @@ using MPewsey.ManiaMap; using MPewsey.ManiaMapGodot.Exceptions; using System; -using System.Collections.Generic; namespace MPewsey.ManiaMapGodot { @@ -59,10 +58,7 @@ public partial class RoomNode3D : Node3D, IRoomNode [Export] public Godot.Collections.Array> ActiveCells { get; set; } = new Godot.Collections.Array>(); /// - public Layout Layout { get; private set; } - - /// - public LayoutState LayoutState { get; private set; } + public LayoutPack LayoutPack { get; private set; } /// public Room RoomLayout { get; private set; } @@ -70,9 +66,6 @@ public partial class RoomNode3D : Node3D, IRoomNode /// public RoomState RoomState { get; private set; } - /// - public IReadOnlyList DoorConnections { get; private set; } = Array.Empty(); - /// public bool IsInitialized { get; private set; } @@ -200,19 +193,16 @@ private static bool MouseIsInsideMainScreen() /// The layout and layout state are assigned to the room based on the current ManiaMapManager. /// /// The room ID. + /// The layout pack. /// The room scene. /// The node to which the room will be added as a child. /// If true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position. - public static RoomNode3D CreateInstance(Uid id, PackedScene scene, Node parent, bool assignLayoutPosition = false) + public static RoomNode3D CreateInstance(Uid id, LayoutPack layoutPack, PackedScene scene, Node parent, bool assignLayoutPosition = false) { - var manager = ManiaMapManager.Current; - var layout = manager.Layout; - var layoutState = manager.LayoutState; - var roomLayout = layout.Rooms[id]; - var roomState = layoutState.RoomStates[id]; - var doorConnections = manager.GetDoorConnections(id); - var collisionMask = manager.Settings.CellCollisionMask; - return CreateInstance(scene, parent, layout, layoutState, roomLayout, roomState, doorConnections, collisionMask, assignLayoutPosition); + var roomLayout = layoutPack.Layout.Rooms[id]; + var roomState = layoutPack.LayoutState.RoomStates[id]; + var collisionMask = layoutPack.Settings.CellCollisionMask; + return CreateInstance(scene, parent, layoutPack, roomLayout, roomState, collisionMask, assignLayoutPosition); } /// @@ -227,12 +217,11 @@ public static RoomNode3D CreateInstance(Uid id, PackedScene scene, Node parent, /// The room's door connections. /// The cell collision mask. /// If true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position. - public static RoomNode3D CreateInstance(PackedScene scene, Node parent, Layout layout, LayoutState layoutState, - Room roomLayout, RoomState roomState, IReadOnlyList doorConnections, - uint cellCollisionMask, bool assignLayoutPosition) + public static RoomNode3D CreateInstance(PackedScene scene, Node parent, LayoutPack layoutPack, + Room roomLayout, RoomState roomState, uint cellCollisionMask, bool assignLayoutPosition) { var room = scene.Instantiate(); - room.Initialize(layout, layoutState, roomLayout, roomState, doorConnections, cellCollisionMask, assignLayoutPosition); + room.Initialize(layoutPack, roomLayout, roomState, cellCollisionMask, assignLayoutPosition); parent.AddChild(room); return room; } @@ -251,17 +240,15 @@ public static RoomNode3D CreateInstance(PackedScene scene, Node parent, Layout l /// The room's door connections. /// The cell collision mask. /// If true, the position of the room will be set to that of the room layout. Otherwise, it will be initialized at its original position. - public bool Initialize(Layout layout, LayoutState layoutState, Room roomLayout, RoomState roomState, - IReadOnlyList doorConnections, uint cellCollisionMask, bool assignLayoutPosition) + public bool Initialize(LayoutPack layoutPack, Room roomLayout, RoomState roomState, + uint cellCollisionMask, bool assignLayoutPosition) { if (IsInitialized) return false; - Layout = layout; - LayoutState = layoutState; + LayoutPack = layoutPack; RoomLayout = roomLayout; RoomState = roomState; - DoorConnections = doorConnections; if (assignLayoutPosition) MoveToLayoutPosition(); diff --git a/addons/mpewsey.maniamap/scripts/runtime/RoomTemplateDatabase.cs b/addons/mpewsey.maniamap/scripts/runtime/RoomTemplateDatabase.cs index 3e3f606..21c8af4 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/RoomTemplateDatabase.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/RoomTemplateDatabase.cs @@ -99,10 +99,9 @@ public RoomTemplateResource GetRoomTemplate(int id) /// This method uses the layout from the current ManiaMapManager. /// /// The room ID. - public RoomTemplateResource GetRoomTemplate(Uid id) + public RoomTemplateResource GetRoomTemplate(Uid id, LayoutPack layoutPack) { - var manager = ManiaMapManager.Current; - var room = manager.Layout.Rooms[id]; + var room = layoutPack.Layout.Rooms[id]; return GetRoomTemplate(room.Template.Id); } @@ -139,18 +138,17 @@ private async Task> LoadScenesAsync(IEnumerable /// The node serving as the parent of the rooms. /// The layer coordinate to instantiate. - public async Task> CreateRoom2DInstancesAsync(Node parent, int? z = null, bool useSubThreads = false) + public async Task> CreateRoom2DInstancesAsync(Node parent, LayoutPack layoutPack, int? z = null, bool useSubThreads = false) { - var manager = ManiaMapManager.Current; - z ??= manager.Layout.Rooms.Values.Select(x => x.Position.Z).First(); - var rooms = manager.Layout.Rooms.Values.Where(x => x.Position.Z == z).ToList(); + z ??= layoutPack.Layout.Rooms.Values.Select(x => x.Position.Z).First(); + var rooms = layoutPack.Layout.Rooms.Values.Where(x => x.Position.Z == z).ToList(); var scenes = await LoadScenesAsync(rooms, useSubThreads); var result = new List(rooms.Count); foreach (var room in rooms) { var scene = scenes[room.Template.Id]; - result.Add(RoomNode2D.CreateInstance(room.Id, scene, parent, true)); + result.Add(RoomNode2D.CreateInstance(room.Id, layoutPack, scene, parent, true)); } return result; @@ -161,17 +159,16 @@ public async Task> CreateRoom2DInstancesAsync(Node parent, int? /// Returns a list of the instantiated rooms. /// /// The node serving as the parent of the rooms. - public async Task> CreateRoom3DInstancesAsync(Node parent, bool useSubThreads = false) + public async Task> CreateRoom3DInstancesAsync(Node parent, LayoutPack layoutPack, bool useSubThreads = false) { - var manager = ManiaMapManager.Current; - var rooms = manager.Layout.Rooms.Values.ToList(); + var rooms = layoutPack.Layout.Rooms.Values.ToList(); var scenes = await LoadScenesAsync(rooms, useSubThreads); var result = new List(rooms.Count); foreach (var room in rooms) { var scene = scenes[room.Template.Id]; - result.Add(RoomNode3D.CreateInstance(room.Id, scene, parent, true)); + result.Add(RoomNode3D.CreateInstance(room.Id, layoutPack, scene, parent, true)); } return result; @@ -183,18 +180,17 @@ public async Task> CreateRoom3DInstancesAsync(Node parent, bool /// /// The node serving as the parent of the rooms. /// The layer coordinate to instantiate. - public List CreateRoom2DInstances(Node parent, int? z = null) + public List CreateRoom2DInstances(Node parent, LayoutPack layoutPack, int? z = null) { - var manager = ManiaMapManager.Current; - z ??= manager.Layout.Rooms.Values.Select(x => x.Position.Z).First(); + z ??= layoutPack.Layout.Rooms.Values.Select(x => x.Position.Z).First(); var result = new List(); - foreach (var room in manager.Layout.Rooms.Values) + foreach (var room in layoutPack.Layout.Rooms.Values) { if (room.Position.Z == z) { var template = GetRoomTemplate(room.Template.Id); - result.Add(RoomNode2D.CreateInstance(room.Id, template.LoadScene(), parent, true)); + result.Add(RoomNode2D.CreateInstance(room.Id, layoutPack, template.LoadScene(), parent, true)); } } @@ -206,15 +202,14 @@ public List CreateRoom2DInstances(Node parent, int? z = null) /// Returns a list of the instantiated rooms. /// /// The node serving as the parent of the rooms. - public List CreateRoom3DInstances(Node parent) + public List CreateRoom3DInstances(Node parent, LayoutPack layoutPack) { - var manager = ManiaMapManager.Current; var result = new List(); - foreach (var room in manager.Layout.Rooms.Values) + foreach (var room in layoutPack.Layout.Rooms.Values) { var template = GetRoomTemplate(room.Template.Id); - result.Add(RoomNode3D.CreateInstance(room.Id, template.LoadScene(), parent, true)); + result.Add(RoomNode3D.CreateInstance(room.Id, layoutPack, template.LoadScene(), parent, true)); } return result; @@ -227,10 +222,10 @@ public List CreateRoom3DInstances(Node parent) /// The room ID. /// The node serving as the room's parent. /// If true, the layout position will be assigned to the room. - public async Task CreateRoom2DInstanceAsync(Uid id, Node parent, bool assignLayoutPosition = false, bool useSubThreads = false) + public async Task CreateRoom2DInstanceAsync(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition = false, bool useSubThreads = false) { - var scene = await GetRoomTemplate(id).LoadSceneAsync(useSubThreads); - return RoomNode2D.CreateInstance(id, scene, parent, assignLayoutPosition); + var scene = await GetRoomTemplate(id, layoutPack).LoadSceneAsync(useSubThreads); + return RoomNode2D.CreateInstance(id, layoutPack, scene, parent, assignLayoutPosition); } /// @@ -240,10 +235,10 @@ public async Task CreateRoom2DInstanceAsync(Uid id, Node parent, boo /// The room ID. /// The node serving as the room's parent. /// If true, the layout position will be assigned to the room. - public async Task CreateRoom3DInstanceAsync(Uid id, Node parent, bool assignLayoutPosition = false, bool useSubThreads = false) + public async Task CreateRoom3DInstanceAsync(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition = false, bool useSubThreads = false) { - var scene = await GetRoomTemplate(id).LoadSceneAsync(useSubThreads); - return RoomNode3D.CreateInstance(id, scene, parent, assignLayoutPosition); + var scene = await GetRoomTemplate(id, layoutPack).LoadSceneAsync(useSubThreads); + return RoomNode3D.CreateInstance(id, layoutPack, scene, parent, assignLayoutPosition); } /// @@ -253,9 +248,10 @@ public async Task CreateRoom3DInstanceAsync(Uid id, Node parent, boo /// The room ID. /// The node serving as the room's parent. /// If true, the layout position will be assigned to the room. - public RoomNode2D CreateRoom2DInstance(Uid id, Node parent, bool assignLayoutPosition = false) + public RoomNode2D CreateRoom2DInstance(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition = false) { - return RoomNode2D.CreateInstance(id, GetRoomTemplate(id).LoadScene(), parent, assignLayoutPosition); + var scene = GetRoomTemplate(id, layoutPack).LoadScene(); + return RoomNode2D.CreateInstance(id, layoutPack, scene, parent, assignLayoutPosition); } /// @@ -265,9 +261,10 @@ public RoomNode2D CreateRoom2DInstance(Uid id, Node parent, bool assignLayoutPos /// The room ID. /// The node serving as the room's parent. /// If true, the layout position will be assigned to the room. - public RoomNode3D CreateRoom3DInstance(Uid id, Node parent, bool assignLayoutPosition = false) + public RoomNode3D CreateRoom3DInstance(Uid id, LayoutPack layoutPack, Node parent, bool assignLayoutPosition = false) { - return RoomNode3D.CreateInstance(id, GetRoomTemplate(id).LoadScene(), parent, assignLayoutPosition); + var scene = GetRoomTemplate(id, layoutPack).LoadScene(); + return RoomNode3D.CreateInstance(id, layoutPack, scene, parent, assignLayoutPosition); } } } \ No newline at end of file diff --git a/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMap.cs b/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMap.cs index edaaad7..47016b8 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMap.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMap.cs @@ -28,13 +28,13 @@ protected override void Initialize(Layout layout, LayoutState layoutState) } /// - /// Draws the map for the specified layer (z) coordinate based on the current ManiaMapManager layout. + /// Draws the map for the specified layer (z) coordinate. /// + /// The layout pack. /// The layer coordinate. If null, the minimum layer coordinate in the layout will be used. - public void DrawMap(int? z = null) + public void DrawMap(LayoutPack layoutPack, int? z = null) { - var manager = ManiaMapManager.Current; - DrawMap(manager.Layout, manager.LayoutState, z); + DrawMap(layoutPack.Layout, layoutPack.LayoutState, z); } /// diff --git a/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMapBook.cs b/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMapBook.cs index 24ce114..8c222ec 100644 --- a/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMapBook.cs +++ b/addons/mpewsey.maniamap/scripts/runtime/drawing/LayoutTileMapBook.cs @@ -41,17 +41,19 @@ protected override void Initialize(Layout layout, LayoutState layoutState) } /// - /// Draws all layout layers onto tile maps using the ManiaMapManager layout. + /// Draws all layout layers onto tile maps. /// - public void DrawPages() + /// The layout pack. + public void DrawPages(LayoutPack layoutPack) { - var manager = ManiaMapManager.Current; - DrawPages(manager.Layout, manager.LayoutState); + DrawPages(layoutPack.Layout, layoutPack.LayoutState); } /// /// Draws all layout layers onto tile maps. /// + /// The layout. + /// The layout state. If null, the full map will be drawn. Otherwise, the layout state cell visibilities will be applied. public void DrawPages(Layout layout, LayoutState layoutState = null) { Initialize(layout, layoutState); diff --git a/samples/scripts/RoomLayout2DSample.cs b/samples/scripts/RoomLayout2DSample.cs index 62df1f1..bafc8ae 100644 --- a/samples/scripts/RoomLayout2DSample.cs +++ b/samples/scripts/RoomLayout2DSample.cs @@ -53,9 +53,9 @@ private async void GenerateLayoutAsync() MessageLabel.Text = string.Empty; var layout = results.GetOutput("Layout"); - ManiaMapManager.Initialize(layout, new LayoutState(layout), new ManiaMapSettings()); + var layoutPack = new LayoutPack(layout, new LayoutState(layout), new ManiaMapSettings()); ClearContainer(); - RoomTemplateDatabase.CreateRoom2DInstances(Container); + RoomTemplateDatabase.CreateRoom2DInstances(Container, layoutPack); Camera.CenterCameraView(layout, CellSize); } } diff --git a/samples/scripts/RoomLayout3DSample.cs b/samples/scripts/RoomLayout3DSample.cs index 7270928..df05105 100644 --- a/samples/scripts/RoomLayout3DSample.cs +++ b/samples/scripts/RoomLayout3DSample.cs @@ -53,9 +53,9 @@ private async void GenerateLayoutAsync() MessageLabel.Text = string.Empty; var layout = results.GetOutput("Layout"); - ManiaMapManager.Initialize(layout, new LayoutState(layout), new ManiaMapSettings()); + var layoutPack = new LayoutPack(layout, new LayoutState(layout), new ManiaMapSettings()); ClearContainer(); - RoomTemplateDatabase.CreateRoom3DInstances(Container); + RoomTemplateDatabase.CreateRoom3DInstances(Container, layoutPack); Camera.ResetPosition(); } } diff --git a/tests/scripts/TestRoomNode2D.cs b/tests/scripts/TestRoomNode2D.cs index 62ef872..4e48ec0 100644 --- a/tests/scripts/TestRoomNode2D.cs +++ b/tests/scripts/TestRoomNode2D.cs @@ -142,9 +142,9 @@ public void TestRoomFlag() var state = new LayoutState(layout); var roomId = layout.Rooms.Keys.First(); var roomState = state.RoomStates[roomId]; - ManiaMapManager.Initialize(layout, state, new ManiaMapSettings()); + var layoutPack = new LayoutPack(layout, state, new ManiaMapSettings()); - var room = database.CreateRoom2DInstance(roomId, root); + var room = database.CreateRoom2DInstance(roomId, layoutPack, root); var roomFlags = room.FindChildren("*", nameof(RoomFlag2D), true, false); Assertions.AssertThat(roomFlags.Count).IsGreater(0); var roomFlag = roomFlags[0] as RoomFlag2D; @@ -189,11 +189,11 @@ public async Task TestOnAreaEnteredCellArea() var state = new LayoutState(layout); var roomId = layout.Rooms.Keys.First(); var roomState = state.RoomStates[roomId]; - ManiaMapManager.Initialize(layout, state, settings); + var layoutPack = new LayoutPack(layout, state, settings); // Create room and hook up signals to detect the cells the test area is touching. var database = ResourceLoader.Load(RoomTemplateDatabase); - var room = database.CreateRoom2DInstance(roomId, root); + var room = database.CreateRoom2DInstance(roomId, layoutPack, root); var cellSize = room.CellSize; room.OnCellAreaEntered += (area, collision) => indexes.Add(new Vector2(area.Row, area.Column)); room.OnCellAreaExited += (area, collision) => indexes.Remove(new Vector2(area.Row, area.Column)); diff --git a/tests/scripts/TestRoomNode3D.cs b/tests/scripts/TestRoomNode3D.cs index 5968065..571ab93 100644 --- a/tests/scripts/TestRoomNode3D.cs +++ b/tests/scripts/TestRoomNode3D.cs @@ -150,9 +150,9 @@ public void TestRoomFlag() var state = new LayoutState(layout); var roomId = layout.Rooms.Keys.First(); var roomState = state.RoomStates[roomId]; - ManiaMapManager.Initialize(layout, state, new ManiaMapSettings()); + var layoutPack = new LayoutPack(layout, state, new ManiaMapSettings()); - var room = database.CreateRoom3DInstance(roomId, root); + var room = database.CreateRoom3DInstance(roomId, layoutPack, root); var roomFlags = room.FindChildren("*", nameof(RoomFlag3D), true, false); Assertions.AssertThat(roomFlags.Count).IsGreater(0); var roomFlag = roomFlags[0] as RoomFlag3D; @@ -197,11 +197,11 @@ public async Task TestOnAreaEnteredCellArea() var state = new LayoutState(layout); var roomId = layout.Rooms.Keys.First(); var roomState = state.RoomStates[roomId]; - ManiaMapManager.Initialize(layout, state, settings); + var layoutPack = new LayoutPack(layout, state, settings); // Create room and hook up signals to detect the cells the test area is touching. var database = ResourceLoader.Load(RoomTemplateDatabase); - var room = database.CreateRoom3DInstance(roomId, root); + var room = database.CreateRoom3DInstance(roomId, layoutPack, root); var cellSize = room.CellSize; room.OnCellAreaEntered += (area, collision) => indexes.Add(new Vector2(area.Row, area.Column)); room.OnCellAreaExited += (area, collision) => indexes.Remove(new Vector2(area.Row, area.Column)); diff --git a/tests/scripts/drawing/TestLayoutTileMap.cs b/tests/scripts/drawing/TestLayoutTileMap.cs index 281327d..71315d9 100644 --- a/tests/scripts/drawing/TestLayoutTileMap.cs +++ b/tests/scripts/drawing/TestLayoutTileMap.cs @@ -22,8 +22,8 @@ public void TestDrawMap() var layout = results.GetOutput("Layout"); var layoutState = new LayoutState(layout); - ManiaMapManager.Initialize(layout, layoutState); - map.DrawMap(); + var layoutPack = new LayoutPack(layout, layoutState); + map.DrawMap(layoutPack); } } } diff --git a/tests/scripts/drawing/TestLayoutTileMapBook.cs b/tests/scripts/drawing/TestLayoutTileMapBook.cs index 2682214..b92213e 100644 --- a/tests/scripts/drawing/TestLayoutTileMapBook.cs +++ b/tests/scripts/drawing/TestLayoutTileMapBook.cs @@ -22,8 +22,8 @@ public void TestDrawMap() var layout = results.GetOutput("Layout"); var layoutState = new LayoutState(layout); - ManiaMapManager.Initialize(layout, layoutState); - map.DrawPages(); + var layoutPack = new LayoutPack(layout, layoutState); + map.DrawPages(layoutPack); } } }