Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace Exiled.Loader.Features.Configs.CustomConverters

using Exiled.API.Features;
using Exiled.API.Features.Pools;

using UnityEngine;

using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
Expand All @@ -36,13 +34,20 @@ public bool Accepts(Type type)
/// <inheritdoc cref="IYamlTypeConverter" />
public object ReadYaml(IParser parser, Type type)
{
Type baseType = Nullable.GetUnderlyingType(type) ?? type;
Type baseType = Nullable.GetUnderlyingType(type);

bool isNullable = true;
if (baseType == null)
{
baseType = type;
isNullable = false;
}

if (parser.TryConsume(out Scalar scalar))
{
if (string.IsNullOrEmpty(scalar.Value) || scalar.Value.Equals("null", StringComparison.OrdinalIgnoreCase))
{
if (Nullable.GetUnderlyingType(type) != null)
if (isNullable)
return null;

Log.Error($"Cannot assign null to non-nullable type {baseType.FullName}.");
Expand Down Expand Up @@ -83,7 +88,11 @@ public object ReadYaml(IParser parser, Type type)
}
}

object color = Activator.CreateInstance(type, coordinates.ToArray());
object color;
if (isNullable)
color = Activator.CreateInstance(type, Activator.CreateInstance(baseType, coordinates.ToArray()));
else
color = Activator.CreateInstance(type, coordinates.ToArray());

ListPool<object>.Pool.Return(coordinates);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace Exiled.Loader.Features.Configs.CustomConverters

using Exiled.API.Features;
using Exiled.API.Features.Pools;

using UnityEngine;

using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
Expand All @@ -30,19 +28,26 @@ public sealed class VectorsConverter : IYamlTypeConverter
public bool Accepts(Type type)
{
Type baseType = Nullable.GetUnderlyingType(type) ?? type;
return baseType == typeof(Vector2) || baseType == typeof(Vector3) || baseType == typeof(Vector4);
return baseType == typeof(Vector2) || baseType == typeof(Vector3) || baseType == typeof(Vector4) || baseType == typeof(Quaternion);
}

/// <inheritdoc cref="IYamlTypeConverter" />
public object ReadYaml(IParser parser, Type type)
{
Type baseType = Nullable.GetUnderlyingType(type) ?? type;
Type baseType = Nullable.GetUnderlyingType(type);

bool isNullable = true;
if (baseType == null)
{
isNullable = false;
baseType = type;
}

if (parser.TryConsume(out Scalar scalar))
{
if (string.IsNullOrEmpty(scalar.Value) || scalar.Value.Equals("null", StringComparison.OrdinalIgnoreCase))
{
if (Nullable.GetUnderlyingType(type) != null)
if (isNullable)
return null;

Log.Error($"Cannot assign null to non-nullable type {baseType.FullName}.");
Expand Down Expand Up @@ -75,7 +80,11 @@ public object ReadYaml(IParser parser, Type type)
coordinates.Add(coordinate);
}

object vector = Activator.CreateInstance(baseType, coordinates.ToArray());
object vector;
if (isNullable)
vector = Activator.CreateInstance(type, Activator.CreateInstance(baseType, coordinates.ToArray()));
else
vector = Activator.CreateInstance(type, coordinates.ToArray());

ListPool<object>.Pool.Return(coordinates);

Expand Down Expand Up @@ -111,6 +120,13 @@ public void WriteYaml(IEmitter emitter, object value, Type type)
coordinates["z"] = vector4.z;
coordinates["w"] = vector4.w;
}
else if (value is Quaternion quaternion)
{
coordinates["x"] = quaternion.x;
coordinates["y"] = quaternion.y;
coordinates["z"] = quaternion.z;
coordinates["w"] = quaternion.w;
}

emitter.Emit(new MappingStart());

Expand Down
Loading