mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
Update DrawnLine & Plane to allow line addition.
This commit is contained in:
parent
d8677a6e4b
commit
b35a11a2ee
2 changed files with 71 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace Nibriboard.RippleSpace
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -7,6 +8,25 @@ namespace Nibriboard.RippleSpace
|
|||
/// </summary>
|
||||
public class DrawnLine
|
||||
{
|
||||
/// <summary>
|
||||
/// The id of line that this <see cref="Nibriboard.RippleSpace.DrawnLine" /> is part of.
|
||||
/// Note that this id may not be unique - several lines that were all
|
||||
/// drawn at once may also have the same id. This is such that a single
|
||||
/// line that was split across multiple chunks can still be referenced.
|
||||
/// </summary>
|
||||
public readonly Guid LineId;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the line.
|
||||
/// </summary>
|
||||
public int LineWidth;
|
||||
/// <summary>
|
||||
/// The colour of the line.
|
||||
/// </summary>
|
||||
public string Colour;
|
||||
/// <summary>
|
||||
/// The points that represent the line.
|
||||
/// </summary>
|
||||
public List<LocationReference> Points = new List<LocationReference>();
|
||||
|
||||
/// <summary>
|
||||
|
@ -39,9 +59,41 @@ namespace Nibriboard.RippleSpace
|
|||
}
|
||||
}
|
||||
|
||||
public DrawnLine()
|
||||
public DrawnLine() : this(Guid.NewGuid())
|
||||
{
|
||||
|
||||
}
|
||||
protected DrawnLine(Guid inLineId)
|
||||
{
|
||||
LineId = inLineId;
|
||||
}
|
||||
|
||||
public List<DrawnLine> SplitOnChunks(int chunkSize)
|
||||
{
|
||||
List<DrawnLine> results = new List<DrawnLine>();
|
||||
|
||||
// Don't bother splitting the line up if it all falls in the same chunk
|
||||
if (!SpansMultipleChunks)
|
||||
{
|
||||
results.Add(this);
|
||||
return results;
|
||||
}
|
||||
|
||||
DrawnLine nextLine = new DrawnLine();
|
||||
ChunkReference currentChunk = null;
|
||||
foreach(LocationReference point in Points)
|
||||
{
|
||||
if(currentChunk != null && point.ContainingChunk != currentChunk)
|
||||
{
|
||||
// We're heading into a new chunk! Split the line up here.
|
||||
// TODO: Add connecting lines to each DrawnLine instance to prevent gaps
|
||||
results.Add(nextLine);
|
||||
nextLine = new DrawnLine(LineId);
|
||||
}
|
||||
|
||||
nextLine.Points.Add(point);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,5 +65,22 @@ namespace Nibriboard.RippleSpace
|
|||
|
||||
return loadedChunk;
|
||||
}
|
||||
|
||||
public async Task AddLine(DrawnLine newLine)
|
||||
{
|
||||
List<DrawnLine> chunkedLine;
|
||||
// Split the line up into chunked pieces if neccessary
|
||||
if(newLine.SpansMultipleChunks)
|
||||
chunkedLine = newLine.SplitOnChunks(ChunkSize);
|
||||
else
|
||||
chunkedLine = new List<DrawnLine>() { newLine };
|
||||
|
||||
// Add each segment to the appropriate chunk
|
||||
foreach(DrawnLine newLineSegment in chunkedLine)
|
||||
{
|
||||
Chunk containingChunk = await FetchChunk(newLineSegment.ContainingChunk);
|
||||
containingChunk.Add(newLineSegment);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue