fix: added missing types for new primitives
This commit is contained in:
@@ -144,18 +144,26 @@ public abstract class LiteNetLibCommunicatorBase : Behaviour, INetworkCommunicat
|
||||
{
|
||||
// I know, ugly af. I need to find a better way
|
||||
netPacketProcessor.RegisterNestedType(AABB2DNetPacker.Write, AABB2DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(AABB3DNetPacker.Write, AABB3DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(CircleNetPacker.Write, CircleNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(ColorHSVNetPacker.Write, ColorHSVNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(ColorRGBANetPacker.Write, ColorRGBANetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(ColorHSVANetPacker.Write, ColorHSVANetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(ColorRGBNetPacker.Write, ColorRGBNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Line2DEquationNetPacker.Write, Line2DEquationNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(ColorRGBANetPacker.Write, ColorRGBANetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Line2DNetPacker.Write, Line2DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Line2DEquationNetPacker.Write, Line2DEquationNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Line3DNetPacker.Write, Line3DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Projection1DNetPacker.Write, Projection1DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(QuaternionNetPacker.Write, QuaternionNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Ray2DNetPacker.Write, Ray2DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Ray3DNetPacker.Write, Ray3DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Shape2DNetPacker.Write, Shape2DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(TriangleNetPacker.Write, TriangleNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Vector2DNetPacker.Write, Vector2DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Vector2DIntNetPacker.Write, Vector2DIntNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Vector3DNetPacker.Write, Vector3DNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Vector3DIntNetPacker.Write, Vector3DIntNetPacker.Read);
|
||||
netPacketProcessor.RegisterNestedType(Vector4DNetPacker.Write, Vector4DNetPacker.Read);
|
||||
}
|
||||
|
||||
public INetworkCommunicator SubscribeToPackets<T>(Event<IConnection, T>.EventHandler callback)
|
||||
|
@@ -0,0 +1,26 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
internal static class ColorHSVANetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, ColorHSVA data)
|
||||
{
|
||||
writer.Put(data.Hue);
|
||||
writer.Put(data.Saturation);
|
||||
writer.Put(data.Value);
|
||||
writer.Put(data.Alpha);
|
||||
}
|
||||
|
||||
internal static ColorHSVA Read(NetDataReader reader)
|
||||
{
|
||||
float hue = reader.GetFloat();
|
||||
float saturation = reader.GetFloat();
|
||||
float value = reader.GetFloat();
|
||||
float alpha = reader.GetFloat();
|
||||
|
||||
return new ColorHSVA(hue, saturation, value, alpha);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
internal static class Line3DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Line3D data)
|
||||
{
|
||||
Vector3DNetPacker.Write(writer, data.From);
|
||||
Vector3DNetPacker.Write(writer, data.To);
|
||||
}
|
||||
|
||||
internal static Line3D Read(NetDataReader reader)
|
||||
{
|
||||
Vector3D from = Vector3DNetPacker.Read(reader);
|
||||
Vector3D to = Vector3DNetPacker.Read(reader);
|
||||
|
||||
return new Line3D(from, to);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
internal static class Ray2DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Ray2D data)
|
||||
{
|
||||
Vector2DNetPacker.Write(writer, data.Origin);
|
||||
Vector2DNetPacker.Write(writer, data.Direction);
|
||||
}
|
||||
|
||||
internal static Ray2D Read(NetDataReader reader)
|
||||
{
|
||||
Vector2D from = Vector2DNetPacker.Read(reader);
|
||||
Vector2D direction = Vector2DNetPacker.Read(reader);
|
||||
|
||||
return new Ray2D(from, direction);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
internal static class Ray3DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Ray3D data)
|
||||
{
|
||||
Vector3DNetPacker.Write(writer, data.Origin);
|
||||
Vector3DNetPacker.Write(writer, data.Direction);
|
||||
}
|
||||
|
||||
internal static Ray3D Read(NetDataReader reader)
|
||||
{
|
||||
Vector3D from = Vector3DNetPacker.Read(reader);
|
||||
Vector3D direction = Vector3DNetPacker.Read(reader);
|
||||
|
||||
return new Ray3D(from, direction);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
internal static class Vector2DIntNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Vector2DInt data)
|
||||
{
|
||||
writer.Put(data.X);
|
||||
writer.Put(data.Y);
|
||||
}
|
||||
|
||||
internal static Vector2DInt Read(NetDataReader reader)
|
||||
{
|
||||
int x = reader.GetInt();
|
||||
int y = reader.GetInt();
|
||||
|
||||
return new Vector2DInt(x, y);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
internal static class Vector3DIntNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Vector3DInt data)
|
||||
{
|
||||
writer.Put(data.X);
|
||||
writer.Put(data.Y);
|
||||
writer.Put(data.Z);
|
||||
}
|
||||
|
||||
internal static Vector3DInt Read(NetDataReader reader)
|
||||
{
|
||||
int x = reader.GetInt();
|
||||
int y = reader.GetInt();
|
||||
int z = reader.GetInt();
|
||||
|
||||
return new Vector3DInt(x, y, z);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using LiteNetLib.Utils;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
namespace Engine.Systems.Network;
|
||||
|
||||
internal static class Vector4DNetPacker
|
||||
{
|
||||
internal static void Write(NetDataWriter writer, Vector4D data)
|
||||
{
|
||||
writer.Put(data.X);
|
||||
writer.Put(data.Y);
|
||||
writer.Put(data.Z);
|
||||
writer.Put(data.W);
|
||||
}
|
||||
|
||||
internal static Vector4D Read(NetDataReader reader)
|
||||
{
|
||||
float x = reader.GetFloat();
|
||||
float y = reader.GetFloat();
|
||||
float z = reader.GetFloat();
|
||||
float w = reader.GetFloat();
|
||||
|
||||
return new Vector4D(x, y, z, w);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class ColorHSVAConverter : EngineTypeYamlSerializerBase<ColorHSVA>
|
||||
{
|
||||
private static readonly int SUBSTRING_START_LENGTH = nameof(ColorHSVA).Length + 1;
|
||||
|
||||
public override ColorHSVA Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
string value = parser.Consume<Scalar>().Value;
|
||||
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||
string[] values = insideParenthesis.Split(", ");
|
||||
return new ColorHSVA(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3]));
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
ColorHSVA hsva = (ColorHSVA)value!;
|
||||
emitter.Emit(new Scalar($"{nameof(ColorHSVA)}({hsva.Hue}, {hsva.Saturation}, {hsva.Value}, {hsva.Alpha})"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Line3DConverter : EngineTypeYamlSerializerBase<Line3D>
|
||||
{
|
||||
public override Line3D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
parser.Consume<MappingStart>();
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Line3D.From)) != 0)
|
||||
throw new ArgumentException($"{nameof(Line3D)} mapping must start with {nameof(Line3D.From)}");
|
||||
Vector3D from = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Line3D.To)) != 0)
|
||||
throw new ArgumentException($"{nameof(Line3D)} mapping must end with {nameof(Line3D.To)}");
|
||||
Vector3D to = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||
|
||||
parser.Consume<MappingEnd>();
|
||||
|
||||
return new Line3D(from, to);
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Line3D line3D = (Line3D)value!;
|
||||
|
||||
emitter.Emit(new MappingStart());
|
||||
emitter.Emit(new Scalar(nameof(Line3D.From)));
|
||||
serializer(line3D.From, typeof(Vector3D));
|
||||
emitter.Emit(new Scalar(nameof(Line3D.To)));
|
||||
serializer(line3D.To, typeof(Vector3D));
|
||||
emitter.Emit(new MappingEnd());
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Ray2DConverter : EngineTypeYamlSerializerBase<Ray2D>
|
||||
{
|
||||
public override Ray2D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
parser.Consume<MappingStart>();
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray2D.Origin)) != 0)
|
||||
throw new ArgumentException($"{nameof(Ray2D)} mapping must start with {nameof(Ray2D.Origin)}");
|
||||
Vector2D origin = (Vector2D)rootDeserializer(typeof(Vector2D))!;
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray2D.Direction)) != 0)
|
||||
throw new ArgumentException($"{nameof(Ray2D)} mapping must end with {nameof(Ray2D.Direction)}");
|
||||
Vector2D direction = (Vector2D)rootDeserializer(typeof(Vector2D))!;
|
||||
|
||||
parser.Consume<MappingEnd>();
|
||||
|
||||
return new Ray2D(origin, direction);
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Ray2D ray2D = (Ray2D)value!;
|
||||
|
||||
emitter.Emit(new MappingStart());
|
||||
emitter.Emit(new Scalar(nameof(ray2D.Origin)));
|
||||
serializer(ray2D.Origin, typeof(Vector2D));
|
||||
emitter.Emit(new Scalar(nameof(ray2D.Direction)));
|
||||
serializer(ray2D.Direction, typeof(Vector2D));
|
||||
emitter.Emit(new MappingEnd());
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Ray3DConverter : EngineTypeYamlSerializerBase<Ray3D>
|
||||
{
|
||||
public override Ray3D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
parser.Consume<MappingStart>();
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray3D.Origin)) != 0)
|
||||
throw new ArgumentException($"{nameof(Ray3D)} mapping must start with {nameof(Ray3D.Origin)}");
|
||||
Vector3D origin = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||
|
||||
if (parser.Consume<Scalar>().Value.CompareTo(nameof(Ray3D.Direction)) != 0)
|
||||
throw new ArgumentException($"{nameof(Ray3D)} mapping must end with {nameof(Ray3D.Direction)}");
|
||||
Vector3D direction = (Vector3D)rootDeserializer(typeof(Vector3D))!;
|
||||
|
||||
parser.Consume<MappingEnd>();
|
||||
|
||||
return new Ray3D(origin, direction);
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Ray3D ray3D = (Ray3D)value!;
|
||||
|
||||
emitter.Emit(new MappingStart());
|
||||
emitter.Emit(new Scalar(nameof(ray3D.Origin)));
|
||||
serializer(ray3D.Origin, typeof(Vector3D));
|
||||
emitter.Emit(new Scalar(nameof(ray3D.Direction)));
|
||||
serializer(ray3D.Direction, typeof(Vector3D));
|
||||
emitter.Emit(new MappingEnd());
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Vector2DIntConverter : EngineTypeYamlSerializerBase<Vector2DInt>
|
||||
{
|
||||
private static readonly int SUBSTRING_START_LENGTH = nameof(Vector2DInt).Length + 1;
|
||||
|
||||
public override Vector2DInt Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
string value = parser.Consume<Scalar>().Value;
|
||||
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||
string[] values = insideParenthesis.Split(", ");
|
||||
return new Vector2DInt(int.Parse(values[0]), int.Parse(values[1]));
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Vector2DInt vector2DInt = (Vector2DInt)value!;
|
||||
emitter.Emit(new Scalar($"{nameof(Vector2DInt)}({vector2DInt.X}, {vector2DInt.Y})"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Vector3DIntConverter : EngineTypeYamlSerializerBase<Vector3DInt>
|
||||
{
|
||||
private static readonly int SUBSTRING_START_LENGTH = nameof(Vector3DInt).Length + 1;
|
||||
|
||||
public override Vector3DInt Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
string value = parser.Consume<Scalar>().Value;
|
||||
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||
string[] values = insideParenthesis.Split(", ");
|
||||
return new Vector3DInt(int.Parse(values[0]), int.Parse(values[1]), int.Parse(values[2]));
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Vector3DInt vector3DInt = (Vector3DInt)value!;
|
||||
emitter.Emit(new Scalar($"{nameof(Vector3DInt)}({vector3DInt.X}, {vector3DInt.Y}, {vector3DInt.Z})"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Vector4DConverter : EngineTypeYamlSerializerBase<Vector4D>
|
||||
{
|
||||
private static readonly int SUBSTRING_START_LENGTH = nameof(Vector4D).Length + 1;
|
||||
|
||||
public override Vector4D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
string value = parser.Consume<Scalar>().Value;
|
||||
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||
string[] values = insideParenthesis.Split(", ");
|
||||
return new Vector4D(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3]));
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Vector4D vector4D = (Vector4D)value!;
|
||||
emitter.Emit(new Scalar($"{nameof(Vector4D)}({vector4D.X}, {vector4D.Y}, {vector4D.Z}, {vector4D.W})"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user