diff options
| author | Jacob Palecki <[email protected]> | 2021-04-01 22:08:01 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2021-04-01 22:08:01 -0700 |
| commit | ebfd5a8af07bc5fdf5b463714d8030e49eac53ba (patch) | |
| tree | a31b8b3350cdde51cfdaa86260d9788c3e75d010 /grapher/Models/Serialized | |
| parent | Add lookuptable json (diff) | |
| download | rawaccel-ebfd5a8af07bc5fdf5b463714d8030e49eac53ba.tar.xz rawaccel-ebfd5a8af07bc5fdf5b463714d8030e49eac53ba.zip | |
Add differing table types
Diffstat (limited to 'grapher/Models/Serialized')
| -rw-r--r-- | grapher/Models/Serialized/LookupTable.cs | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/grapher/Models/Serialized/LookupTable.cs b/grapher/Models/Serialized/LookupTable.cs index 578c5bf..d373461 100644 --- a/grapher/Models/Serialized/LookupTable.cs +++ b/grapher/Models/Serialized/LookupTable.cs @@ -10,32 +10,9 @@ using System.Threading.Tasks; namespace grapher.Models.Serialized { [Serializable] - public class LookupTable + public static class LookupTable { - [Serializable] - public class Point - { - public Point(double x, double y) - { - X = x; - Y = y; - } - - double X { get; set; } - - double Y { get; set; } - } - - public LookupTable(Point[] points) - { - Points = points; - } - - public Point[] Points { get; } - - public bool InSensGraph { get; } - - public static LookupTable Deserialize(string lutFile) + public static void Deserialize(string lutFile, ref DriverSettings settings) { if (!File.Exists(lutFile)) { @@ -44,23 +21,29 @@ namespace grapher.Models.Serialized JObject lutJObject = JObject.Parse(File.ReadAllText(lutFile)); - var lut = lutJObject.ToObject<LookupTable>(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); + var spacedLut = lutJObject.ToObject<SpacedTable>(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - if (lut is null || lut.Points is null) + if (spacedLut is null) { - throw new Exception($"{lutFile} does not contain valid lookuptable json."); - } + var arbitraryLut = lutJObject.ToObject<ArbitraryTable>(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - lut.Verify(); + if (arbitraryLut is null || arbitraryLut.points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } - return lut; - } - - private void Verify() - { - if (Points.Length >= short.MaxValue) + settings.ArbitraryTable = arbitraryLut; + settings.args.x.lutArgs.type = TableType.arbitrary; + } + else { - throw new Exception($"LUT file with {Points.Length} points is too long. Max points: {short.MaxValue}"); + if (spacedLut.points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } + + settings.SpacedTable = spacedLut; + settings.args.x.lutArgs = spacedLut.args; } } } |