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:
parent
dd184b38ac
commit
23514f788d
7 changed files with 95 additions and 22 deletions
|
@ -44,6 +44,21 @@ namespace Nibriboard.Client
|
||||||
return false;
|
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>
|
/// <summary>
|
||||||
/// Adds a series of points to the incomplete line with the specified id.
|
/// Adds a series of points to the incomplete line with the specified id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -53,7 +68,7 @@ namespace Nibriboard.Client
|
||||||
{
|
{
|
||||||
// Create a new line if one doesn't exist already
|
// Create a new line if one doesn't exist already
|
||||||
if(!currentLines.ContainsKey(lineId))
|
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
|
// Add these points to the line
|
||||||
currentLines[lineId].Points.AddRange(points);
|
currentLines[lineId].Points.AddRange(points);
|
||||||
|
|
|
@ -7,14 +7,6 @@ namespace Nibriboard.Client.Messages
|
||||||
/// The id of the line to complete
|
/// The id of the line to complete
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string LineId;
|
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()
|
public LineCompleteMessage()
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,14 +11,6 @@ namespace Nibriboard.Client.Messages
|
||||||
/// The id of the line to complete
|
/// The id of the line to complete
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string LineId;
|
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()
|
public LineCompleteReflectionMessage()
|
||||||
{
|
{
|
||||||
|
|
23
Nibriboard/Client/Messages/LineStartMessage.cs
Normal file
23
Nibriboard/Client/Messages/LineStartMessage.cs
Normal 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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
Nibriboard/Client/Messages/LineStartReflectionMessage.cs
Normal file
27
Nibriboard/Client/Messages/LineStartReflectionMessage.cs
Normal 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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,6 +55,7 @@ namespace Nibriboard.Client
|
||||||
["CursorPosition"] = typeof(CursorPositionMessage),
|
["CursorPosition"] = typeof(CursorPositionMessage),
|
||||||
["PlaneChange"] = typeof(PlaneChangeMessage),
|
["PlaneChange"] = typeof(PlaneChangeMessage),
|
||||||
["ChunkUpdateRequest"] = typeof(ChunkUpdateRequestMessage),
|
["ChunkUpdateRequest"] = typeof(ChunkUpdateRequestMessage),
|
||||||
|
["LineStart"] = typeof(LineStartMessage),
|
||||||
["LinePart"] = typeof(LinePartMessage),
|
["LinePart"] = typeof(LinePartMessage),
|
||||||
["LineComplete"] = typeof(LineCompleteMessage)
|
["LineComplete"] = typeof(LineCompleteMessage)
|
||||||
};
|
};
|
||||||
|
@ -384,6 +385,31 @@ namespace Nibriboard.Client
|
||||||
return Task.CompletedTask;
|
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>
|
/// <summary>
|
||||||
/// Handles messages containing a fragment of a line from the client.
|
/// Handles messages containing a fragment of a line from the client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -421,8 +447,6 @@ namespace Nibriboard.Client
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DrawnLine line = manager.LineIncubator.CompleteLine(message.LineId);
|
DrawnLine line = manager.LineIncubator.CompleteLine(message.LineId);
|
||||||
line.Width = message.LineWidth;
|
|
||||||
line.Colour = message.LineColour;
|
|
||||||
|
|
||||||
if(CurrentPlane == null)
|
if(CurrentPlane == null)
|
||||||
{
|
{
|
||||||
|
@ -437,9 +461,7 @@ namespace Nibriboard.Client
|
||||||
Log.WriteLine("[NibriClient#{0}] Adding {1}px {2} line", Id, line.Width, line.Colour);
|
Log.WriteLine("[NibriClient#{0}] Adding {1}px {2} line", Id, line.Width, line.Colour);
|
||||||
manager.BroadcastPlane(this, new LineCompleteReflectionMessage() {
|
manager.BroadcastPlane(this, new LineCompleteReflectionMessage() {
|
||||||
OtherClientId = Id,
|
OtherClientId = Id,
|
||||||
LineId = line.LineId,
|
LineId = line.LineId
|
||||||
LineColour = line.Colour,
|
|
||||||
LineWidth = line.Width
|
|
||||||
});
|
});
|
||||||
await CurrentPlane.AddLine(line);
|
await CurrentPlane.AddLine(line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,8 @@
|
||||||
<Compile Include="Client\RawChunkReference.cs" />
|
<Compile Include="Client\RawChunkReference.cs" />
|
||||||
<Compile Include="Client\Messages\LinePartReflectionMessage.cs" />
|
<Compile Include="Client\Messages\LinePartReflectionMessage.cs" />
|
||||||
<Compile Include="Client\Messages\LineCompleteReflectionMessage.cs" />
|
<Compile Include="Client\Messages\LineCompleteReflectionMessage.cs" />
|
||||||
|
<Compile Include="Client\Messages\LineStartMessage.cs" />
|
||||||
|
<Compile Include="Client\Messages\LineStartReflectionMessage.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="ClientFiles\index.html" />
|
<EmbeddedResource Include="ClientFiles\index.html" />
|
||||||
|
|
Loading…
Reference in a new issue