Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #29 from mxashlynn/improve-map-tostrings
Browse files Browse the repository at this point in the history
Improve Map class ToString() methods.
  • Loading branch information
mxashlynn committed Mar 28, 2019
2 parents 50acad0 + 8187c77 commit 0aa67d3
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 69 deletions.
28 changes: 15 additions & 13 deletions ParquetClassLibrary/Sandbox/MapChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace ParquetClassLibrary.Sandbox
/// <summary>
/// Models details of a playable chunk in sandbox-mode.
/// Map Chunks are composed of Parquets and Special Points.
/// <see cref="T:ParquetClassLibrary.Sandbox.MapChunk"/> are
/// handmade (as opposed to procedurally generated) components
/// of <see cref="T:ParquetClassLibrary.Sandbox.MapRegion"/>s.
/// </summary>
[JsonObject(MemberSerialization.Fields)]
public class MapChunk : MapParent
Expand All @@ -21,21 +24,21 @@ public class MapChunk : MapParent
#endregion

#region Chunk Contents
/// <summary>Floors and walkable terrain in the region.</summary>
/// <summary>Floors and walkable terrain in the chunk.</summary>
protected override EntityID[,] _floorLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];
Assembly.ParquetsPerChunkDimension];

/// <summary>Walls and obstructing terrain in the region.</summary>
/// <summary>Walls and obstructing terrain in the chunk.</summary>
protected override EntityID[,] _blockLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];
Assembly.ParquetsPerChunkDimension];

/// <summary>Furniture and natural items in the region.</summary>
/// <summary>Furniture and natural items in the chunk.</summary>
protected override EntityID[,] _furnishingLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];
Assembly.ParquetsPerChunkDimension];

/// <summary>Collectable materials in the region.</summary>
/// <summary>Collectable materials in the chunk.</summary>
protected override EntityID[,] _collectableLayer { get; } = new EntityID[Assembly.ParquetsPerChunkDimension,
Assembly.ParquetsPerChunkDimension];
Assembly.ParquetsPerChunkDimension];
#endregion

#region Serialization Methods
Expand All @@ -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);
Expand All @@ -82,13 +85,12 @@ public class MapChunk : MapParent

#region Utility Methods
/// <summary>
/// Visualizes the region as a string with merged layers.
/// Intended for Console debugging.
/// Describes the chunk as a string containing basic information.
/// </summary>
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:ParquetClassLibrary.Sandbox.MapRegion"/>.</returns>
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:ParquetClassLibrary.Sandbox.MapChunk"/>.</returns>
public override string ToString()
{
return $"Chunk: \n{base.ToString()}";
return $"Chunk {base.ToString()}";
}
#endregion
}
Expand Down
94 changes: 84 additions & 10 deletions ParquetClassLibrary/Sandbox/MapParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,43 @@ public abstract class MapParent
#endregion

#region Map Contents
/// <summary>Exit, spawn, and other special points in the region.</summary>
/// <summary>Exit, spawn, and other special points on the map.</summary>
protected readonly List<SpecialPoint> _specialPoints = new List<SpecialPoint>();

/// <summary>Floors and walkable terrain in the region.</summary>
/// <summary>Floors and walkable terrain on the map.</summary>
protected abstract EntityID[,] _floorLayer { get; }

/// <summary>Walls and obstructing terrain in the region.</summary>
/// <summary>Walls and obstructing terrain on the map.</summary>
protected abstract EntityID[,] _blockLayer { get; }

/// <summary>Furniture and natural items in the region.</summary>
/// <summary>Furniture and natural items on the map.</summary>
protected abstract EntityID[,] _furnishingLayer { get; }

/// <summary>Collectable materials in the region.</summary>
/// <summary>Collectable materials on the map.</summary>
protected abstract EntityID[,] _collectableLayer { get; }

/// <summary>The total number of parquets in the entire map.</summary>
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
Expand Down Expand Up @@ -345,7 +368,7 @@ public ParquetStack GetAllParquetsAtPosition(Vector2Int in_position)
}

/// <summary>
/// Gets all the parquets in the entire region.
/// Gets all the parquets in the entire map.
/// </summary>
/// <returns>A collection of parquets.</returns>
public IEnumerable<ParquetParent> GetAllParquets()
Expand Down Expand Up @@ -396,7 +419,7 @@ public string SerializeToString()

#region Utility Methods
/// <summary>
/// Determines if the given position corresponds to a point in the region.
/// Determines if the given position corresponds to a point on the map.
/// </summary>
/// <param name="in_position">The position to validate.</param>
/// <returns><c>true</c>, if the position is valid, <c>false</c> otherwise.</returns>
Expand All @@ -409,11 +432,11 @@ public bool IsValidPosition(Vector2Int in_position)
}

/// <summary>
/// Visualizes the region as a string with merged layers.
/// Visualizes the map as a string with merged layers.
/// Intended for Console debugging.
/// </summary>
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:ParquetClassLibrary.Sandbox.MapParent"/>.</returns>
public override string ToString()
/// <returns>A <see cref="T:System.String"/> that represents the current map.</returns>
internal string DumpMap()
{
var representation = new StringBuilder(DimensionsInParquets.Magnitude);
#region Compose visual represenation of contents.
Expand All @@ -440,6 +463,57 @@ public override string ToString()

return representation.ToString();
}

/// <summary>
/// Visualizes the map as a string, listing layers separately.
/// Intended for Console debugging.
/// </summary>
/// <returns>A <see cref="T:System.String"/> that represents the current map.</returns>
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}";
}

/// <summary>
/// Describes the map as a string containing basic information.
/// </summary>
/// <returns>A <see cref="T:System.String"/> that represents the current map.</returns>
public override string ToString()
{
return $"({DimensionsInParquets.x }, {DimensionsInParquets.y}) contains {ParquetsCount} parquets and {_specialPoints.Count} special points.";
}
#endregion
}
}
48 changes: 2 additions & 46 deletions ParquetClassLibrary/Sandbox/MapRegion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,56 +137,12 @@ public MapRegion(bool in_generateID)

#region Utility Methods
/// <summary>
/// Visualizes the region as a string with merged layers.
/// Intended for Console debugging.
/// Describes the region as a string containing basic information.
/// </summary>
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:ParquetClassLibrary.Sandbox.MapRegion"/>.</returns>
public override string ToString()
{
return $"Region {Title} ({DimensionsInParquets.x }, {DimensionsInParquets.y})\n{base.ToString()}";
}

/// <summary>
/// Visualizes the region as a string, listing layers separately.
/// Intended for Console debugging.
/// </summary>
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:ParquetClassLibrary.Sandbox.MapRegion"/>.</returns>
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
}
Expand Down

0 comments on commit 0aa67d3

Please sign in to comment.