1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

Fill out more classes incl. DrawnLine.

Also fill out some of the comparison logic & the chunk wiring.
This commit is contained in:
Starbeamrainbowlabs 2017-01-07 20:19:21 +00:00
parent 6e894f58fc
commit 37051e0f7b
6 changed files with 110 additions and 1 deletions

View file

@ -124,6 +124,27 @@ namespace Nibriboard.RippleSpace
} }
} }
/// <summary>
/// Adds one or more new drawn lines to the chunk.
/// Note that new lines added must not cross chunk borders.
/// </summary>
/// <param name="newLines">The new line(s) to add.</param>
public void Add(params DrawnLine[] newLines)
{
int i = 0;
foreach (DrawnLine newLine in newLines)
{
if (newLine.SpansMultipleChunks == true)
throw new ArgumentException("Error: A line you tried to add spans multiple chunks.", $"newLines[{i}]");
if (newLine.ContainingChunk != Location)
throw new ArgumentException($"Error: A line you tried to add isn't in this chunk ({Location}).", $"newLine[{i}]");
lines.Add(newLine);
i++;
}
}
public IEnumerator<DrawnLine> GetEnumerator() public IEnumerator<DrawnLine> GetEnumerator()
{ {
UpdateAccessTime(); UpdateAccessTime();

View file

@ -36,6 +36,25 @@ namespace Nibriboard.RippleSpace
return $"{Plane.Name}-{X},{Y}.chunk"; return $"{Plane.Name}-{X},{Y}.chunk";
} }
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()}";
}
public static ChunkReference Parse(Plane plane, string source) public static ChunkReference Parse(Plane plane, string source)
{ {
if (!source.StartsWith("ChunkReference:")) if (!source.StartsWith("ChunkReference:"))

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace Nibriboard.RippleSpace namespace Nibriboard.RippleSpace
{ {
/// <summary> /// <summary>
@ -6,8 +7,41 @@ namespace Nibriboard.RippleSpace
/// </summary> /// </summary>
public class DrawnLine public class DrawnLine
{ {
public List<LocationReference> Points = new List<LocationReference>();
/// <summary>
/// Whether this line spans multiple chunks.
/// </summary>
public bool SpansMultipleChunks {
get {
// TODO: Make this more intelligent such that connecting lines
// can be stored that connect lines that span multiple chunks
if (Points.Count == 0)
return false;
ChunkReference containingChunk = Points[0].ContainingChunk;
foreach(LocationReference point in Points)
{
if (point.ContainingChunk != containingChunk)
return true;
}
return false;
}
}
/// <summary>
/// Gets a reference in chunk-space ot the chunk that this line starts in.
/// </summary>
public ChunkReference ContainingChunk {
get {
if (Points.Count == 0)
throw new InvalidOperationException("Error: This line doesn't contain any points yet!");
return Points[0].ContainingChunk;
}
}
public DrawnLine() public DrawnLine()
{ {
} }
} }
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Configuration;
namespace Nibriboard.RippleSpace namespace Nibriboard.RippleSpace
{ {
/// <summary> /// <summary>
@ -6,11 +7,39 @@ namespace Nibriboard.RippleSpace
/// </summary> /// </summary>
public class LocationReference : Reference public class LocationReference : Reference
{ {
public ChunkReference ContainingChunk {
get {
return new ChunkReference(
Plane,
X / Plane.ChunkSize,
Y / Plane.ChunkSize
);
}
}
public LocationReference(Plane inPlane, int inX, int inY) : base(inPlane, inX, inY) public LocationReference(Plane inPlane, int inX, int inY) : base(inPlane, inX, inY)
{ {
} }
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 $"LocationReference: {base.ToString()}";
}
public static LocationReference Parse(Plane plane, string source) public static LocationReference Parse(Plane plane, string source)
{ {
// TODO: Decide if this is the format that we want to use for location references // TODO: Decide if this is the format that we want to use for location references

View file

@ -59,7 +59,8 @@ namespace Nibriboard.RippleSpace
// Uh-oh! The chunk isn't loaded at moment. Load it quick & then // Uh-oh! The chunk isn't loaded at moment. Load it quick & then
// return it fast. // return it fast.
Chunk loadedChunk = await Chunk.FromFile(this, chunkLocation.AsFilename()); string chunkFilePath = Path.Combine(StorageDirectory, chunkLocation.AsFilename());
Chunk loadedChunk = await Chunk.FromFile(this, chunkFilePath);
loadedChunkspace.Add(chunkLocation, loadedChunk); loadedChunkspace.Add(chunkLocation, loadedChunk);
return loadedChunk; return loadedChunk;

View file

@ -16,5 +16,10 @@ namespace Nibriboard.RippleSpace
{ {
Plane = inPlane; Plane = inPlane;
} }
public override string ToString()
{
return $"({X}, {Y}, {Plane.Name})";
}
} }
} }