From f86ef53d51487bc3724846ecbd60af81877c8e69 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 1 Nov 2024 13:25:49 +0100 Subject: [PATCH] Support multiple ability sources --- PkmnLib.Dataloader/AbilityDataLoader.cs | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/PkmnLib.Dataloader/AbilityDataLoader.cs b/PkmnLib.Dataloader/AbilityDataLoader.cs index c444f44..7fecc39 100644 --- a/PkmnLib.Dataloader/AbilityDataLoader.cs +++ b/PkmnLib.Dataloader/AbilityDataLoader.cs @@ -12,9 +12,8 @@ namespace PkmnLib.Dataloader; public static class AbilityDataLoader { - public static AbilityLibrary LoadAbilities(Stream stream) + private static Dictionary LoadAbilitiesData(Stream stream) { - var library = new AbilityLibrary(); var obj = JsonSerializer.Deserialize(stream); if (obj == null) throw new InvalidDataException("Ability data is empty."); @@ -28,13 +27,34 @@ public static class AbilityDataLoader }); if (objects == null) throw new InvalidDataException("Ability data is empty."); + return objects; + } + + public static AbilityLibrary LoadAbilities(Stream[] streams) + { + var library = new AbilityLibrary(); + var objects = streams.SelectMany(LoadAbilitiesData); + if (objects == null) + throw new InvalidDataException("Ability data is empty."); + var abilities = objects.Select(x => DeserializeAbility(x.Key, x.Value)); + foreach (var a in abilities) + library.Add(a); + return library; + } + + public static AbilityLibrary LoadAbilities(Stream stream) + { + var library = new AbilityLibrary(); + var objects = LoadAbilitiesData(stream); + if (objects == null) + throw new InvalidDataException("Ability data is empty."); var abilities = objects.Select(x => DeserializeAbility(x.Key, x.Value)); foreach (var a in abilities) library.Add(a); return library; } - + private static AbilityImpl DeserializeAbility(string name, SerializedAbility serialized) { var effect = serialized.Effect;