Move data and data loading to plugin libraries.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-05-16 13:01:23 +02:00
parent b6ff51c9df
commit 810cdbb15a
46 changed files with 108405 additions and 155 deletions

View File

@@ -0,0 +1,38 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.Libraries.DataLoaders;
internal static class JsonParameterLoader
{
internal static object? ToParameter(this JsonNode node)
{
switch (node.GetValueKind())
{
case JsonValueKind.Undefined:
throw new InvalidOperationException("Undefined value.");
case JsonValueKind.Object:
return node.AsObject().ToDictionary(x => (StringKey)x.Key, x => x.Value?.ToParameter());
case JsonValueKind.Array:
return node.AsArray().Select(x => x?.ToParameter()).ToList();
case JsonValueKind.String:
return node.GetValue<string>();
case JsonValueKind.Number:
var element = node.GetValue<JsonElement>();
if (element.TryGetInt32(out var v))
return v;
if (element.TryGetSingle(out var f))
return f;
throw new InvalidOperationException("Number is not an integer or a float.");
case JsonValueKind.True:
return true;
case JsonValueKind.False:
return false;
case JsonValueKind.Null:
return null;
default:
throw new ArgumentOutOfRangeException();
}
}
}