From 1f74cdbda0500f54e70c539fb0b5db2eccd044fc Mon Sep 17 00:00:00 2001 From: Matt Pewsey <23442063+mpewsey@users.noreply.github.com> Date: Mon, 6 May 2024 12:35:33 -0400 Subject: [PATCH] Add connecting room method --- src/ManiaMap.Tests/TestDoorConnection.cs | 17 +++++++++++++++++ src/ManiaMap/DoorConnection.cs | 14 ++++++++++++++ src/ManiaMap/Generators/LayoutGraphSelector.cs | 2 +- src/ManiaMap/ManiaMap.csproj | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/ManiaMap.Tests/TestDoorConnection.cs b/src/ManiaMap.Tests/TestDoorConnection.cs index 51ce40a3..e38f7075 100644 --- a/src/ManiaMap.Tests/TestDoorConnection.cs +++ b/src/ManiaMap.Tests/TestDoorConnection.cs @@ -36,5 +36,22 @@ public void TestGetDoorPosition() Assert.IsNull(position); } } + + [TestMethod] + public void TestGetConnectingRoom() + { + var results = Samples.BigLayoutSample.Generate(12345, Console.WriteLine); + Assert.IsTrue(results.Success); + var layout = results.GetOutput("Layout"); + + foreach (var connection in layout.DoorConnections.Values) + { + var toRoom = connection.ToRoom; + var fromRoom = connection.FromRoom; + Assert.AreEqual(connection.GetConnectingRoom(toRoom), fromRoom); + Assert.AreEqual(connection.GetConnectingRoom(fromRoom), toRoom); + Assert.AreEqual(connection.GetConnectingRoom(new Uid(int.MaxValue)), new Uid(-1, -1, -1)); + } + } } } diff --git a/src/ManiaMap/DoorConnection.cs b/src/ManiaMap/DoorConnection.cs index 7bbf50a1..35f5b813 100644 --- a/src/ManiaMap/DoorConnection.cs +++ b/src/ManiaMap/DoorConnection.cs @@ -97,5 +97,19 @@ public DoorPosition GetDoorPosition(Uid roomId) return ToDoor; return null; } + + /// + /// Returns the ID of the connecting room, e.g. the "to room" if the "from room" ID is specified and vice versa. + /// If the specified room ID does not exist in the connection, returns Uid(-1, -1, -1). + /// + /// The room ID. + public Uid GetConnectingRoom(Uid roomId) + { + if (roomId == FromRoom) + return ToRoom; + if (roomId == ToRoom) + return FromRoom; + return new Uid(-1, -1, -1); + } } } diff --git a/src/ManiaMap/Generators/LayoutGraphSelector.cs b/src/ManiaMap/Generators/LayoutGraphSelector.cs index fff3a081..95c7f9d7 100644 --- a/src/ManiaMap/Generators/LayoutGraphSelector.cs +++ b/src/ManiaMap/Generators/LayoutGraphSelector.cs @@ -16,7 +16,7 @@ public class LayoutGraphSelector : IPipelineStep /// A delegate returning a LayoutGraph. /// public delegate LayoutGraph LayoutGraphDelegate(); - + /// /// Draws a random layout graph and adds a copy to the results output dictionary. /// diff --git a/src/ManiaMap/ManiaMap.csproj b/src/ManiaMap/ManiaMap.csproj index 9a4e51ba..532f0d7e 100644 --- a/src/ManiaMap/ManiaMap.csproj +++ b/src/ManiaMap/ManiaMap.csproj @@ -14,7 +14,7 @@ https://github.com/mpewsey/ManiaMap procedural-generation;roguelike;metroidvania;videogames BSD-3-Clause - 2.4.0 + 2.5.0 Debug;Release;Unity https://mpewsey.github.io/ManiaMap/ True