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

[server] Add line start event.

This commit is contained in:
Starbeamrainbowlabs 2017-06-30 16:47:29 +01:00
parent dd184b38ac
commit 23514f788d
7 changed files with 95 additions and 22 deletions

View file

@ -44,6 +44,21 @@ namespace Nibriboard.Client
return false;
}
/// <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
});
}
/// <summary>
/// Adds a series of points to the incomplete line with the specified id.
/// </summary>
@ -53,7 +68,7 @@ namespace Nibriboard.Client
{
// Create a new line if one doesn't exist already
if(!currentLines.ContainsKey(lineId))
currentLines.Add(lineId, new DrawnLine(lineId));
throw new InvalidOperationException($"Error: A line with the id {lineId} doesn't exist, so you can't add to it.");
// Add these points to the line
currentLines[lineId].Points.AddRange(points);

View file

@ -7,14 +7,6 @@ namespace Nibriboard.Client.Messages
/// The id of the line to complete
/// </summary>
public string LineId;
/// <summary>
/// The colour of the line. May be any valid colour accepted by the HTML5 Canvas API.
/// </summary>
public string LineColour;
/// <summary>
/// The width of the line, in pixels.
/// </summary>
public int LineWidth;
public LineCompleteMessage()
{

View file

@ -11,14 +11,6 @@ namespace Nibriboard.Client.Messages
/// The id of the line to complete
/// </summary>
public string LineId;
/// <summary>
/// The colour of the line. May be any valid colour accepted by the HTML5 Canvas API.
/// </summary>
public string LineColour;
/// <summary>
/// The width of the line, in pixels.
/// </summary>
public int LineWidth;
public LineCompleteReflectionMessage()
{

View file

@ -0,0 +1,23 @@
using System;
namespace Nibriboard.Client.Messages
{
public class LineStartMessage : Message
{
/// <summary>
/// The id of the line to complete
/// </summary>
public string LineId;
/// <summary>
/// The colour of the line. May be any valid colour accepted by the HTML5 Canvas API.
/// </summary>
public string LineColour;
/// <summary>
/// The width of the line, in pixels.
/// </summary>
public int LineWidth;
public LineStartMessage()
{
}
}
}

View file

@ -0,0 +1,27 @@
using System;
namespace Nibriboard.Client.Messages
{
public class LineStartReflectionMessage : Message
{
/// <summary>
/// The id of the client that has completed drawing a line.
/// </summary>
public int OtherClientId;
/// <summary>
/// The id of the line to complete
/// </summary>
public string LineId;
/// <summary>
/// The colour of the line. May be any valid colour accepted by the HTML5 Canvas API.
/// </summary>
public string LineColour;
/// <summary>
/// The width of the line, in pixels.
/// </summary>
public int LineWidth;
public LineStartReflectionMessage()
{
}
}
}

View file

@ -55,6 +55,7 @@ namespace Nibriboard.Client
["CursorPosition"] = typeof(CursorPositionMessage),
["PlaneChange"] = typeof(PlaneChangeMessage),
["ChunkUpdateRequest"] = typeof(ChunkUpdateRequestMessage),
["LineStart"] = typeof(LineStartMessage),
["LinePart"] = typeof(LinePartMessage),
["LineComplete"] = typeof(LineCompleteMessage)
};
@ -384,6 +385,31 @@ namespace Nibriboard.Client
return Task.CompletedTask;
}
/// <summary>
/// Handles line start events from the client.
/// These messages are currently only required to let other clients know about
/// lines that are being drawn and their properties for live display.
/// </summary>
/// <param name="message">The LineStartMessage to process.</param>
protected Task handleLineStartMessage(LineStartMessage message)
{
// Create a new line
manager.LineIncubator.CreateLine(
message.LineId,
message.LineColour,
message.LineWidth
);
manager.BroadcastPlane(this, new LineStartReflectionMessage() {
OtherClientId = Id,
LineId = message.LineId,
LineColour = message.LineColour,
LineWidth = message.LineWidth
});
return Task.CompletedTask;
}
/// <summary>
/// Handles messages containing a fragment of a line from the client.
/// </summary>
@ -421,8 +447,6 @@ namespace Nibriboard.Client
return;
}
DrawnLine line = manager.LineIncubator.CompleteLine(message.LineId);
line.Width = message.LineWidth;
line.Colour = message.LineColour;
if(CurrentPlane == null)
{
@ -437,9 +461,7 @@ namespace Nibriboard.Client
Log.WriteLine("[NibriClient#{0}] Adding {1}px {2} line", Id, line.Width, line.Colour);
manager.BroadcastPlane(this, new LineCompleteReflectionMessage() {
OtherClientId = Id,
LineId = line.LineId,
LineColour = line.Colour,
LineWidth = line.Width
LineId = line.LineId
});
await CurrentPlane.AddLine(line);
}

View file

@ -103,6 +103,8 @@
<Compile Include="Client\RawChunkReference.cs" />
<Compile Include="Client\Messages\LinePartReflectionMessage.cs" />
<Compile Include="Client\Messages\LineCompleteReflectionMessage.cs" />
<Compile Include="Client\Messages\LineStartMessage.cs" />
<Compile Include="Client\Messages\LineStartReflectionMessage.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ClientFiles\index.html" />