-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.cpp
136 lines (121 loc) · 3.23 KB
/
Config.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "Config.h"
#include <fstream>
#include "XPLMDataAccess.h"
#include "CUESDK.h"
bool Config::Load() {
//Clear current data
conditions.clear();
keys.clear();
// Load js file
nlohmann::json js;
std::ifstream t(DirPath + "illuminate.json");
if (t.is_open())
{
t >> js;
}
t.close();
BackgroundColor[0] = 0;
BackgroundColor[1] = 0;
BackgroundColor[2] = 0;
// Load Colors
if (js["colors"].is_array())
{
for each (auto color in js["colors"])
{
if (color["name"].is_string()) {
Color c = Color();
c.name = color["name"].get<std::string>();
if (color["r"].is_number()) c.r = color["r"].get<int>();
if (color["g"].is_number()) c.g = color["g"].get<int>();
if (color["b"].is_number()) c.b = color["b"].get<int>();
colors[c.name] = c;
if (c.name.compare("background") == 0) {
BackgroundColor[0] = c.r;
BackgroundColor[1] = c.g;
BackgroundColor[2] = c.b;
}
}
}
}
if (js["conditions"].is_array())
{
// Load conditions
for each (auto condition in js["conditions"])
{
Condition c = Condition();
if(condition["dataRef"].is_string()) c.dataRefString = condition["dataRef"].get<std::string>();
if(condition["name"].is_string()) c.dataRefName = condition["name"].get<std::string>();
if(condition["value"].is_number()) c.value = condition["value"].get<double>();
if (condition["match"].is_string())
{
string match = condition["match"].get<std::string>();
if (match == std::string("less_than"))
{
c.conditionType = ConditionType::less_than;
}
else if (match == std::string("greater_than"))
{
c.conditionType = ConditionType::greater_than;
}
else {
c.conditionType = ConditionType::exactly;
}
}
c.dataRef = XPLMFindDataRef(c.dataRefString.c_str());
if (c.dataRef == NULL) continue;
c.dataType = XPLMGetDataRefTypes(c.dataRef);
if (c.dataType == xplmType_FloatArray || c.dataType == xplmType_IntArray) {
if (condition["index"].is_number()) {
c.index = condition["index"].get<int>();
}
else {
c.index = 0;
}
}
conditions.push_back(c);
}
}
if (js["keys"].is_array())
{
// Load keys
for each (auto key in js["keys"])
{
Key k = Key();
if(key["name"].is_string()) k.name = key["name"].get<std::string>();
if (key["conditions"].is_array())
{
for each (auto condition in key["conditions"])
{
if(condition.is_string()) k.conditions.push_back(condition.get<std::string>());
}
}
if (key["key"].is_string())
{
char tmp = key["key"].get<std::string>().c_str()[0];
k.LedId = CorsairGetLedIdForKeyName(tmp);
}
else if (key["key"].is_number())
{
k.LedId = (CorsairLedId)key["key"].get<int>();
}
if (key["color"].is_string())
{
if (colors.find(key["color"].get<std::string>()) != colors.end())
{
Color c = colors[key["color"].get<std::string>()];
k.Color[0] = c.r;
k.Color[1] = c.g;
k.Color[2] = c.b;
}
}
else
{
if(key["color"]["r"].is_number()) k.Color[0] = key["color"]["r"].get<int>();
if(key["color"]["g"].is_number()) k.Color[1] = key["color"]["g"].get<int>();
if(key["color"]["b"].is_number()) k.Color[2] = key["color"]["b"].get<int>();
}
keys.push_back(k);
}
}
return true;
}