diff --git a/src/ManiaMap.Tests/Drawing/TestLayoutMap.cs b/src/ManiaMap.Tests/Drawing/TestLayoutMap.cs index 94cca3c1..423b7492 100644 --- a/src/ManiaMap.Tests/Drawing/TestLayoutMap.cs +++ b/src/ManiaMap.Tests/Drawing/TestLayoutMap.cs @@ -12,7 +12,7 @@ public class TestLayoutMap [TestMethod] public void TestSaveManiaMapImages() { - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = Samples.ManiaMapSample.ManiaMapLayout(Console.WriteLine); Assert.IsNotNull(layout); diff --git a/src/ManiaMap.Tests/Generators/TestCollectableGenerator.cs b/src/ManiaMap.Tests/Generators/TestCollectableGenerator.cs index 23d35175..bf78443b 100644 --- a/src/ManiaMap.Tests/Generators/TestCollectableGenerator.cs +++ b/src/ManiaMap.Tests/Generators/TestCollectableGenerator.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using MPewsey.Common.Random; using MPewsey.ManiaMap.Exceptions; +using System; using System.Collections.Generic; namespace MPewsey.ManiaMap.Generators.Tests @@ -24,7 +25,7 @@ public void TestGenerateLayoutForBigLayout() Assert.IsNotNull(layout); var collectableGenerator = new CollectableGenerator(); - collectableGenerator.Generate(layout, collectableGroups, random); + collectableGenerator.Generate(layout, collectableGroups, random, Console.WriteLine); var result = new List(); foreach (var room in layout.Rooms.Values) @@ -51,7 +52,7 @@ public void TestCollectableSpotNotFound() Assert.IsNotNull(layout); var collectableGenerator = new CollectableGenerator(); - Assert.ThrowsException(() => collectableGenerator.Generate(layout, collectableGroups, random)); + Assert.ThrowsException(() => collectableGenerator.Generate(layout, collectableGroups, random, Console.WriteLine)); } [TestMethod] diff --git a/src/ManiaMap.Tests/Generators/TestLayoutGenerator.cs b/src/ManiaMap.Tests/Generators/TestLayoutGenerator.cs index 5155a4b5..e0f86a12 100644 --- a/src/ManiaMap.Tests/Generators/TestLayoutGenerator.cs +++ b/src/ManiaMap.Tests/Generators/TestLayoutGenerator.cs @@ -1,5 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using MPewsey.Common.Logging; using MPewsey.Common.Random; using MPewsey.ManiaMap.Exceptions; using MPewsey.ManiaMap.Samples; @@ -18,18 +17,14 @@ public class TestLayoutGenerator public void TestCancellationToken() { var log = new List(); - Logger.RemoveAllListeners(); - Logger.AddListener(log.Add); - Logger.AddListener(Console.WriteLine); var token = new CancellationTokenSource(20).Token; var random = new RandomSeed(12345); var graph = Samples.GraphLibrary.BigGraph(); var templateGroups = Samples.BigLayoutSample.BigLayoutTemplateGroups(); var generator = new LayoutGenerator(); - var layout = generator.Generate(1, graph, templateGroups, random, token); + var layout = generator.Generate(1, graph, templateGroups, random, log.Add, token); - Logger.RemoveAllListeners(); Assert.IsTrue(log.Count > 0); Assert.IsTrue(log[log.Count - 1].Contains("Process cancelled")); Assert.IsNull(layout); @@ -38,17 +33,14 @@ public void TestCancellationToken() [TestMethod] public void TestHyperSquareCrossLayout() { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - - var graph = Samples.GraphLibrary.CrossGraph(); + var graph = GraphLibrary.CrossGraph(); var templateGroups = new TemplateGroups(); - templateGroups.Add("Default", Samples.TemplateLibrary.Miscellaneous.HyperSquareTemplate()); + templateGroups.Add("Default", TemplateLibrary.Miscellaneous.HyperSquareTemplate()); var generator = new LayoutGenerator(); var random = new RandomSeed(12345); - var layout = generator.Generate(1, graph, templateGroups, random); + var layout = generator.Generate(1, graph, templateGroups, random, Console.WriteLine); Assert.IsNotNull(layout); @@ -65,17 +57,14 @@ public void TestHyperSquareCrossLayout() [TestMethod] public void TestHyperSquareStackedLoopLayout() { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - - var graph = Samples.GraphLibrary.StackedLoopGraph(); + var graph = GraphLibrary.StackedLoopGraph(); var templateGroups = new TemplateGroups(); - templateGroups.Add("Default", Samples.TemplateLibrary.Miscellaneous.HyperSquareTemplate()); + templateGroups.Add("Default", TemplateLibrary.Miscellaneous.HyperSquareTemplate()); var generator = new LayoutGenerator(); var random = new RandomSeed(12345); - var layout = generator.Generate(1, graph, templateGroups, random); + var layout = generator.Generate(1, graph, templateGroups, random, Console.WriteLine); Assert.IsNotNull(layout); @@ -92,18 +81,15 @@ public void TestHyperSquareStackedLoopLayout() [TestMethod] public void TestLLoopLayout() { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - - var graph = Samples.GraphLibrary.LoopGraph(); + var graph = GraphLibrary.LoopGraph(); var templateGroups = new TemplateGroups(); - var template = Samples.TemplateLibrary.Miscellaneous.LTemplate(); + var template = TemplateLibrary.Miscellaneous.LTemplate(); templateGroups.Add("Default", template.UniqueVariations()); var generator = new LayoutGenerator(); var random = new RandomSeed(12345); - var layout = generator.Generate(1, graph, templateGroups, random); + var layout = generator.Generate(1, graph, templateGroups, random, Console.WriteLine); Assert.IsNotNull(layout); @@ -121,17 +107,14 @@ public void TestLLoopLayout() [TestMethod] public void TestHyperSquareGeekLayout() { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - - var graph = Samples.GraphLibrary.GeekGraph(); + var graph = GraphLibrary.GeekGraph(); var templateGroups = new TemplateGroups(); - templateGroups.Add("Default", Samples.TemplateLibrary.Miscellaneous.HyperSquareTemplate()); + templateGroups.Add("Default", TemplateLibrary.Miscellaneous.HyperSquareTemplate()); var generator = new LayoutGenerator(); var random = new RandomSeed(123456); - var layout = generator.Generate(1, graph, templateGroups, random); + var layout = generator.Generate(1, graph, templateGroups, random, Console.WriteLine); Assert.IsNotNull(layout); @@ -148,11 +131,11 @@ public void TestHyperSquareGeekLayout() [TestMethod] public void TestGraphIsNotFullyConnected() { - var graph = Samples.GraphLibrary.GeekGraph(); + var graph = GraphLibrary.GeekGraph(); graph.AddNode(100000); var templateGroups = new TemplateGroups(); - templateGroups.Add("Default", Samples.TemplateLibrary.Miscellaneous.HyperSquareTemplate()); + templateGroups.Add("Default", TemplateLibrary.Miscellaneous.HyperSquareTemplate()); var generator = new LayoutGenerator(); var random = new RandomSeed(123456); @@ -162,10 +145,7 @@ public void TestGraphIsNotFullyConnected() [TestMethod] public void TestManiaMapLayout() { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = ManiaMapSample.ManiaMapLayout(Console.WriteLine); Assert.IsNotNull(layout); @@ -196,14 +176,11 @@ public void TestToString() [DataRow(123456789)] public void TestBigLayout(int seed) { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - var random = new RandomSeed(seed); - var graph = Samples.GraphLibrary.BigGraph(); - var templateGroups = Samples.BigLayoutSample.BigLayoutTemplateGroups(); + var graph = GraphLibrary.BigGraph(); + var templateGroups = BigLayoutSample.BigLayoutTemplateGroups(); var generator = new LayoutGenerator(); - var layout = generator.Generate(1, graph, templateGroups, random); + var layout = generator.Generate(1, graph, templateGroups, random, Console.WriteLine); Assert.IsNotNull(layout); } @@ -216,9 +193,7 @@ public void TestBigLayout(int seed) [DataRow(123456789)] public async Task TestBigLayoutAsync(int seed) { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - var results = await BigLayoutSample.GenerateAsync(seed); + var results = await BigLayoutSample.GenerateAsync(seed, Console.WriteLine); var layout = results.GetOutput("Layout"); Assert.IsNotNull(layout); } @@ -226,18 +201,15 @@ public async Task TestBigLayoutAsync(int seed) [TestMethod] public void TestDirectedRingLayout() { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - - var graph = Samples.GraphLibrary.DirectedRingGraph(); + var graph = GraphLibrary.DirectedRingGraph(); var templateGroups = new TemplateGroups(); - templateGroups.Add("Nodes", Samples.TemplateLibrary.Miscellaneous.HyperSquareTemplate()); - templateGroups.Add("Edges", Samples.TemplateLibrary.Squares.Square1x1NorthExitTemplate().AllVariations()); + templateGroups.Add("Nodes", TemplateLibrary.Miscellaneous.HyperSquareTemplate()); + templateGroups.Add("Edges", TemplateLibrary.Squares.Square1x1NorthExitTemplate().AllVariations()); var generator = new LayoutGenerator(); var random = new RandomSeed(12345); - var layout = generator.Generate(1, graph, templateGroups, random); + var layout = generator.Generate(1, graph, templateGroups, random, Console.WriteLine); Assert.IsNotNull(layout); diff --git a/src/ManiaMap.Tests/Generators/TestLayoutGraphRandomizer.cs b/src/ManiaMap.Tests/Generators/TestLayoutGraphRandomizer.cs index 27565f65..f63c86c2 100644 --- a/src/ManiaMap.Tests/Generators/TestLayoutGraphRandomizer.cs +++ b/src/ManiaMap.Tests/Generators/TestLayoutGraphRandomizer.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using MPewsey.Common.Pipelines; using MPewsey.Common.Random; +using System; using System.Collections.Generic; using System.Threading; @@ -24,7 +25,7 @@ public void TestApplyStep() var randomizer = new LayoutGraphRandomizer(); var results = new PipelineResults(input); - Assert.IsTrue(randomizer.ApplyStep(results, CancellationToken.None)); + Assert.IsTrue(randomizer.ApplyStep(results, Console.WriteLine, CancellationToken.None)); Assert.IsTrue(results.Outputs.ContainsKey("LayoutGraph")); } @@ -35,7 +36,7 @@ public void TestRandomizeLayout() graph.AddNodeVariations("Group1", new int[] { 0, 1 }); var seed = new RandomSeed(12345); var randomizer = new LayoutGraphRandomizer(); - var result = randomizer.RandomizeGraph(graph, seed); + var result = randomizer.RandomizeGraph(graph, seed, Console.WriteLine); Assert.AreNotEqual(graph, result); } } diff --git a/src/ManiaMap.Tests/Generators/TestLayoutGraphSelector.cs b/src/ManiaMap.Tests/Generators/TestLayoutGraphSelector.cs index 215d73ef..846713d7 100644 --- a/src/ManiaMap.Tests/Generators/TestLayoutGraphSelector.cs +++ b/src/ManiaMap.Tests/Generators/TestLayoutGraphSelector.cs @@ -31,7 +31,7 @@ public void TestListSelector() var selector = new LayoutGraphSelector(); var results = new PipelineResults(input); - Assert.IsTrue(selector.ApplyStep(results, CancellationToken.None)); + Assert.IsTrue(selector.ApplyStep(results, Console.WriteLine, CancellationToken.None)); Assert.AreEqual(1, results.Outputs.Count); Assert.IsTrue(results.Outputs.ContainsKey("LayoutGraph")); } @@ -56,7 +56,7 @@ public void TestFunctionSelector() var selector = new LayoutGraphSelector(); var results = new PipelineResults(input); - Assert.IsTrue(selector.ApplyStep(results, CancellationToken.None)); + Assert.IsTrue(selector.ApplyStep(results, Console.WriteLine, CancellationToken.None)); Assert.AreEqual(1, results.Outputs.Count); Assert.IsTrue(results.Outputs.ContainsKey("LayoutGraph")); } diff --git a/src/ManiaMap.Tests/Generators/TestPipelineBuilder.cs b/src/ManiaMap.Tests/Generators/TestPipelineBuilder.cs index 6a830c77..2a49c240 100644 --- a/src/ManiaMap.Tests/Generators/TestPipelineBuilder.cs +++ b/src/ManiaMap.Tests/Generators/TestPipelineBuilder.cs @@ -1,5 +1,4 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using MPewsey.Common.Logging; using MPewsey.Common.Serialization; using System; @@ -17,10 +16,7 @@ public class TestPipelineBuilder [DataRow(123456789)] public void TestDefaultPipelineGeneration(int seed) { - Logger.RemoveAllListeners(); - Logger.AddListener(Console.WriteLine); - - var results = Samples.BigLayoutSample.Generate(seed); + var results = Samples.BigLayoutSample.Generate(seed, Console.WriteLine); Assert.IsTrue(results.Success); Assert.IsTrue(results.Outputs.ContainsKey("Layout")); } @@ -28,7 +24,7 @@ public void TestDefaultPipelineGeneration(int seed) [TestMethod] public void TestLoadXmlString() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); Assert.IsTrue(results.Outputs.ContainsKey("Layout")); var layout = results.GetOutput("Layout"); @@ -41,7 +37,7 @@ public void TestLoadXmlString() [TestMethod] public void TestSaveAndLoadXml() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); Assert.IsTrue(results.Outputs.ContainsKey("Layout")); var layout = results.GetOutput("Layout"); @@ -54,7 +50,7 @@ public void TestSaveAndLoadXml() [TestMethod] public void TestSaveAndLoadJson() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); Assert.IsTrue(results.Outputs.ContainsKey("Layout")); var layout = results.GetOutput("Layout"); @@ -67,7 +63,7 @@ public void TestSaveAndLoadJson() [TestMethod] public void TestSaveAndLoadEncryptedXml() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); Assert.IsTrue(results.Outputs.ContainsKey("Layout")); var layout = results.GetOutput("Layout"); diff --git a/src/ManiaMap.Tests/TestDoorConnection.cs b/src/ManiaMap.Tests/TestDoorConnection.cs index dbb5744b..51ce40a3 100644 --- a/src/ManiaMap.Tests/TestDoorConnection.cs +++ b/src/ManiaMap.Tests/TestDoorConnection.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; namespace MPewsey.ManiaMap.Tests { @@ -8,7 +9,7 @@ public class TestDoorConnection [TestMethod] public void TestEdgeDirection() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); @@ -21,7 +22,7 @@ public void TestEdgeDirection() [TestMethod] public void TestGetDoorPosition() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); diff --git a/src/ManiaMap.Tests/TestLayout.cs b/src/ManiaMap.Tests/TestLayout.cs index 15bad2ff..a6270dc0 100644 --- a/src/ManiaMap.Tests/TestLayout.cs +++ b/src/ManiaMap.Tests/TestLayout.cs @@ -23,7 +23,7 @@ public void TestToString() public void TestSaveAndLoadManiaMapLayoutXml() { var path = "ManiaMapLayout.xml"; - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = Samples.ManiaMapSample.ManiaMapLayout(Console.WriteLine); XmlSerialization.SaveXml(path, layout); var copy = XmlSerialization.LoadXml(path); Assert.AreEqual(layout.Id, copy.Id); @@ -37,7 +37,7 @@ public void TestSaveAndLoadManiaMapLayoutXml() public void TestSaveAndLoadBigLayoutXml() { var path = "Layout.xml"; - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); XmlSerialization.SaveXml(path, layout); @@ -54,7 +54,7 @@ public void TestSaveAndLoadBigLayoutXml() public void TestSaveAndLoadBigLayoutJson() { var path = "Layout.json"; - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); JsonSerialization.SaveJson(path, layout); @@ -71,7 +71,7 @@ public void TestSaveAndLoadBigLayoutJson() public void TestSaveAndLoadEncryptedJson() { var path = "LayoutJson.sav"; - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); @@ -93,7 +93,7 @@ public void TestSaveAndLoadEncryptedJson() public void TestSaveAndLoadXmlBytes() { var path = "ManiaMapLayoutBytes.xml"; - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = Samples.ManiaMapSample.ManiaMapLayout(Console.WriteLine); XmlSerialization.SaveXml(path, layout); var bytes = File.ReadAllBytes(path); var copy = XmlSerialization.LoadXml(bytes); @@ -103,7 +103,7 @@ public void TestSaveAndLoadXmlBytes() [TestMethod] public void TestGetRoomConnections() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); var connections = layout.GetRoomConnections(); @@ -113,7 +113,7 @@ public void TestGetRoomConnections() [TestMethod] public void TestGetDoorConnection() { - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = Samples.ManiaMapSample.ManiaMapLayout(Console.WriteLine); var connection = layout.DoorConnections.Values.First(); Assert.AreEqual(connection, layout.GetDoorConnection(connection.FromRoom, connection.ToRoom)); Assert.AreEqual(connection, layout.GetDoorConnection(connection.ToRoom, connection.FromRoom)); @@ -122,7 +122,7 @@ public void TestGetDoorConnection() [TestMethod] public void TestContainsDoor() { - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = Samples.ManiaMapSample.ManiaMapLayout(Console.WriteLine); var connection = layout.DoorConnections.Values.First(); Assert.IsTrue(connection.ContainsDoor(connection.FromRoom, connection.FromDoor.Position, connection.FromDoor.Direction)); Assert.IsTrue(connection.ContainsDoor(connection.ToRoom, connection.ToDoor.Position, connection.ToDoor.Direction)); @@ -132,7 +132,7 @@ public void TestContainsDoor() [TestMethod] public void TestRemoveDoorConnection() { - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = Samples.ManiaMapSample.ManiaMapLayout(Console.WriteLine); var connection = layout.DoorConnections.Values.First(); Assert.IsTrue(layout.RemoveDoorConnection(connection.FromRoom, connection.ToRoom)); } @@ -168,7 +168,7 @@ public void TestGenerateConstrainedLayout() public void TestVisibleCellCount() { var seed = new RandomSeed(12345); - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); var layout = results.GetOutput("Layout"); var layoutState = new LayoutState(layout); @@ -198,7 +198,7 @@ public void TestVisibleCellCount() public void TestVisibleCellProgress() { var seed = new RandomSeed(12345); - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); var layout = results.GetOutput("Layout"); var layoutState = new LayoutState(layout); @@ -224,7 +224,7 @@ public void TestVisibleCellProgress() [TestMethod] public void TestFindRoomWithTag() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); var layout = results.GetOutput("Layout"); var room = layout.FindRoomWithTag("Origin"); Assert.IsNotNull(room); @@ -234,7 +234,7 @@ public void TestFindRoomWithTag() [TestMethod] public void TestFindRoomsWithTag() { - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); var layout = results.GetOutput("Layout"); var rooms = layout.FindRoomsWithTag("Origin"); Assert.IsNotNull(rooms); diff --git a/src/ManiaMap.Tests/TestLayoutState.cs b/src/ManiaMap.Tests/TestLayoutState.cs index 511e8e7b..1c6f2712 100644 --- a/src/ManiaMap.Tests/TestLayoutState.cs +++ b/src/ManiaMap.Tests/TestLayoutState.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using MPewsey.Common.Serialization; +using System; namespace MPewsey.ManiaMap.Tests { @@ -10,7 +11,7 @@ public class TestLayoutState public void TestSaveAndLoadManiaMapXml() { var path = "ManiaMapLayoutState.xml"; - var layout = Samples.ManiaMapSample.ManiaMapLayout(); + var layout = Samples.ManiaMapSample.ManiaMapLayout(Console.WriteLine); var state = new LayoutState(layout); XmlSerialization.SaveXml(path, state); var copy = XmlSerialization.LoadXml(path); @@ -22,7 +23,7 @@ public void TestSaveAndLoadManiaMapXml() public void TestSaveAndLoadBigLayoutXml() { var path = "BigLayoutState.xml"; - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); var state = new LayoutState(layout); diff --git a/src/ManiaMap.Tests/TestRoom.cs b/src/ManiaMap.Tests/TestRoom.cs index e76db1fb..5666033d 100644 --- a/src/ManiaMap.Tests/TestRoom.cs +++ b/src/ManiaMap.Tests/TestRoom.cs @@ -2,6 +2,7 @@ using MPewsey.Common.Mathematics; using MPewsey.Common.Serialization; using MPewsey.ManiaMap.Graphs; +using System; using System.Linq; namespace MPewsey.ManiaMap.Tests @@ -13,7 +14,7 @@ public class TestRoom public void TestSaveAndLoad() { var path = "Room.xml"; - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); var room = layout.Rooms.Values.First(); diff --git a/src/ManiaMap.Tests/TestRoomState.cs b/src/ManiaMap.Tests/TestRoomState.cs index d7d5c471..b9ddd9a3 100644 --- a/src/ManiaMap.Tests/TestRoomState.cs +++ b/src/ManiaMap.Tests/TestRoomState.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using MPewsey.Common.Serialization; +using System; using System.Linq; namespace MPewsey.ManiaMap.Tests @@ -11,7 +12,7 @@ public class TestRoomState public void TestSaveAndLoad() { var path = "RoomState.xml"; - var results = Samples.BigLayoutSample.Generate(12345); + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); Assert.IsTrue(results.Success); var layout = results.GetOutput("Layout"); var room = layout.Rooms.Values.First(); diff --git a/src/ManiaMap.Tests/TestRoomTemplate.cs b/src/ManiaMap.Tests/TestRoomTemplate.cs index 2d90b813..f00b1eb0 100644 --- a/src/ManiaMap.Tests/TestRoomTemplate.cs +++ b/src/ManiaMap.Tests/TestRoomTemplate.cs @@ -546,7 +546,7 @@ public void TestMirroredVertically() [TestMethod] public void TestCollectableSpotsAreValid() { - var spots = new DataContractDictionary + var spots = new HashMap { { 1, new CollectableSpot(Vector2DInt.Zero, "Default", 1) }, }; @@ -567,7 +567,7 @@ public void TestCollectableSpotsAreValid() [TestMethod] public void TestValidateCollectableSpotPositions() { - var spots = new DataContractDictionary + var spots = new HashMap { { 1, new CollectableSpot(new Vector2DInt(-1, -1), "Default", 1) }, }; @@ -588,7 +588,7 @@ public void TestValidateCollectableSpotPositions() [TestMethod] public void TestValidateCollectableSpotGroupNames() { - var spots = new DataContractDictionary + var spots = new HashMap { { 1, new CollectableSpot(Vector2DInt.Zero, "", 1) }, }; @@ -609,7 +609,7 @@ public void TestValidateCollectableSpotGroupNames() [TestMethod] public void TestCollectableSpotsAreNotValid() { - var spots = new DataContractDictionary + var spots = new HashMap { { 1, new CollectableSpot(Vector2DInt.Zero, "", 1) }, }; @@ -630,12 +630,12 @@ public void TestCollectableSpotsAreNotValid() [TestMethod] public void TestCollectableSpotValuesAreNotEqual() { - var spots1 = new DataContractDictionary + var spots1 = new HashMap { { 1, new CollectableSpot(Vector2DInt.Zero, "", 1) }, }; - var spots2 = new DataContractDictionary + var spots2 = new HashMap { { 2, new CollectableSpot(Vector2DInt.Zero, "", 1) }, }; diff --git a/src/ManiaMap/Cell.cs b/src/ManiaMap/Cell.cs index afc337b4..6986b661 100644 --- a/src/ManiaMap/Cell.cs +++ b/src/ManiaMap/Cell.cs @@ -26,7 +26,7 @@ public class Cell /// A dictionary of doors. /// [DataMember(Order = 1)] - public DataContractDictionary Doors { get; set; } = new DataContractDictionary(); + public HashMap Doors { get; set; } = new HashMap(); /// /// A list of feature names. @@ -67,7 +67,7 @@ public class Cell [OnDeserialized] private void OnDeserialized(StreamingContext context) { - Doors = Doors ?? new DataContractDictionary(); + Doors = Doors ?? new HashMap(); Features = Features ?? new List(); } diff --git a/src/ManiaMap/CollectableGroups.cs b/src/ManiaMap/CollectableGroups.cs index 68499c67..094b344d 100644 --- a/src/ManiaMap/CollectableGroups.cs +++ b/src/ManiaMap/CollectableGroups.cs @@ -16,7 +16,7 @@ public class CollectableGroups /// A dictionary of collectables by group name. /// [DataMember(Order = 1)] - private DataContractDictionary> Groups { get; set; } = new DataContractDictionary>(); + private HashMap> Groups { get; set; } = new HashMap>(); /// /// A readonly dictionary of collectables by group name. @@ -27,7 +27,7 @@ public class CollectableGroups [OnDeserialized] private void OnDeserialized(StreamingContext context) { - Groups = Groups ?? new DataContractDictionary>(); + Groups = Groups ?? new HashMap>(); } /// diff --git a/src/ManiaMap/DoorConnection.cs b/src/ManiaMap/DoorConnection.cs index 201c05ac..7bbf50a1 100644 --- a/src/ManiaMap/DoorConnection.cs +++ b/src/ManiaMap/DoorConnection.cs @@ -8,7 +8,7 @@ namespace MPewsey.ManiaMap /// Represents a door connection between two Room. /// [DataContract(Namespace = Constants.DataContractNamespace)] - public class DoorConnection : IDataContractValueDictionaryValue + public class DoorConnection : IValueHashMapEntry { /// /// The from room ID. @@ -41,7 +41,7 @@ public class DoorConnection : IDataContractValueDictionaryValue public Box Shaft { get; private set; } /// - RoomPair IDataContractValueDictionaryValue.Key => new RoomPair(FromRoom, ToRoom); + RoomPair IValueHashMapEntry.Key => new RoomPair(FromRoom, ToRoom); /// /// The edge direction. diff --git a/src/ManiaMap/Generators/CollectableGenerator.cs b/src/ManiaMap/Generators/CollectableGenerator.cs index e6507bca..506b04ac 100644 --- a/src/ManiaMap/Generators/CollectableGenerator.cs +++ b/src/ManiaMap/Generators/CollectableGenerator.cs @@ -1,5 +1,4 @@ using MPewsey.Common.Collections; -using MPewsey.Common.Logging; using MPewsey.Common.Mathematics; using MPewsey.Common.Pipelines; using MPewsey.Common.Random; @@ -93,13 +92,14 @@ public override string ToString() /// * %RandomSeed - The random seed. /// /// The pipeline results. + /// The logging action. Ignored if null. /// The cancellation token. - public bool ApplyStep(PipelineResults results, CancellationToken cancellationToken) + public bool ApplyStep(PipelineResults results, Action logger, CancellationToken cancellationToken) { var layout = results.GetArgument("Layout"); var collectableGroups = results.GetArgument("CollectableGroups"); var randomSeed = results.GetArgument("RandomSeed"); - Generate(layout, collectableGroups, randomSeed); + Generate(layout, collectableGroups, randomSeed, logger); return true; } @@ -124,9 +124,10 @@ private void Initialize(Layout layout, CollectableGroups collectableGroups, Rand /// The layout. /// The collectable groups. /// The random seed. - public void Generate(Layout layout, CollectableGroups collectableGroups, RandomSeed randomSeed) + /// The logging action. Ignored if null. + public void Generate(Layout layout, CollectableGroups collectableGroups, RandomSeed randomSeed, Action logger = null) { - Logger.Log("[Collectable Generator] Running collectable generator..."); + logger?.Invoke("[Collectable Generator] Running collectable generator..."); Initialize(layout, collectableGroups, randomSeed); CreateCollectableSpotWeights(); @@ -138,7 +139,7 @@ public void Generate(Layout layout, CollectableGroups collectableGroups, RandomS AddCollectable(collectable.Group, collectable.Id); } - Logger.Log("[Collectable Generator] Collectable generator complete."); + logger?.Invoke("[Collectable Generator] Collectable generator complete."); } /// diff --git a/src/ManiaMap/Generators/LayoutGenerator.cs b/src/ManiaMap/Generators/LayoutGenerator.cs index fcc45355..fd8a4ac4 100644 --- a/src/ManiaMap/Generators/LayoutGenerator.cs +++ b/src/ManiaMap/Generators/LayoutGenerator.cs @@ -1,5 +1,4 @@ -using MPewsey.Common.Logging; -using MPewsey.Common.Mathematics; +using MPewsey.Common.Mathematics; using MPewsey.Common.Pipelines; using MPewsey.Common.Random; using MPewsey.ManiaMap.Exceptions; @@ -125,15 +124,16 @@ private void SetAllowableRebases(int chain) /// * %Layout - The generated layout. /// /// The pipeline results. + /// The logging action. Ignored if null. /// The cancellation token. - public bool ApplyStep(PipelineResults results, CancellationToken cancellationToken) + public bool ApplyStep(PipelineResults results, Action logger, CancellationToken cancellationToken) { var layoutId = results.GetArgument("LayoutId"); var graph = results.GetArgument("LayoutGraph"); var templateGroups = results.GetArgument("TemplateGroups"); var randomSeed = results.GetArgument("RandomSeed"); - var layout = Generate(layoutId, graph, templateGroups, randomSeed, cancellationToken); + var layout = Generate(layoutId, graph, templateGroups, randomSeed, logger, cancellationToken); results.SetOutput("Layout", layout); return layout != null; } @@ -163,11 +163,12 @@ private void Initialize(LayoutGraph graph, TemplateGroups templateGroups, Random /// The layout graph. /// The template groups. /// The random seed. + /// The logging action. Ignored if null. /// The cancellation token. public Layout Generate(int layoutId, LayoutGraph graph, TemplateGroups templateGroups, - RandomSeed randomSeed, CancellationToken cancellationToken = default) + RandomSeed randomSeed, Action logger = null, CancellationToken cancellationToken = default) { - Logger.Log("[Layout Generator] Running layout generator..."); + logger?.Invoke("[Layout Generator] Running layout generator..."); Initialize(graph, templateGroups, randomSeed); var chains = Graph.FindChains(MaxBranchLength); @@ -180,7 +181,7 @@ public Layout Generate(int layoutId, LayoutGraph graph, TemplateGroups templateG // Check cancellation token. if (cancellationToken.IsCancellationRequested) { - Logger.Log("[Layout Generator] Process cancelled."); + logger?.Invoke("[Layout Generator] Process cancelled."); return null; } @@ -193,7 +194,7 @@ public Layout Generate(int layoutId, LayoutGraph graph, TemplateGroups templateG if (Layout.IsComplete(TemplateGroups)) { Layout = new Layout(Layout); - Logger.Log("[Layout Generator] Layout generator complete."); + logger?.Invoke("[Layout Generator] Layout generator complete."); return Layout; } @@ -201,7 +202,7 @@ public Layout Generate(int layoutId, LayoutGraph graph, TemplateGroups templateG ChainIndex = 0; layouts.Clear(); layouts.Push(baseLayout); - Logger.Log("[Layout Generator] Layout constraints not satisfied. Restarting..."); + logger?.Invoke("[Layout Generator] Layout constraints not satisfied. Restarting..."); continue; } @@ -211,7 +212,7 @@ public Layout Generate(int layoutId, LayoutGraph graph, TemplateGroups templateG { layouts.Pop(); ChainIndex--; - Logger.Log("[Layout Generator] Rebase count exceeded. Backtracking..."); + logger?.Invoke("[Layout Generator] Rebase count exceeded. Backtracking..."); continue; } @@ -222,11 +223,11 @@ public Layout Generate(int layoutId, LayoutGraph graph, TemplateGroups templateG { layouts.Push(Layout); ChainIndex++; - Logger.Log($"[Layout Generator] Added chain {ChainIndex} / {chains.Count}..."); + logger?.Invoke($"[Layout Generator] Added chain {ChainIndex} / {chains.Count}..."); } } - Logger.Log("[Layout Generator] Layout generator failed."); + logger?.Invoke("[Layout Generator] Layout generator failed."); return null; } diff --git a/src/ManiaMap/Generators/LayoutGraphRandomizer.cs b/src/ManiaMap/Generators/LayoutGraphRandomizer.cs index 775fd01e..97cb0934 100644 --- a/src/ManiaMap/Generators/LayoutGraphRandomizer.cs +++ b/src/ManiaMap/Generators/LayoutGraphRandomizer.cs @@ -1,7 +1,7 @@ -using MPewsey.Common.Logging; -using MPewsey.Common.Pipelines; +using MPewsey.Common.Pipelines; using MPewsey.Common.Random; using MPewsey.ManiaMap.Graphs; +using System; using System.Threading; namespace MPewsey.ManiaMap.Generators @@ -22,12 +22,13 @@ public class LayoutGraphRandomizer : IPipelineStep /// * %LayoutGraph - The randomized layout graph. /// /// The pipeline results. + /// The logging action. Ignored if null. /// The cancellation token. - public bool ApplyStep(PipelineResults results, CancellationToken cancellationToken) + public bool ApplyStep(PipelineResults results, Action logger, CancellationToken cancellationToken) { var randomSeed = results.GetArgument("RandomSeed"); var graph = results.GetArgument("LayoutGraph"); - results.SetOutput("LayoutGraph", RandomizeGraph(graph, randomSeed)); + results.SetOutput("LayoutGraph", RandomizeGraph(graph, randomSeed, logger)); return true; } @@ -36,11 +37,12 @@ public bool ApplyStep(PipelineResults results, CancellationToken cancellationTok /// /// The layout graph. /// The random seed. - public LayoutGraph RandomizeGraph(LayoutGraph graph, RandomSeed randomSeed) + /// The logging action. Ignored if null. + public LayoutGraph RandomizeGraph(LayoutGraph graph, RandomSeed randomSeed, Action logger = null) { - Logger.Log("[Layout Graph Randomizer] Running layout graph randomizer..."); + logger?.Invoke("[Layout Graph Randomizer] Running layout graph randomizer..."); var result = graph.CreateVariation(randomSeed); - Logger.Log("[Layout Graph Randomizer] Layout graph randomizer complete."); + logger?.Invoke("[Layout Graph Randomizer] Layout graph randomizer complete."); return result; } } diff --git a/src/ManiaMap/Generators/LayoutGraphSelector.cs b/src/ManiaMap/Generators/LayoutGraphSelector.cs index ec4256fc..0282c87c 100644 --- a/src/ManiaMap/Generators/LayoutGraphSelector.cs +++ b/src/ManiaMap/Generators/LayoutGraphSelector.cs @@ -1,5 +1,4 @@ -using MPewsey.Common.Logging; -using MPewsey.Common.Pipelines; +using MPewsey.Common.Pipelines; using MPewsey.Common.Random; using MPewsey.ManiaMap.Graphs; using System; @@ -24,12 +23,13 @@ public class LayoutGraphSelector : IPipelineStep /// * %LayoutGraph - The drawn layout graph. /// /// The pipeline results. + /// The logging action. Ignored if null. /// The cancellation token. - public bool ApplyStep(PipelineResults results, CancellationToken cancellationToken) + public bool ApplyStep(PipelineResults results, Action logger, CancellationToken cancellationToken) { var randomSeed = results.GetArgument("RandomSeed"); var layouts = results.GetArgument("LayoutGraphs"); - results.SetOutput("LayoutGraph", DrawSelection(layouts, randomSeed)); + results.SetOutput("LayoutGraph", DrawSelection(layouts, randomSeed, logger)); return true; } @@ -38,12 +38,13 @@ public bool ApplyStep(PipelineResults results, CancellationToken cancellationTok /// /// A list of layout graphs. /// The random seed. - public LayoutGraph DrawSelection(IList graphs, RandomSeed randomSeed) + /// The logging action. Ignored if null. + public LayoutGraph DrawSelection(IList graphs, RandomSeed randomSeed, Action logger = null) { - Logger.Log("[Layout Graph Selector] Running layout graph list selector..."); + logger?.Invoke("[Layout Graph Selector] Running layout graph list selector..."); var index = randomSeed.Next(0, graphs.Count); var result = graphs[index].Copy(); - Logger.Log("[Layout Graph Selector] Layout graph selector complete."); + logger?.Invoke("[Layout Graph Selector] Layout graph selector complete."); return result; } @@ -52,12 +53,13 @@ public LayoutGraph DrawSelection(IList graphs, RandomSeed randomSee /// /// A list of functions returning a layout graph. /// The random seed. - public LayoutGraph DrawSelection(IList> functions, RandomSeed randomSeed) + /// The logging action. Ignored if null. + public LayoutGraph DrawSelection(IList> functions, RandomSeed randomSeed, Action logger = null) { - Logger.Log("[Layout Graph Selector] Applying layout graph delegate list selector..."); + logger?.Invoke("[Layout Graph Selector] Applying layout graph delegate list selector..."); var index = randomSeed.Next(0, functions.Count); var result = functions[index].Invoke().Copy(); - Logger.Log("[Layout Graph Selector] Layout graph selector complete."); + logger?.Invoke("[Layout Graph Selector] Layout graph selector complete."); return result; } @@ -66,17 +68,18 @@ public LayoutGraph DrawSelection(IList> functions, RandomSeed /// /// A list of layout graphs or functions returning layout graphs. /// The random seed. + /// The logging action. Ignored if null. /// Raised if the type of `graphs` is not handled. - public LayoutGraph DrawSelection(object graphs, RandomSeed randomSeed) + public LayoutGraph DrawSelection(object graphs, RandomSeed randomSeed, Action logger = null) { - Logger.Log("[Layout Graph Selector] Running layout graph selector..."); + logger?.Invoke("[Layout Graph Selector] Running layout graph selector..."); switch (graphs) { case IList list: - return DrawSelection(list, randomSeed); + return DrawSelection(list, randomSeed, logger); case IList> functions: - return DrawSelection(functions, randomSeed); + return DrawSelection(functions, randomSeed, logger); default: throw new ArgumentException($"Unhandled type for `graphs`: {graphs.GetType()}."); } diff --git a/src/ManiaMap/Graphs/LayoutEdge.cs b/src/ManiaMap/Graphs/LayoutEdge.cs index fd9b2c58..668acc06 100644 --- a/src/ManiaMap/Graphs/LayoutEdge.cs +++ b/src/ManiaMap/Graphs/LayoutEdge.cs @@ -18,7 +18,7 @@ namespace MPewsey.ManiaMap.Graphs /// ``` /// [DataContract(Namespace = Constants.DataContractNamespace)] - public class LayoutEdge : IRoomSource, IDataContractValueDictionaryValue + public class LayoutEdge : IRoomSource, IValueHashMapEntry { /// [DataMember(Order = 1)] @@ -82,7 +82,7 @@ public class LayoutEdge : IRoomSource, IDataContractValueDictionaryValue new Uid(FromNode, ToNode, 1); } /// - EdgeIndexes IDataContractValueDictionaryValue.Key => new EdgeIndexes(FromNode, ToNode); + EdgeIndexes IValueHashMapEntry.Key => new EdgeIndexes(FromNode, ToNode); /// [OnDeserialized] diff --git a/src/ManiaMap/Graphs/LayoutGraph.cs b/src/ManiaMap/Graphs/LayoutGraph.cs index 9d9238ef..0f27435e 100644 --- a/src/ManiaMap/Graphs/LayoutGraph.cs +++ b/src/ManiaMap/Graphs/LayoutGraph.cs @@ -29,25 +29,25 @@ public class LayoutGraph /// A dictionary of nodes by ID. /// [DataMember(Order = 3)] - private DataContractValueDictionary Nodes { get; set; } = new DataContractValueDictionary(); + private ValueHashMap Nodes { get; set; } = new ValueHashMap(); /// /// A dictionary of nodes by from and to node ID's. /// [DataMember(Order = 4)] - private DataContractValueDictionary Edges { get; set; } = new DataContractValueDictionary(); + private ValueHashMap Edges { get; set; } = new ValueHashMap(); /// /// A dictionary of neighboring nodes by node ID. /// [DataMember(Order = 5)] - private DataContractDictionary> Neighbors { get; set; } = new DataContractDictionary>(); + private HashMap> Neighbors { get; set; } = new HashMap>(); /// /// A dictionary of node variation groups. /// [DataMember(Order = 6)] - private DataContractDictionary> NodeVariations { get; set; } = new DataContractDictionary>(); + private HashMap> NodeVariations { get; set; } = new HashMap>(); /// /// A readonly dictionary of nodes. @@ -73,10 +73,10 @@ public class LayoutGraph [OnDeserialized] private void OnDeserialized(StreamingContext context) { - Nodes = Nodes ?? new DataContractValueDictionary(); - Edges = Edges ?? new DataContractValueDictionary(); - Neighbors = Neighbors ?? new DataContractDictionary>(); - NodeVariations = NodeVariations ?? new DataContractDictionary>(); + Nodes = Nodes ?? new ValueHashMap(); + Edges = Edges ?? new ValueHashMap(); + Neighbors = Neighbors ?? new HashMap>(); + NodeVariations = NodeVariations ?? new HashMap>(); } /// diff --git a/src/ManiaMap/Graphs/LayoutNode.cs b/src/ManiaMap/Graphs/LayoutNode.cs index f71c0752..cac2a46e 100644 --- a/src/ManiaMap/Graphs/LayoutNode.cs +++ b/src/ManiaMap/Graphs/LayoutNode.cs @@ -17,7 +17,7 @@ namespace MPewsey.ManiaMap.Graphs /// ``` /// [DataContract(Namespace = Constants.DataContractNamespace)] - public class LayoutNode : IRoomSource, IDataContractValueDictionaryValue + public class LayoutNode : IRoomSource, IValueHashMapEntry { /// /// The unique node ID. @@ -49,7 +49,7 @@ public class LayoutNode : IRoomSource, IDataContractValueDictionaryValue public Uid RoomId { get => new Uid(Id); } /// - int IDataContractValueDictionaryValue.Key => Id; + int IValueHashMapEntry.Key => Id; /// [OnDeserialized] diff --git a/src/ManiaMap/Layout.cs b/src/ManiaMap/Layout.cs index 546a8b46..2ab9f9d5 100644 --- a/src/ManiaMap/Layout.cs +++ b/src/ManiaMap/Layout.cs @@ -36,19 +36,19 @@ public class Layout /// A dictionary of rooms in the layout by ID. /// [DataMember(Order = 3)] - public DataContractValueDictionary Rooms { get; private set; } = new DataContractValueDictionary(); + public ValueHashMap Rooms { get; private set; } = new ValueHashMap(); /// /// A dictionary of door connections by room ID pairs. /// [DataMember(Order = 4)] - public DataContractValueDictionary DoorConnections { get; private set; } = new DataContractValueDictionary(); + public ValueHashMap DoorConnections { get; private set; } = new ValueHashMap(); /// /// A dictionary of room templates in the layout by ID. /// [DataMember(Order = 5)] - public DataContractValueDictionary Templates { get; private set; } = new DataContractValueDictionary(); + public ValueHashMap Templates { get; private set; } = new ValueHashMap(); /// /// The current number of times the layout has been used as a base for another layout. @@ -63,9 +63,9 @@ public class Layout [OnDeserialized] private void OnDeserialized(StreamingContext context) { - Rooms = Rooms ?? new DataContractValueDictionary(); - DoorConnections = DoorConnections ?? new DataContractValueDictionary(); - Templates = Templates ?? new DataContractValueDictionary(); + Rooms = Rooms ?? new ValueHashMap(); + DoorConnections = DoorConnections ?? new ValueHashMap(); + Templates = Templates ?? new ValueHashMap(); TemplateCounts = TemplateCounts ?? new Dictionary(); AssignRoomTemplates(); } @@ -89,8 +89,8 @@ public Layout(Layout baseLayout) Id = baseLayout.Id; Name = baseLayout.Name; Seed = baseLayout.Seed; - Rooms = new DataContractValueDictionary(baseLayout.Rooms); - DoorConnections = new DataContractValueDictionary(baseLayout.DoorConnections); + Rooms = new ValueHashMap(baseLayout.Rooms); + DoorConnections = new ValueHashMap(baseLayout.DoorConnections); TemplateCounts = new Dictionary(baseLayout.TemplateCounts); PopulateTemplates(); baseLayout.Rebases++; diff --git a/src/ManiaMap/LayoutState.cs b/src/ManiaMap/LayoutState.cs index 1d773c62..8f35be8b 100644 --- a/src/ManiaMap/LayoutState.cs +++ b/src/ManiaMap/LayoutState.cs @@ -20,13 +20,13 @@ public class LayoutState /// A dictionary of room states by ID. /// [DataMember(Order = 1)] - public DataContractValueDictionary RoomStates { get; private set; } = new DataContractValueDictionary(); + public ValueHashMap RoomStates { get; private set; } = new ValueHashMap(); /// [OnDeserialized] private void OnDeserialized(StreamingContext context) { - RoomStates = RoomStates ?? new DataContractValueDictionary(); + RoomStates = RoomStates ?? new ValueHashMap(); } /// diff --git a/src/ManiaMap/ManiaMap.csproj b/src/ManiaMap/ManiaMap.csproj index fc59fe02..15a6b50e 100644 --- a/src/ManiaMap/ManiaMap.csproj +++ b/src/ManiaMap/ManiaMap.csproj @@ -68,7 +68,7 @@ - + diff --git a/src/ManiaMap/Room.cs b/src/ManiaMap/Room.cs index ae927aed..63fdedcf 100644 --- a/src/ManiaMap/Room.cs +++ b/src/ManiaMap/Room.cs @@ -9,7 +9,7 @@ namespace MPewsey.ManiaMap /// Represents a room in a Layout. /// [DataContract(Namespace = Constants.DataContractNamespace)] - public class Room : IDataContractValueDictionaryValue + public class Room : IValueHashMapEntry { /// /// The room ID. @@ -61,7 +61,7 @@ public int TemplateId /// A dictionary of collectable object ID's by location ID. /// [DataMember(Order = 8)] - public DataContractDictionary Collectables { get; private set; } = new DataContractDictionary(); + public HashMap Collectables { get; private set; } = new HashMap(); /// /// A list of tags. @@ -73,12 +73,12 @@ public int TemplateId [OnDeserialized] private void OnDeserialized(StreamingContext context) { - Collectables = Collectables ?? new DataContractDictionary(); + Collectables = Collectables ?? new HashMap(); Tags = Tags ?? new List(); } /// - Uid IDataContractValueDictionaryValue.Key => Id; + Uid IValueHashMapEntry.Key => Id; /// /// Initializes a room from a room source. diff --git a/src/ManiaMap/RoomState.cs b/src/ManiaMap/RoomState.cs index a7b08475..b6236995 100644 --- a/src/ManiaMap/RoomState.cs +++ b/src/ManiaMap/RoomState.cs @@ -8,7 +8,7 @@ namespace MPewsey.ManiaMap /// Stores the state of a Room in a Layout. /// [DataContract(Namespace = Constants.DataContractNamespace)] - public class RoomState : IDataContractValueDictionaryValue + public class RoomState : IValueHashMapEntry { /// /// The ID of the corresponding room. @@ -32,24 +32,24 @@ public class RoomState : IDataContractValueDictionaryValue /// A set of acquired collectable location ID's. /// [DataMember(Order = 4)] - public DataContractHashSet AcquiredCollectables { get; private set; } = new DataContractHashSet(); + public Set AcquiredCollectables { get; private set; } = new Set(); /// /// A set of flags that are set for a room. /// [DataMember(Order = 5)] - public DataContractHashSet Flags { get; private set; } = new DataContractHashSet(); + public Set Flags { get; private set; } = new Set(); /// - Uid IDataContractValueDictionaryValue.Key => Id; + Uid IValueHashMapEntry.Key => Id; /// [OnDeserialized] private void OnDeserialized(StreamingContext context) { VisibleCells = VisibleCells ?? new BitArray2D(); - AcquiredCollectables = AcquiredCollectables ?? new DataContractHashSet(); - Flags = Flags ?? new DataContractHashSet(); + AcquiredCollectables = AcquiredCollectables ?? new Set(); + Flags = Flags ?? new Set(); } /// diff --git a/src/ManiaMap/RoomTemplate.cs b/src/ManiaMap/RoomTemplate.cs index 141be322..6487c771 100644 --- a/src/ManiaMap/RoomTemplate.cs +++ b/src/ManiaMap/RoomTemplate.cs @@ -13,7 +13,7 @@ namespace MPewsey.ManiaMap /// Contains information for the geometry and properties of a Room in a Layout. /// [DataContract(Namespace = Constants.DataContractNamespace)] - public class RoomTemplate : IDataContractValueDictionaryValue + public class RoomTemplate : IValueHashMapEntry { /// /// The unique ID. @@ -38,17 +38,17 @@ public class RoomTemplate : IDataContractValueDictionaryValue /// A dictionary of collectable spots by ID. /// [DataMember(Order = 4)] - public DataContractDictionary CollectableSpots { get; private set; } + public HashMap CollectableSpots { get; private set; } /// - int IDataContractValueDictionaryValue.Key => Id; + int IValueHashMapEntry.Key => Id; /// [OnDeserialized] private void OnDeserialized(StreamingContext context) { Cells = Cells ?? new Array2D(); - CollectableSpots = CollectableSpots ?? new DataContractDictionary(); + CollectableSpots = CollectableSpots ?? new HashMap(); } /// @@ -59,12 +59,12 @@ private void OnDeserialized(StreamingContext context) /// An array of cells in the template. /// A dictionary of collectable spots by ID. public RoomTemplate(int id, string name, Array2D cells, - DataContractDictionary collectableSpots = null) + HashMap collectableSpots = null) { Id = id; Name = name; Cells = cells; - CollectableSpots = collectableSpots ?? new DataContractDictionary(); + CollectableSpots = collectableSpots ?? new HashMap(); } /// @@ -378,7 +378,7 @@ private Array2D CellsRotated90() /// /// Returns a dictionary of collectable spots rotated 90 degrees clockwise. /// - private DataContractDictionary CollectableSpotsRotated90() + private HashMap CollectableSpotsRotated90() { var spots = CollectableSpots.ToDictionary(x => x.Key, x => x.Value.Copy()); @@ -416,7 +416,7 @@ private Array2D CellsRotated180() /// /// Returns a dictionary of collectable spots rotated 180 degrees. /// - private DataContractDictionary CollectableSpotsRotated180() + private HashMap CollectableSpotsRotated180() { var spots = CollectableSpots.ToDictionary(x => x.Key, x => x.Value.Copy()); @@ -454,7 +454,7 @@ private Array2D CellsRotated270() /// /// Returns a dictionary of collectable spots rotated 270 degrees clockwise. /// - private DataContractDictionary CollectableSpotsRotated270() + private HashMap CollectableSpotsRotated270() { var spots = CollectableSpots.ToDictionary(x => x.Key, x => x.Value.Copy()); @@ -492,7 +492,7 @@ private Array2D CellsMirroredVertically() /// /// Returns a dictionary of collectable spots mirrored vertically. /// - private DataContractDictionary CollectableSpotsMirroredVertically() + private HashMap CollectableSpotsMirroredVertically() { var spots = CollectableSpots.ToDictionary(x => x.Key, x => x.Value.Copy()); @@ -530,7 +530,7 @@ private Array2D CellsMirroredHorizontally() /// /// Returns a dictionary of collectable spots mirrored horizontally. /// - private DataContractDictionary CollectableSpotsMirroredHorizontally() + private HashMap CollectableSpotsMirroredHorizontally() { var spots = CollectableSpots.ToDictionary(x => x.Key, x => x.Value.Copy()); diff --git a/src/ManiaMap/Samples/BigLayoutSample.cs b/src/ManiaMap/Samples/BigLayoutSample.cs index 2c880b01..fc06a4bd 100644 --- a/src/ManiaMap/Samples/BigLayoutSample.cs +++ b/src/ManiaMap/Samples/BigLayoutSample.cs @@ -2,6 +2,7 @@ using MPewsey.Common.Pipelines; using MPewsey.Common.Random; using MPewsey.ManiaMap.Generators; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -77,8 +78,9 @@ public static TemplateGroups BigLayoutTemplateGroups() /// Generates the big layout using default parameters and returns the results. /// /// The random seed. + /// The logging action. Ignored if null. /// The cancellation token. - public static PipelineResults Generate(int seed, CancellationToken cancellationToken = default) + public static PipelineResults Generate(int seed, Action logger = null, CancellationToken cancellationToken = default) { var random = new RandomSeed(seed); var graph = GraphLibrary.BigGraph(); @@ -96,15 +98,16 @@ public static PipelineResults Generate(int seed, CancellationToken cancellationT }; var pipeline = PipelineBuilder.CreateDefaultPipeline(); - return pipeline.Run(inputs, cancellationToken); + return pipeline.Run(inputs, logger, cancellationToken); } /// /// Generates the big layout asynchronously using default parameters and returns the results. /// /// The random seed. + /// The logging action. Ignored if null. /// The cancellation token. - public static Task GenerateAsync(int seed, CancellationToken cancellationToken = default) + public static Task GenerateAsync(int seed, Action logger = null, CancellationToken cancellationToken = default) { var random = new RandomSeed(seed); var graph = GraphLibrary.BigGraph(); @@ -122,7 +125,7 @@ public static Task GenerateAsync(int seed, CancellationToken ca }; var pipeline = PipelineBuilder.CreateDefaultPipeline(); - return pipeline.RunAsync(inputs, cancellationToken); + return pipeline.RunAsync(inputs, logger, cancellationToken); } } } diff --git a/src/ManiaMap/Samples/ManiaMapSample.cs b/src/ManiaMap/Samples/ManiaMapSample.cs index 80f45233..7e9c844c 100644 --- a/src/ManiaMap/Samples/ManiaMapSample.cs +++ b/src/ManiaMap/Samples/ManiaMapSample.cs @@ -1,6 +1,7 @@ using MPewsey.Common.Random; using MPewsey.ManiaMap.Generators; using MPewsey.ManiaMap.Graphs; +using System; namespace MPewsey.ManiaMap.Samples { @@ -184,13 +185,13 @@ public static LayoutGraph ManiaMapLayoutGraph() /// /// Generates the Mania Map layout and returns it. /// - public static Layout ManiaMapLayout() + public static Layout ManiaMapLayout(Action logger = null) { var graph = ManiaMapLayoutGraph(); var templateGroups = LetterTemplateGroups(); var generator = new LayoutGenerator(); var random = new RandomSeed(12345); - return generator.Generate(1, graph, templateGroups, random); + return generator.Generate(1, graph, templateGroups, random, logger); } } } diff --git a/src/ManiaMap/TemplateGroups.cs b/src/ManiaMap/TemplateGroups.cs index 3deecd03..93283ba8 100644 --- a/src/ManiaMap/TemplateGroups.cs +++ b/src/ManiaMap/TemplateGroups.cs @@ -16,7 +16,7 @@ public class TemplateGroups /// A dictionary of templates by group name. /// [DataMember(Order = 1)] - private DataContractDictionary> Groups { get; set; } = new DataContractDictionary>(); + private HashMap> Groups { get; set; } = new HashMap>(); /// /// A readonly dictionary of templates by group name. @@ -26,7 +26,7 @@ public class TemplateGroups [OnDeserialized] private void OnDeserialized(StreamingContext context) { - Groups = Groups ?? new DataContractDictionary>(); + Groups = Groups ?? new HashMap>(); ConsolidateTemplates(); }