Support multiple ability sources
This commit is contained in:
parent
1df35c1f50
commit
f86ef53d51
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue