mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[server] Add protocol event to remove a line segment by unique id
This commit is contained in:
parent
56fd7d8460
commit
5c12d13600
5 changed files with 77 additions and 9 deletions
39
Nibriboard/Client/Messages/LineRemoveMessage.cs
Normal file
39
Nibriboard/Client/Messages/LineRemoveMessage.cs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Nibriboard.RippleSpace;
|
||||||
|
|
||||||
|
namespace Nibriboard.Client.Messages
|
||||||
|
{
|
||||||
|
public class LineRemoveMessage : Message
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A reference to the chunk that contains the line to remove.
|
||||||
|
/// </summary>
|
||||||
|
public RawChunkReference ContainingChunk;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The unique id of the line segment to remove.
|
||||||
|
/// </summary>
|
||||||
|
public string UniqueId;
|
||||||
|
|
||||||
|
public LineRemoveMessage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the raw ContainingChunk as a ChunkReference.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane">The plane to put the chunk reference on.</param>
|
||||||
|
/// <returns>The containing chunk as a regular chunk reference.</returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
@ -59,6 +58,7 @@ namespace Nibriboard.Client
|
||||||
["LineStart"] = typeof(LineStartMessage),
|
["LineStart"] = typeof(LineStartMessage),
|
||||||
["LinePart"] = typeof(LinePartMessage),
|
["LinePart"] = typeof(LinePartMessage),
|
||||||
["LineComplete"] = typeof(LineCompleteMessage),
|
["LineComplete"] = typeof(LineCompleteMessage),
|
||||||
|
["LineRemove"] = typeof(LineRemoveMessage),
|
||||||
["ViewportUpdate"] = typeof(ViewportUpdateMessage)
|
["ViewportUpdate"] = typeof(ViewportUpdateMessage)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ namespace Nibriboard.Client
|
||||||
#region Message Sending
|
#region Message Sending
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a <see cref="Nibriboard.Client.Messages.Message"/> to the client.
|
/// Sends a <see cref="Message"/> to the client.
|
||||||
/// If you *really* need to send a raw message to the client, you can do so with the SendRawa() method.
|
/// If you *really* need to send a raw message to the client, you can do so with the SendRawa() method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">The message to send.</param>
|
/// <param name="message">The message to send.</param>
|
||||||
|
@ -487,6 +487,19 @@ namespace Nibriboard.Client
|
||||||
await CurrentPlane.AddLine(line);
|
await CurrentPlane.AddLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles messages requesting that a line be removed from a chunk.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message to handle.</param>
|
||||||
|
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
|
#endregion
|
||||||
|
|
||||||
#region RippleSpace Event Handlers
|
#region RippleSpace Event Handlers
|
||||||
|
|
|
@ -137,6 +137,7 @@
|
||||||
<Compile Include="Client\Messages\ViewportUpdateMessage.cs" />
|
<Compile Include="Client\Messages\ViewportUpdateMessage.cs" />
|
||||||
<Compile Include="NibriboardApp.cs" />
|
<Compile Include="NibriboardApp.cs" />
|
||||||
<Compile Include="Utilities\LineSimplifier.cs" />
|
<Compile Include="Utilities\LineSimplifier.cs" />
|
||||||
|
<Compile Include="Client\Messages\LineRemoveMessage.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<!--
|
<!--
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -199,6 +199,15 @@ namespace Nibriboard.RippleSpace
|
||||||
OnChunkUpdate(this, new ChunkUpdateEventArgs() { UpdateType = ChunkUpdateType.Addition });
|
OnChunkUpdate(this, new ChunkUpdateEventArgs() { UpdateType = ChunkUpdateType.Addition });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the line in this chunk with the specified unique id.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="targetLineUniqueId">The id of the line to remove.</param>
|
||||||
|
public bool Remove(string targetLineUniqueId)
|
||||||
|
{
|
||||||
|
return lines.RemoveAll((line) => line.UniqueId == targetLineUniqueId) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerator<DrawnLine> GetEnumerator()
|
public IEnumerator<DrawnLine> GetEnumerator()
|
||||||
{
|
{
|
||||||
UpdateAccessTime();
|
UpdateAccessTime();
|
||||||
|
|
|
@ -229,6 +229,12 @@ namespace Nibriboard.RippleSpace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> RemoveLineSegment(ChunkReference containingChunk, string targetLineUniqueId)
|
||||||
|
{
|
||||||
|
Chunk chunk = await FetchChunk(containingChunk);
|
||||||
|
return chunk.Remove(targetLineUniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
public void PerformMaintenance()
|
public void PerformMaintenance()
|
||||||
{
|
{
|
||||||
// Be lazy and don't bother to perform maintenance if it's not needed
|
// Be lazy and don't bother to perform maintenance if it's not needed
|
||||||
|
|
Loading…
Reference in a new issue