Skip to content

Commit

Permalink
Add connecting room method
Browse files Browse the repository at this point in the history
  • Loading branch information
mpewsey committed May 6, 2024
1 parent 5c6a617 commit 1f74cdb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/ManiaMap.Tests/TestDoorConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>("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));
}
}
}
}
14 changes: 14 additions & 0 deletions src/ManiaMap/DoorConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,19 @@ public DoorPosition GetDoorPosition(Uid roomId)
return ToDoor;
return null;
}

/// <summary>
/// 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).
/// </summary>
/// <param name="roomId">The room ID.</param>
public Uid GetConnectingRoom(Uid roomId)
{
if (roomId == FromRoom)
return ToRoom;
if (roomId == ToRoom)
return FromRoom;
return new Uid(-1, -1, -1);
}
}
}
2 changes: 1 addition & 1 deletion src/ManiaMap/Generators/LayoutGraphSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LayoutGraphSelector : IPipelineStep
/// A delegate returning a LayoutGraph.
/// </summary>
public delegate LayoutGraph LayoutGraphDelegate();

/// <summary>
/// Draws a random layout graph and adds a copy to the results output dictionary.
///
Expand Down
2 changes: 1 addition & 1 deletion src/ManiaMap/ManiaMap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RepositoryUrl>https://github.com/mpewsey/ManiaMap</RepositoryUrl>
<PackageTags>procedural-generation;roguelike;metroidvania;videogames</PackageTags>
<PackageLicenseExpression>BSD-3-Clause</PackageLicenseExpression>
<VersionPrefix>2.4.0</VersionPrefix>
<VersionPrefix>2.5.0</VersionPrefix>
<Configurations>Debug;Release;Unity</Configurations>
<PackageProjectUrl>https://mpewsey.github.io/ManiaMap/</PackageProjectUrl>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down

0 comments on commit 1f74cdb

Please sign in to comment.