blob: d373461f7ccb31c8eeb149a7993eb0eaf6fc2123 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace grapher.Models.Serialized
{
[Serializable]
public static class LookupTable
{
public static void Deserialize(string lutFile, ref DriverSettings settings)
{
if (!File.Exists(lutFile))
{
throw new Exception($"LUT file does not exist at {lutFile}.");
}
JObject lutJObject = JObject.Parse(File.ReadAllText(lutFile));
var spacedLut = lutJObject.ToObject<SpacedTable>(JsonSerializer.Create(RawAccelSettings.SerializerSettings));
if (spacedLut is null)
{
var arbitraryLut = lutJObject.ToObject<ArbitraryTable>(JsonSerializer.Create(RawAccelSettings.SerializerSettings));
if (arbitraryLut is null || arbitraryLut.points is null)
{
throw new Exception($"{lutFile} does not contain valid lookuptable json.");
}
settings.ArbitraryTable = arbitraryLut;
settings.args.x.lutArgs.type = TableType.arbitrary;
}
else
{
if (spacedLut.points is null)
{
throw new Exception($"{lutFile} does not contain valid lookuptable json.");
}
settings.SpacedTable = spacedLut;
settings.args.x.lutArgs = spacedLut.args;
}
}
}
}
|