1
0
Fork 0

Get chunks and references serialising correctly

This commit is contained in:
Starbeamrainbowlabs 2017-05-29 13:14:56 +01:00
parent db4a9311d5
commit a7132d344d
3 changed files with 32 additions and 1 deletions

View File

@ -4,6 +4,7 @@ using System.Threading.Tasks;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections; using System.Collections;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace Nibriboard.RippleSpace namespace Nibriboard.RippleSpace
{ {
@ -37,6 +38,7 @@ namespace Nibriboard.RippleSpace
/// Represents a single chunk of an infinite <see cref="NibriboardServer.RippleSpace.Plane" />. /// Represents a single chunk of an infinite <see cref="NibriboardServer.RippleSpace.Plane" />.
/// </summary> /// </summary>
[Serializable] [Serializable]
[JsonObject(MemberSerialization.OptIn)]
public class Chunk : IEnumerable<DrawnLine>, IDeserializationCallback public class Chunk : IEnumerable<DrawnLine>, IDeserializationCallback
{ {
/// <summary> /// <summary>
@ -47,7 +49,8 @@ namespace Nibriboard.RippleSpace
/// <summary> /// <summary>
/// The name of the plane that this chunk is on. /// The name of the plane that this chunk is on.
/// </summary> /// </summary>
/// <value>The name of the plane.</value> /// <value>The name of the plane.</value>
[JsonProperty]
public string PlaneName { public string PlaneName {
get { get {
return plane.Name; return plane.Name;
@ -57,16 +60,19 @@ namespace Nibriboard.RippleSpace
/// <summary> /// <summary>
/// The lines that this chunk currently contains. /// The lines that this chunk currently contains.
/// </summary> /// </summary>
[JsonProperty]
private List<DrawnLine> lines = new List<DrawnLine>(); private List<DrawnLine> lines = new List<DrawnLine>();
/// <summary> /// <summary>
/// The size of this chunk. /// The size of this chunk.
/// </summary> /// </summary>
[JsonProperty]
public readonly int Size; public readonly int Size;
/// <summary> /// <summary>
/// The location of this chunk, in chunk-space, on the plane. /// The location of this chunk, in chunk-space, on the plane.
/// </summary> /// </summary>
[JsonProperty]
public readonly ChunkReference Location; public readonly ChunkReference Location;
/// <summary> /// <summary>
@ -86,6 +92,7 @@ namespace Nibriboard.RippleSpace
/// Whether this <see cref="T:Nibriboard.RippleSpace.Chunk"/> is primary chunk. /// Whether this <see cref="T:Nibriboard.RippleSpace.Chunk"/> is primary chunk.
/// Primary chunks are always loaded. /// Primary chunks are always loaded.
/// </summary> /// </summary>
[JsonProperty]
public bool IsPrimaryChunk public bool IsPrimaryChunk
{ {
get { get {

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using SBRL.Utilities; using SBRL.Utilities;
namespace Nibriboard.RippleSpace namespace Nibriboard.RippleSpace

View File

@ -1,15 +1,38 @@
using System; using System;
using Newtonsoft.Json;
namespace Nibriboard.RippleSpace namespace Nibriboard.RippleSpace
{ {
/// <summary> /// <summary>
/// An abstract class representing a coordinate reference to a location. /// An abstract class representing a coordinate reference to a location.
/// </summary> /// </summary>
[JsonObject(MemberSerialization.OptIn)]
public abstract class Reference : ICloneable public abstract class Reference : ICloneable
{ {
public readonly Plane Plane; public readonly Plane Plane;
/// <summary>
/// The name of the plane that this reference is located on.
/// Mainly used by the serialisation system that sends things to the client.
/// </summary>
[JsonProperty]
public string PlaneName
{
get {
return Plane.Name;
}
}
/// <summary>
/// The x position of this reference.
/// </summary>
[JsonProperty]
public int X { get; set; } public int X { get; set; }
/// <summary>
/// The y position of this reference.
/// </summary>
[JsonProperty]
public int Y { get; set; } public int Y { get; set; }
public Reference(Plane inPlane, int inX, int inY) public Reference(Plane inPlane, int inX, int inY)