Support multiple ability sources

This commit is contained in:
Deukhoofd 2024-11-01 13:25:49 +01:00
parent 1df35c1f50
commit f86ef53d51
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 23 additions and 3 deletions

View File

@ -12,9 +12,8 @@ namespace PkmnLib.Dataloader;
public static class AbilityDataLoader
{
public static AbilityLibrary LoadAbilities(Stream stream)
private static Dictionary<string, SerializedAbility> LoadAbilitiesData(Stream stream)
{
var library = new AbilityLibrary();
var obj = JsonSerializer.Deserialize<JsonObject>(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;