Cut 8b, deletes first. The old authorities are removed, not demoted: - ServerShared/CultCache: CultCache.cs, DatabaseEntry.cs (root [Union], DatabaseLink, INamedEntry), RegisterResolver.cs, TypeFormatterResolver.cs, JsonConverters.cs, JsonKnownTypes/**. - Assets/Plugins/MessagePack/** and System.Runtime.CompilerServices.Unsafe.dll (org.gamecult.cultlib ships both). - GalaxyMapLayerData, PlayerData, GlobalSettingsAttribute. - The inspector attributes CultLib already carries or nothing reads. Kept and moved: MathFormatters.cs and MathResolver.cs to ServerShared/Serialization; GetAllChildClasses, SplitCamelCase, FormatTypeName, MaxBy and MinBy to Extensions.cs; Inspectable, PreferredInspectorAttribute and the five Aetheria drawer attributes to ServerShared/Attributes.cs. Aetheria.Shared.csproj drops the vendored MessagePack include and the Unsafe package; the asmdef drops MessagePack. Does not build: the data model moves onto CultLib in the next commit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using MessagePack;
|
|
using MessagePack.Formatters;
|
|
using CultMath;
|
|
using static CultMath.math;
|
|
|
|
|
|
public class MathResolver : IFormatterResolver
|
|
{
|
|
public static readonly MathResolver Instance = new MathResolver();
|
|
|
|
private MathResolver()
|
|
{
|
|
}
|
|
|
|
public IMessagePackFormatter<T> GetFormatter<T>()
|
|
{
|
|
return FormatterCache<T>.Formatter;
|
|
}
|
|
|
|
private static class FormatterCache<T>
|
|
{
|
|
public static readonly IMessagePackFormatter<T> Formatter;
|
|
|
|
static FormatterCache()
|
|
{
|
|
Formatter = (IMessagePackFormatter<T>)MathResolverResolverGetFormatterHelper.GetFormatter(typeof(T));
|
|
}
|
|
}
|
|
}
|
|
|
|
internal static class MathResolverResolverGetFormatterHelper
|
|
{
|
|
private static readonly Dictionary<Type, object> FormatterMap = new Dictionary<Type, object>()
|
|
{
|
|
// standard
|
|
{ typeof(float2), new Float2Formatter() },
|
|
{ typeof(int2), new Int2Formatter() },
|
|
{ typeof(bool2), new Bool2Formatter() },
|
|
{ typeof(float3), new Float3Formatter() },
|
|
{ typeof(float4), new Float4Formatter() },
|
|
{ typeof(float2?), new StaticNullableFormatter<float2>(new Float2Formatter()) },
|
|
{ typeof(int2?), new StaticNullableFormatter<int2>(new Int2Formatter()) },
|
|
{ typeof(float3?), new StaticNullableFormatter<float3>(new Float3Formatter()) },
|
|
{ typeof(float4?), new StaticNullableFormatter<float4>(new Float4Formatter()) },
|
|
|
|
// standard + array
|
|
{ typeof(float2[]), new ArrayFormatter<float2>() },
|
|
{ typeof(int2[]), new ArrayFormatter<int2>() },
|
|
{ typeof(float3[]), new ArrayFormatter<float3>() },
|
|
{ typeof(float4[]), new ArrayFormatter<float4>() },
|
|
{ typeof(float2?[]), new ArrayFormatter<float2?>() },
|
|
{ typeof(int2?[]), new ArrayFormatter<int2?>() },
|
|
{ typeof(float3?[]), new ArrayFormatter<float3?>() },
|
|
{ typeof(float4?[]), new ArrayFormatter<float4?>() },
|
|
|
|
// standard + list
|
|
{ typeof(List<float2>), new ListFormatter<float2>() },
|
|
{ typeof(List<int2>), new ListFormatter<int2>() },
|
|
{ typeof(List<float3>), new ListFormatter<float3>() },
|
|
{ typeof(List<float4>), new ListFormatter<float4>() },
|
|
{ typeof(List<float2?>), new ListFormatter<float2?>() },
|
|
{ typeof(List<int2?>), new ListFormatter<int2?>() },
|
|
{ typeof(List<float3?>), new ListFormatter<float3?>() },
|
|
{ typeof(List<float4?>), new ListFormatter<float4?>() },
|
|
};
|
|
|
|
internal static object GetFormatter(Type t)
|
|
{
|
|
object formatter;
|
|
if (FormatterMap.TryGetValue(t, out formatter))
|
|
{
|
|
return formatter;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|