2017-01-06 18:57:58 +00:00
|
|
|
|
using System;
|
2017-01-07 17:35:56 +00:00
|
|
|
|
using System.IO;
|
2017-05-29 12:14:56 +00:00
|
|
|
|
|
2017-03-20 18:47:21 +00:00
|
|
|
|
using SBRL.Utilities;
|
2017-03-04 21:49:51 +00:00
|
|
|
|
|
2017-01-06 18:57:58 +00:00
|
|
|
|
namespace Nibriboard.RippleSpace
|
|
|
|
|
{
|
2017-01-06 19:05:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// References the location of a chunk.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Defaults to chunk-space, but absolute plane-space can also be calculated
|
2017-01-10 19:52:27 +00:00
|
|
|
|
/// and obtained (A <see cref="NibriboardServer.RippleSpace.LocationReference" />
|
2017-01-06 19:05:27 +00:00
|
|
|
|
/// is returned).
|
|
|
|
|
/// </remarks>
|
2017-01-06 18:57:58 +00:00
|
|
|
|
public class ChunkReference : Reference
|
|
|
|
|
{
|
2017-01-06 20:45:35 +00:00
|
|
|
|
public ChunkReference(Plane inPlane, int inX, int inY) : base(inPlane, inX, inY)
|
2017-01-06 18:57:58 +00:00
|
|
|
|
{
|
2017-01-06 20:45:35 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 20:48:53 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts this chunk-space reference to plane-space.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>This chunk-space reference in plane-space.</returns>
|
2017-01-06 20:45:35 +00:00
|
|
|
|
public LocationReference InPlanespace()
|
|
|
|
|
{
|
|
|
|
|
return new LocationReference(
|
|
|
|
|
Plane,
|
2017-03-20 18:47:21 +00:00
|
|
|
|
X * Plane.ChunkSize,
|
|
|
|
|
Y * Plane.ChunkSize
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a rectangle representing the area of the chunk that this ChunkReference references.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A Rectangle representing this ChunkReference's chunk's area.</returns>
|
|
|
|
|
public Rectangle InPlanespaceRectangle()
|
|
|
|
|
{
|
|
|
|
|
return new Rectangle(
|
|
|
|
|
X * Plane.ChunkSize,
|
|
|
|
|
Y * Plane.ChunkSize,
|
|
|
|
|
(X * Plane.ChunkSize) + Plane.ChunkSize,
|
|
|
|
|
(Y * Plane.ChunkSize) + Plane.ChunkSize
|
2017-01-06 20:45:35 +00:00
|
|
|
|
);
|
2017-01-06 18:57:58 +00:00
|
|
|
|
}
|
2017-01-06 21:14:31 +00:00
|
|
|
|
|
|
|
|
|
public string AsFilename()
|
|
|
|
|
{
|
|
|
|
|
return $"{Plane.Name}-{X},{Y}.chunk";
|
|
|
|
|
}
|
2017-01-07 17:35:56 +00:00
|
|
|
|
|
2017-01-21 17:06:19 +00:00
|
|
|
|
public override int GetHashCode ()
|
|
|
|
|
{
|
|
|
|
|
return $"({Plane.Name})+{X}+{Y}".GetHashCode();
|
|
|
|
|
}
|
2017-01-07 20:19:21 +00:00
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
ChunkReference otherChunkReference = obj as ChunkReference;
|
|
|
|
|
if (otherChunkReference == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (X == otherChunkReference.X && Y == otherChunkReference.Y &&
|
|
|
|
|
Plane == otherChunkReference.Plane)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"ChunkReference: {base.ToString()}";
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-07 17:35:56 +00:00
|
|
|
|
public static ChunkReference Parse(Plane plane, string source)
|
|
|
|
|
{
|
|
|
|
|
if (!source.StartsWith("ChunkReference:"))
|
|
|
|
|
throw new InvalidDataException($"Error: That isn't a valid chunk reference. Chunk references start with 'ChunkReference:'.");
|
|
|
|
|
|
|
|
|
|
// Trim the extras off the reference
|
|
|
|
|
source = source.Substring("ChunkReference:".Length);
|
|
|
|
|
source = source.Trim("() \v\t\r\n".ToCharArray());
|
|
|
|
|
|
2017-01-10 20:36:03 +00:00
|
|
|
|
int x = int.Parse(source.Substring(0, source.IndexOf(",")));
|
|
|
|
|
int y = int.Parse(source.Substring(source.IndexOf(",") + 1));
|
2017-01-07 17:35:56 +00:00
|
|
|
|
return new ChunkReference(
|
|
|
|
|
plane,
|
|
|
|
|
x,
|
|
|
|
|
y
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-05-01 13:38:57 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a clone of this ChunkReference.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The newly-cloned instance.</returns>
|
|
|
|
|
public override object Clone()
|
|
|
|
|
{
|
|
|
|
|
return new ChunkReference(Plane, X, Y);
|
|
|
|
|
}
|
2017-01-06 18:57:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|