mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
* Export MonoBehaviour byte arrays as scalars rather than sequences * Do not serialize yaml scalars, especially not for byte arrays * Eliminate unnecessary state for yaml scalars * Create a new type hierarchy for yaml scalars * Implement hexidecimal emission of floating point scalars * Implement hexidecimal emission of numeric lists * Resolves #1422 * Resolves #1409 * Resolves #1381 * Related to #927 * Related to #695
36 lines
939 B
C#
36 lines
939 B
C#
using System.Globalization;
|
|
using System.Numerics;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace AssetRipper.Yaml;
|
|
|
|
public abstract partial class YamlScalarNode
|
|
{
|
|
private sealed class NumericNode<T>(T value) : YamlScalarNode where T : struct, INumber<T>, IConvertible
|
|
{
|
|
private protected override void EmitCore(Emitter emitter)
|
|
{
|
|
if (typeof(T) == typeof(float))
|
|
{
|
|
emitter.Write(Unsafe.As<T, float>(ref value));
|
|
}
|
|
else if (typeof(T) == typeof(double))
|
|
{
|
|
emitter.Write(Unsafe.As<T, double>(ref value));
|
|
}
|
|
else if (IsSigned)
|
|
{
|
|
emitter.Write(value.ToInt64(CultureInfo.InvariantCulture));
|
|
}
|
|
else
|
|
{
|
|
emitter.Write(value.ToUInt64(CultureInfo.InvariantCulture));
|
|
}
|
|
}
|
|
|
|
public override string Value => value.ToString() ?? "";
|
|
|
|
private static bool IsSigned => typeof(T) == typeof(sbyte) || typeof(T) == typeof(short) || typeof(T) == typeof(int) || typeof(T) == typeof(long);
|
|
}
|
|
}
|