Skip to content

Commit

Permalink
Add contains room method
Browse files Browse the repository at this point in the history
  • Loading branch information
mpewsey committed May 13, 2024
1 parent e4f0eeb commit 3c0ff42
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ManiaMap.Tests/TestDoorConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,22 @@ public void TestGetConnectingRoom()
Assert.AreEqual(connection.GetConnectingRoom(new Uid(int.MaxValue)), new Uid(-1, -1, -1));
}
}

[TestMethod]
public void TestContainsRoom()
{
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.IsTrue(connection.ContainsRoom(toRoom));
Assert.IsTrue(connection.ContainsRoom(fromRoom));
Assert.IsFalse(connection.ContainsRoom(new Uid(-1, -1, -1)));
}
}
}
}
9 changes: 9 additions & 0 deletions src/ManiaMap/DoorConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,14 @@ public Uid GetConnectingRoom(Uid roomId)
return FromRoom;
return new Uid(-1, -1, -1);
}

/// <summary>
/// Returns true if the door connections "from room" or "to room" matches the specified room ID.
/// </summary>
/// <param name="roomId">The room ID.</param>
public bool ContainsRoom(Uid roomId)
{
return roomId == FromRoom || roomId == ToRoom;
}
}
}

0 comments on commit 3c0ff42

Please sign in to comment.