From 8187c775d1d9e8aa16e09032be44cd07fed8d555 Mon Sep 17 00:00:00 2001 From: Paige Ashlynn Date: Wed, 27 Mar 2019 22:26:35 -0700 Subject: [PATCH] Improves the ToString methods for MapChunk and MapRegion. --- ParquetClassLibrary/Sandbox/MapChunk.cs | 28 +++---- ParquetClassLibrary/Sandbox/MapParent.cs | 94 +++++++++++++++++++++--- ParquetClassLibrary/Sandbox/MapRegion.cs | 48 +----------- 3 files changed, 101 insertions(+), 69 deletions(-) diff --git a/ParquetClassLibrary/Sandbox/MapChunk.cs b/ParquetClassLibrary/Sandbox/MapChunk.cs index f12cac99..1ecc10d6 100644 --- a/ParquetClassLibrary/Sandbox/MapChunk.cs +++ b/ParquetClassLibrary/Sandbox/MapChunk.cs @@ -10,6 +10,9 @@ namespace ParquetClassLibrary.Sandbox /// /// Models details of a playable chunk in sandbox-mode. /// Map Chunks are composed of Parquets and Special Points. + /// are + /// handmade (as opposed to procedurally generated) components + /// of s. /// [JsonObject(MemberSerialization.Fields)] public class MapChunk : MapParent @@ -21,21 +24,21 @@ public class MapChunk : MapParent #endregion #region Chunk Contents - /// Floors and walkable terrain in the region. + /// Floors and walkable terrain in the chunk. protected override EntityID[,] _floorLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension, - Assembly.ParquetsPerChunkDimension]; + Assembly.ParquetsPerChunkDimension]; - /// Walls and obstructing terrain in the region. + /// Walls and obstructing terrain in the chunk. protected override EntityID[,] _blockLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension, - Assembly.ParquetsPerChunkDimension]; + Assembly.ParquetsPerChunkDimension]; - /// Furniture and natural items in the region. + /// Furniture and natural items in the chunk. protected override EntityID[,] _furnishingLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension, - Assembly.ParquetsPerChunkDimension]; + Assembly.ParquetsPerChunkDimension]; - /// Collectable materials in the region. + /// Collectable materials in the chunk. protected override EntityID[,] _collectableLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension, - Assembly.ParquetsPerChunkDimension]; + Assembly.ParquetsPerChunkDimension]; #endregion #region Serialization Methods @@ -57,7 +60,7 @@ public class MapChunk : MapParent } else { - // Determine what version of region map was serialized. + // Determine what version of map was serialized. try { var document = JObject.Parse(in_serializedMap); @@ -82,13 +85,12 @@ public class MapChunk : MapParent #region Utility Methods /// - /// Visualizes the region as a string with merged layers. - /// Intended for Console debugging. + /// Describes the chunk as a string containing basic information. /// - /// A that represents the current . + /// A that represents the current . public override string ToString() { - return $"Chunk: \n{base.ToString()}"; + return $"Chunk {base.ToString()}"; } #endregion } diff --git a/ParquetClassLibrary/Sandbox/MapParent.cs b/ParquetClassLibrary/Sandbox/MapParent.cs index c8388d5b..0e09c10f 100644 --- a/ParquetClassLibrary/Sandbox/MapParent.cs +++ b/ParquetClassLibrary/Sandbox/MapParent.cs @@ -34,20 +34,43 @@ public abstract class MapParent #endregion #region Map Contents - /// Exit, spawn, and other special points in the region. + /// Exit, spawn, and other special points on the map. protected readonly List _specialPoints = new List(); - /// Floors and walkable terrain in the region. + /// Floors and walkable terrain on the map. protected abstract EntityID[,] _floorLayer { get; } - /// Walls and obstructing terrain in the region. + /// Walls and obstructing terrain on the map. protected abstract EntityID[,] _blockLayer { get; } - /// Furniture and natural items in the region. + /// Furniture and natural items on the map. protected abstract EntityID[,] _furnishingLayer { get; } - /// Collectable materials in the region. + /// Collectable materials on the map. protected abstract EntityID[,] _collectableLayer { get; } + + /// The total number of parquets in the entire map. + protected int ParquetsCount + { + get + { + var count = 0; + + for (var x = 0; x < DimensionsInParquets.x; x++) + { + for (var y = 0; y < DimensionsInParquets.y; y++) + { + count += EntityID.None != _floorLayer[x, y] ? 1 : 0; + count += EntityID.None != _blockLayer[x, y] ? 1 : 0; + count += EntityID.None != _furnishingLayer[x, y] ? 1 : 0; + count += EntityID.None != _collectableLayer[x, y] ? 1 : 0; + } + } + + return count; + } + } + #endregion #region Parquets Replacement Methods @@ -345,7 +368,7 @@ public ParquetStack GetAllParquetsAtPosition(Vector2Int in_position) } /// - /// Gets all the parquets in the entire region. + /// Gets all the parquets in the entire map. /// /// A collection of parquets. public IEnumerable GetAllParquets() @@ -396,7 +419,7 @@ public string SerializeToString() #region Utility Methods /// - /// Determines if the given position corresponds to a point in the region. + /// Determines if the given position corresponds to a point on the map. /// /// The position to validate. /// true, if the position is valid, false otherwise. @@ -409,11 +432,11 @@ public bool IsValidPosition(Vector2Int in_position) } /// - /// Visualizes the region as a string with merged layers. + /// Visualizes the map as a string with merged layers. /// Intended for Console debugging. /// - /// A that represents the current . - public override string ToString() + /// A that represents the current map. + internal string DumpMap() { var representation = new StringBuilder(DimensionsInParquets.Magnitude); #region Compose visual represenation of contents. @@ -440,6 +463,57 @@ public override string ToString() return representation.ToString(); } + + /// + /// Visualizes the map as a string, listing layers separately. + /// Intended for Console debugging. + /// + /// A that represents the current map. + public string DumpMapWithLayers() + { + var floorRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); + var blocksRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); + var furnishingsRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); + var collectablesRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); + #region Compose visual represenation of contents. + for (var x = 0; x < DimensionsInParquets.x; x++) + { + for (var y = 0; y < DimensionsInParquets.y; y++) + { + floorRepresentation.Append(EntityID.None != _floorLayer[x, y] + ? _floorLayer[x, y].ToString() + : "~"); + blocksRepresentation.Append(EntityID.None != _blockLayer[x, y] + ? _blockLayer[x, y].ToString() + : " "); + furnishingsRepresentation.Append(EntityID.None != _furnishingLayer[x, y] + ? _furnishingLayer[x, y].ToString() + : " "); + collectablesRepresentation.Append(EntityID.None != _collectableLayer[x, y] + ? _collectableLayer[x, y].ToString() + : " "); + } + floorRepresentation.AppendLine(); + blocksRepresentation.AppendLine(); + furnishingsRepresentation.AppendLine(); + collectablesRepresentation.AppendLine(); + } + #endregion + + return $"Floor:\n{floorRepresentation}\n" + + $"Blocks:\n{blocksRepresentation}\n" + + $"Furnishings:\n{furnishingsRepresentation}\n" + + $"Collectables:\n{collectablesRepresentation}"; + } + + /// + /// Describes the map as a string containing basic information. + /// + /// A that represents the current map. + public override string ToString() + { + return $"({DimensionsInParquets.x }, {DimensionsInParquets.y}) contains {ParquetsCount} parquets and {_specialPoints.Count} special points."; + } #endregion } } diff --git a/ParquetClassLibrary/Sandbox/MapRegion.cs b/ParquetClassLibrary/Sandbox/MapRegion.cs index 81920270..b8b7a19d 100644 --- a/ParquetClassLibrary/Sandbox/MapRegion.cs +++ b/ParquetClassLibrary/Sandbox/MapRegion.cs @@ -137,56 +137,12 @@ public MapRegion(bool in_generateID) #region Utility Methods /// - /// Visualizes the region as a string with merged layers. - /// Intended for Console debugging. + /// Describes the region as a string containing basic information. /// /// A that represents the current . public override string ToString() { - return $"Region {Title} ({DimensionsInParquets.x }, {DimensionsInParquets.y})\n{base.ToString()}"; - } - - /// - /// Visualizes the region as a string, listing layers separately. - /// Intended for Console debugging. - /// - /// A that represents the current . - public string ToLayeredString() - { - var floorRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); - var blocksRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); - var furnishingsRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); - var collectablesRepresentation = new StringBuilder(DimensionsInParquets.Magnitude); - #region Compose visual represenation of contents. - for (var x = 0; x < DimensionsInParquets.x; x++) - { - for (var y = 0; y < DimensionsInParquets.y; y++) - { - floorRepresentation.Append(EntityID.None != _floorLayer[x, y] - ? _floorLayer[x, y].ToString() - : "~"); - blocksRepresentation.Append(EntityID.None != _blockLayer[x, y] - ? _blockLayer[x, y].ToString() - : " "); - furnishingsRepresentation.Append(EntityID.None != _furnishingLayer[x, y] - ? _furnishingLayer[x, y].ToString() - : " "); - collectablesRepresentation.Append(EntityID.None != _collectableLayer[x, y] - ? _collectableLayer[x, y].ToString() - : " "); - } - floorRepresentation.AppendLine(); - blocksRepresentation.AppendLine(); - furnishingsRepresentation.AppendLine(); - collectablesRepresentation.AppendLine(); - } - #endregion - - return $"Region {Title} ({DimensionsInParquets.x}, {DimensionsInParquets.y})\n" + - $"Floor:\n{floorRepresentation}\n" + - $"Blocks:\n{blocksRepresentation}\n" + - $"Furnishings:\n{furnishingsRepresentation}\n" + - $"Collectables:\n{collectablesRepresentation}"; + return $"Region {Title} {base.ToString()}"; } #endregion }