using System.Text.Json; using PkmnLib.Static; using PkmnLib.Static.Libraries; namespace PkmnLib.Dynamic.Libraries.DataLoaders; /// /// Loads growth rate data from a JSON file. /// public static class GrowthRateDataLoader { /// /// Loads the growth rate library from a JSON file. /// public static GrowthRateLibrary LoadGrowthRates(Stream stream, Action>? action = null) { var objects = JsonSerializer.Deserialize>(stream, JsonOptions.DefaultOptions)!; var growthRates = objects.Select(x => new LookupGrowthRate(x.Key, x.Value)).Cast().ToList(); action?.Invoke(growthRates); var library = new GrowthRateLibrary(); foreach (var growthRate in growthRates) { library.Add(growthRate); } return library; } }