diff --git a/Nibriboard/Client/Messages/LineRemoveMessage.cs b/Nibriboard/Client/Messages/LineRemoveMessage.cs new file mode 100644 index 0000000..410c02f --- /dev/null +++ b/Nibriboard/Client/Messages/LineRemoveMessage.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Nibriboard.RippleSpace; + +namespace Nibriboard.Client.Messages +{ + public class LineRemoveMessage : Message + { + /// + /// A reference to the chunk that contains the line to remove. + /// + public RawChunkReference ContainingChunk; + + /// + /// The unique id of the line segment to remove. + /// + public string UniqueId; + + public LineRemoveMessage() + { + } + + /// + /// Returns the raw ContainingChunk as a ChunkReference. + /// + /// The plane to put the chunk reference on. + /// The containing chunk as a regular chunk reference. + public ChunkReference ConvertedContainingChunk(Plane plane) + { + if(ContainingChunk.planeName as string != plane.Name) + throw new InvalidDataException($"Error: A raw reference was for the plane " + + "'{rawRef.planeName}', but the plane '{plane.Name}' " + + "was specified as the plane to lay the chunk references onto!"); + + return new ChunkReference(plane, ContainingChunk.x, ContainingChunk.y); + } + } +} diff --git a/Nibriboard/Client/NibriClient.cs b/Nibriboard/Client/NibriClient.cs index 790b541..daf1273 100644 --- a/Nibriboard/Client/NibriClient.cs +++ b/Nibriboard/Client/NibriClient.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using System.Text; using System.Linq; using System.Reflection; @@ -59,6 +58,7 @@ namespace Nibriboard.Client ["LineStart"] = typeof(LineStartMessage), ["LinePart"] = typeof(LinePartMessage), ["LineComplete"] = typeof(LineCompleteMessage), + ["LineRemove"] = typeof(LineRemoveMessage), ["ViewportUpdate"] = typeof(ViewportUpdateMessage) }; @@ -189,7 +189,7 @@ namespace Nibriboard.Client #region Message Sending /// - /// Sends a to the client. + /// Sends a to the client. /// If you *really* need to send a raw message to the client, you can do so with the SendRawa() method. /// /// The message to send. @@ -487,6 +487,19 @@ namespace Nibriboard.Client await CurrentPlane.AddLine(line); } + /// + /// Handles messages requesting that a line be removed from a chunk. + /// + /// The message to handle. + protected async Task handleLineRemoveMessage(LineRemoveMessage message) + { + bool removeSuccess = await CurrentPlane.RemoveLineSegment( + message.ConvertedContainingChunk(CurrentPlane), + message.UniqueId + ); + Log.WriteLine("[NibriClient#{1}] " + (removeSuccess ? "Removed" : "Failed to remove") + " line segment with unique id {0} from {1}", message.UniqueId, message.ConvertedContainingChunk(CurrentPlane)); + } + #endregion #region RippleSpace Event Handlers diff --git a/Nibriboard/Nibriboard.csproj b/Nibriboard/Nibriboard.csproj index d965c09..7fb965b 100644 --- a/Nibriboard/Nibriboard.csproj +++ b/Nibriboard/Nibriboard.csproj @@ -137,6 +137,7 @@ + - - - - - - - + + + + + + + diff --git a/Nibriboard/RippleSpace/Chunk.cs b/Nibriboard/RippleSpace/Chunk.cs index 059cfd8..b3d2ce5 100644 --- a/Nibriboard/RippleSpace/Chunk.cs +++ b/Nibriboard/RippleSpace/Chunk.cs @@ -199,6 +199,15 @@ namespace Nibriboard.RippleSpace OnChunkUpdate(this, new ChunkUpdateEventArgs() { UpdateType = ChunkUpdateType.Addition }); } + /// + /// Removes the line in this chunk with the specified unique id. + /// + /// The id of the line to remove. + public bool Remove(string targetLineUniqueId) + { + return lines.RemoveAll((line) => line.UniqueId == targetLineUniqueId) > 0; + } + public IEnumerator GetEnumerator() { UpdateAccessTime(); diff --git a/Nibriboard/RippleSpace/Plane.cs b/Nibriboard/RippleSpace/Plane.cs index 7a8be19..8a93482 100644 --- a/Nibriboard/RippleSpace/Plane.cs +++ b/Nibriboard/RippleSpace/Plane.cs @@ -229,6 +229,12 @@ namespace Nibriboard.RippleSpace } } + public async Task RemoveLineSegment(ChunkReference containingChunk, string targetLineUniqueId) + { + Chunk chunk = await FetchChunk(containingChunk); + return chunk.Remove(targetLineUniqueId); + } + public void PerformMaintenance() { // Be lazy and don't bother to perform maintenance if it's not needed