2017-03-29 20:34:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Nibriboard.RippleSpace;
|
|
|
|
|
using SBRL.Utilities;
|
|
|
|
|
|
|
|
|
|
namespace Nibriboard.Client
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Manages the construction of lines that the clients are drawing bit by bit.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class LineIncubator
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current lines that haven't been completed yet.
|
|
|
|
|
/// </summary>
|
2017-04-23 16:11:46 +00:00
|
|
|
|
private Dictionary<string, DrawnLine> currentLines = new Dictionary<string, DrawnLine>();
|
2017-03-29 20:34:24 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The number of lines that this line incubator has completed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int LinesCompleted { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-04-15 15:40:25 +00:00
|
|
|
|
/// The number of lines that are still incubating and haven't been completed yet.
|
2017-03-29 20:34:24 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public int IncompletedLines {
|
|
|
|
|
get {
|
|
|
|
|
return currentLines.Count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LineIncubator()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 14:54:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Figures out whether an incomplete line with the given id exists or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lineId">The line id to check for.</param>
|
2017-04-23 16:11:46 +00:00
|
|
|
|
public bool LineExists(string lineId)
|
2017-04-16 14:54:59 +00:00
|
|
|
|
{
|
2017-04-24 17:09:18 +00:00
|
|
|
|
if(currentLines.ContainsKey(lineId))
|
2017-04-16 14:54:59 +00:00
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-30 15:47:29 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new line in the incubator.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lineId">The line id to attach to the new line in the incubator.</param>
|
|
|
|
|
public void CreateLine(string lineId, string newColour, int newWidth)
|
|
|
|
|
{
|
|
|
|
|
if(currentLines.ContainsKey(lineId))
|
|
|
|
|
throw new InvalidOperationException($"Error: A line with the id {lineId} already exists, so you can't recreate it.");
|
|
|
|
|
|
|
|
|
|
currentLines.Add(lineId, new DrawnLine(lineId) {
|
|
|
|
|
Colour = newColour,
|
|
|
|
|
Width = newWidth
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 14:54:59 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds a series of points to the incomplete line with the specified id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lineId">The line id to add the points to.</param>
|
|
|
|
|
/// <param name="points">The points to add to the lines.</param>
|
2017-06-30 09:33:35 +00:00
|
|
|
|
public void AddBit(string lineId, List<LocationReference> points)
|
2017-03-29 20:34:24 +00:00
|
|
|
|
{
|
|
|
|
|
// Create a new line if one doesn't exist already
|
|
|
|
|
if(!currentLines.ContainsKey(lineId))
|
2017-06-30 15:47:29 +00:00
|
|
|
|
throw new InvalidOperationException($"Error: A line with the id {lineId} doesn't exist, so you can't add to it.");
|
2017-03-29 20:34:24 +00:00
|
|
|
|
|
|
|
|
|
// Add these points to the line
|
|
|
|
|
currentLines[lineId].Points.AddRange(points);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Mark a line as complete and remove it from the incubator.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lineId">The id of the line to complete.</param>
|
|
|
|
|
/// <returns>The completed line.</returns>
|
2017-04-23 16:11:46 +00:00
|
|
|
|
public DrawnLine CompleteLine(string lineId)
|
2017-03-29 20:34:24 +00:00
|
|
|
|
{
|
|
|
|
|
if(!currentLines.ContainsKey(lineId))
|
|
|
|
|
throw new KeyNotFoundException("Error: A line with that id wasn't found in this LineIncubator.");
|
|
|
|
|
|
2017-04-23 17:06:58 +00:00
|
|
|
|
Log.WriteLine("[LineIncubator] Completing line #{0}", lineId);
|
|
|
|
|
|
2017-03-29 20:34:24 +00:00
|
|
|
|
DrawnLine completedLine = currentLines[lineId];
|
|
|
|
|
currentLines.Remove(lineId);
|
|
|
|
|
|
|
|
|
|
return completedLine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|