Adds support for custom ctor for moves in MoveDataLoader
This commit is contained in:
parent
b01a8fb704
commit
dbd07564c4
@ -1,5 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace PkmnLib.Dataloader.Models;
|
namespace PkmnLib.Dataloader.Models;
|
||||||
|
|
||||||
@ -20,6 +22,9 @@ public class SerializedMove
|
|||||||
public string Category { get; set; } = null!;
|
public string Category { get; set; } = null!;
|
||||||
public string[] Flags { get; set; } = null!;
|
public string[] Flags { get; set; } = null!;
|
||||||
public SerializedMoveEffect? Effect { get; set; }
|
public SerializedMoveEffect? Effect { get; set; }
|
||||||
|
|
||||||
|
[JsonExtensionData]
|
||||||
|
public Dictionary<string, JsonElement>? ExtensionData { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SerializedMoveEffect
|
public class SerializedMoveEffect
|
||||||
|
@ -38,6 +38,9 @@ public class SerializedForm
|
|||||||
public bool IsMega { get; set; }
|
public bool IsMega { get; set; }
|
||||||
public SerializedMoves Moves { get; set; } = null!;
|
public SerializedMoves Moves { get; set; } = null!;
|
||||||
public string[] Flags { get; set; } = [];
|
public string[] Flags { get; set; } = [];
|
||||||
|
|
||||||
|
[JsonExtensionData]
|
||||||
|
public Dictionary<string, JsonElement>? ExtensionData { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SerializedEvolution
|
public class SerializedEvolution
|
||||||
|
@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using PkmnLib.Dataloader.Models;
|
using PkmnLib.Dataloader.Models;
|
||||||
|
using PkmnLib.Static;
|
||||||
using PkmnLib.Static.Libraries;
|
using PkmnLib.Static.Libraries;
|
||||||
using PkmnLib.Static.Moves;
|
using PkmnLib.Static.Moves;
|
||||||
using PkmnLib.Static.Utils;
|
using PkmnLib.Static.Utils;
|
||||||
@ -29,6 +30,12 @@ public static class MoveDataLoader
|
|||||||
return library;
|
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)
|
private static MoveDataImpl DeserializeMove(SerializedMove serialized, TypeLibrary typeLibrary)
|
||||||
{
|
{
|
||||||
var type = serialized.Type;
|
var type = serialized.Type;
|
||||||
@ -52,7 +59,7 @@ public static class MoveDataLoader
|
|||||||
throw new InvalidDataException($"Target {target} is not a valid target.");
|
throw new InvalidDataException($"Target {target} is not a valid target.");
|
||||||
var secondaryEffect = ParseEffect(effect);
|
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());
|
priority, secondaryEffect, flags.Select(x => (StringKey)x).ToImmutableHashSet());
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user