Adds support for custom ctor for moves in MoveDataLoader

This commit is contained in:
Deukhoofd 2024-10-01 10:22:53 +02:00
parent b01a8fb704
commit dbd07564c4
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace PkmnLib.Dataloader.Models;
@ -20,6 +22,9 @@ public class SerializedMove
public string Category { get; set; } = null!;
public string[] Flags { get; set; } = null!;
public SerializedMoveEffect? Effect { get; set; }
[JsonExtensionData]
public Dictionary<string, JsonElement>? ExtensionData { get; set; }
}
public class SerializedMoveEffect

View File

@ -38,6 +38,9 @@ public class SerializedForm
public bool IsMega { get; set; }
public SerializedMoves Moves { get; set; } = null!;
public string[] Flags { get; set; } = [];
[JsonExtensionData]
public Dictionary<string, JsonElement>? ExtensionData { get; set; }
}
public class SerializedEvolution

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Text.Json;
using PkmnLib.Dataloader.Models;
using PkmnLib.Static;
using PkmnLib.Static.Libraries;
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
@ -29,6 +30,12 @@ public static class MoveDataLoader
return library;
}
public static Func<SerializedMove, StringKey, TypeIdentifier, MoveCategory, byte, byte, byte, MoveTarget, sbyte,
ISecondaryEffect?, IEnumerable<StringKey>, MoveDataImpl> MoveConstructor =
(serialized, name, moveType, category, basePower, accuracy, baseUsages, target, priority, secondaryEffect,
flags) => new MoveDataImpl(name, moveType, category, basePower, accuracy, baseUsages, target, priority,
secondaryEffect, flags);
private static MoveDataImpl DeserializeMove(SerializedMove serialized, TypeLibrary typeLibrary)
{
var type = serialized.Type;
@ -52,7 +59,7 @@ public static class MoveDataLoader
throw new InvalidDataException($"Target {target} is not a valid target.");
var secondaryEffect = ParseEffect(effect);
var move = new MoveDataImpl(serialized.Name, typeIdentifier, categoryEnum, power, accuracy, pp, targetEnum,
var move = MoveConstructor(serialized, serialized.Name, typeIdentifier, categoryEnum, power, accuracy, pp, targetEnum,
priority, secondaryEffect, flags.Select(x => (StringKey)x).ToImmutableHashSet());
return move;
}