diff --git a/NetAF.Tests/Assets/Locations/Matrix_Tests.cs b/NetAF.Tests/Assets/Locations/Matrix_Tests.cs index 80e02e9..13da98c 100644 --- a/NetAF.Tests/Assets/Locations/Matrix_Tests.cs +++ b/NetAF.Tests/Assets/Locations/Matrix_Tests.cs @@ -2,6 +2,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using NetAF.Assets; +using NetAF.Serialization.Assets; namespace NetAF.Tests.Assets.Locations { @@ -150,5 +151,31 @@ public void Given2Point1UnitApart_WhenDistanceBetweenPoints_Then1() Assert.AreEqual(1, (int)result); } + + [TestMethod] + public void GivenVisitedRoomOn1And1VisitedRoomOn3_When_ThenReturnContaining1And3() + { + List roomPositions = + [ + new(new(string.Empty, string.Empty), new Point3D(0, 0, 0)), + new(new(string.Empty, string.Empty), new Point3D(0, 1, 0)), + new(new(string.Empty, string.Empty), new Point3D(0, 1, 1)), + new(new(string.Empty, string.Empty), new Point3D(0, 1, 2)), + new(new(string.Empty, string.Empty), new Point3D(0, 1, 3)) + ]; + + var serialization = RoomSerialization.FromRoom(roomPositions[2].Room); + serialization.HasBeenVisited = true; + roomPositions[2].Room.RestoreFrom(serialization); + roomPositions[4].Room.RestoreFrom(serialization); + + var matrix = new Matrix([.. roomPositions]); + + var result = matrix.FindAllZWithVisitedRooms(); + + Assert.AreEqual(2, result.Length); + Assert.AreEqual(1, result[0]); + Assert.AreEqual(3, result[1]); + } } } diff --git a/NetAF/Assets/ExaminableObject.cs b/NetAF/Assets/ExaminableObject.cs index 403e675..fba6cd6 100644 --- a/NetAF/Assets/ExaminableObject.cs +++ b/NetAF/Assets/ExaminableObject.cs @@ -26,31 +26,8 @@ public class ExaminableObject : IExaminable if (request.Examinable.Description != null) description.Append(request.Examinable.Description.GetDescription()); - if (request.Examinable.Commands?.Any() ?? false) - { - if (description.Length > 0) - description.Append(" "); - - description.Append($"{Environment.NewLine}{Environment.NewLine}{request.Examinable.Identifier.Name} provides the following commands: "); - - for (int i = 0; i < request.Examinable.Commands.Length; i++) - { - CustomCommand customCommand = request.Examinable.Commands[i]; - description.Append($"{Environment.NewLine}\"{customCommand.Help.Command}\" - {customCommand.Help.Description.RemoveSentenceEnd()}, "); - } - - if (description.ToString().EndsWith(", ")) - { - description.Remove(description.Length - 2, 2); - description.EnsureFinishedSentence(); - } - } - - if (description.Length == 0) - description.Append(request.Examinable.Identifier.Name); - - if (description.Length == 0) - description.Append(request.Examinable.GetType().Name); + AddCommandsToDescription(request, ref description); + EnsureAtleastABasicDescription(request, ref description); if (request.Examinable.Attributes.Count > 0) description.Append($"\n\n{StringUtilities.ConstructAttributesAsString(request.Examinable.Attributes.GetAsDictionary())}"); @@ -69,6 +46,52 @@ public class ExaminableObject : IExaminable #endregion + #region StaticMethods + + /// + /// Ensure that at least a basic description has been added. + /// + /// The examination request. + /// The current description. + private static void EnsureAtleastABasicDescription(ExaminationRequest request, ref StringBuilder description) + { + if (description.Length == 0) + description.Append(request.Examinable.Identifier.Name); + + if (description.Length == 0) + description.Append(request.Examinable.GetType().Name); + } + + /// + /// Add any commands to the description. + /// + /// The examination request. + /// The current description. + private static void AddCommandsToDescription(ExaminationRequest request, ref StringBuilder description) + { + if (request.Examinable.Commands == null || request.Examinable.Commands.Length == 0) + return; + + if (description.Length > 0) + description.Append(' '); + + description.Append($"{Environment.NewLine}{Environment.NewLine}{request.Examinable.Identifier.Name} provides the following commands: "); + + for (int i = 0; i < request.Examinable.Commands.Length; i++) + { + CustomCommand customCommand = request.Examinable.Commands[i]; + description.Append($"{Environment.NewLine}\"{customCommand.Help.Command}\" - {customCommand.Help.Description.RemoveSentenceEnd()}, "); + } + + if (description.ToString().EndsWith(", ")) + { + description.Remove(description.Length - 2, 2); + description.EnsureFinishedSentence(); + } + } + + #endregion + #region Implementation of IExaminable /// diff --git a/NetAF/Assets/Locations/Matrix.cs b/NetAF/Assets/Locations/Matrix.cs index 21159c1..0d79019 100644 --- a/NetAF/Assets/Locations/Matrix.cs +++ b/NetAF/Assets/Locations/Matrix.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; namespace NetAF.Assets.Locations @@ -88,6 +89,29 @@ public double DistanceBetweenRooms(Room a, Room b) return DistanceBetweenPoints(aPos.Value, bPos.Value); } + /// + /// Find all Z that have visited rooms. + /// + /// An array containing all Z with visited rooms. + public int[] FindAllZWithVisitedRooms() + { + List floors = []; + + for (var floor = 0; floor < Depth; floor++) + { + foreach (var room in FindAllRoomsOnZ(floor)) + { + if (room.HasBeenVisited) + { + floors.Add(floor); + continue; + } + } + } + + return [.. floors]; + } + #endregion #region StaticMethods diff --git a/NetAF/Rendering/Console/FrameBuilders/ConsoleRegionMapBuilder.cs b/NetAF/Rendering/Console/FrameBuilders/ConsoleRegionMapBuilder.cs index e99bc28..82e4ea1 100644 --- a/NetAF/Rendering/Console/FrameBuilders/ConsoleRegionMapBuilder.cs +++ b/NetAF/Rendering/Console/FrameBuilders/ConsoleRegionMapBuilder.cs @@ -286,7 +286,7 @@ public void BuildRegionMap(Region region, Point2D startPosition, Point3D focusPo var rooms = matrix.ToRooms().Where(r => r != null).ToArray(); var unvisitedRoomPositions = rooms.Select(region.GetPositionOfRoom).Where(r => !r.Room.HasBeenVisited).ToList(); var visitedRoomPositions = rooms.Select(region.GetPositionOfRoom).Where(r => r.Room.HasBeenVisited).ToList(); - var multiLevel = matrix.Depth > 1; + var multiLevel = matrix.Depth > 1 && (region.IsVisibleWithoutDiscovery || matrix.FindAllZWithVisitedRooms().Length > 1); var indicatorLength = 3 + matrix.Depth.ToString().Length; var maxAvailableWidth = maxSize.Width; var x = startPosition.X;