-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.cpp
68 lines (58 loc) · 2.19 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
#include "config.h"
#include <QDebug>
Config::Config()
{
}
void Config::parse(QFile& file)
{
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
QJsonObject JON = doc.object();
if (JON["Position"].toObject().value("NUMBER").isArray())
{
position.MIN_NUMBER = JON["Position"].toObject().value("NUMBER")[0].toInt();
position.MAX_NUMBER = JON["Position"].toObject().value("NUMBER")[1].toInt();
}
if (JON["Position"].toObject().value("COUNT_MODULES").isArray())
{
position.MIN_COUNT_MODULES = JON["Position"].toObject().value("COUNT_MODULES")[0].toInt();
position.MAX_COUNT_MODULES = JON["Position"].toObject().value("COUNT_MODULES")[1].toInt();
}
if (JON["Position"].toObject().value("AVG_TIME").isArray())
{
position.MIN_AVG_TIME = JON["Position"].toObject().value("AVG_TIME")[0].toDouble();
position.MAX_AVG_TIME = JON["Position"].toObject().value("AVG_TIME")[1].toDouble();
}
if (JON["Position"].toObject().value("STEP_TIME").isArray())
{
position.MIN_STEP_TIME = JON["Position"].toObject().value("STEP_TIME")[0].toDouble();
position.MAX_STEP_TIME = JON["Position"].toObject().value("STEP_TIME")[1].toDouble();
}
if (JON["Module"].toObject().value("SIZE").isArray())
{
platform.WIDTH = JON["Module"].toObject().value("SIZE")[0].toInt();
platform.HEIGHT = JON["Module"].toObject().value("SIZE")[1].toInt();
}
if (JON["Transborder"].toObject().value("SIZE").isArray())
{
transborder.WIDTH = JON["Transborder"].toObject().value("SIZE")[0].toInt();
transborder.HEIGHT = JON["Transborder"].toObject().value("SIZE")[1].toInt();
}
if (JON["Train"].toObject().value("SIZE").isArray())
{
train.WIDTH = JON["Train"].toObject().value("SIZE")[0].toInt();
train.HEIGHT = JON["Train"].toObject().value("SIZE")[1].toInt();
}
if (JON["MAX_COUNT_TRAINS"].isDouble())
MAX_COUNT_TRAINS = JON["MAX_COUNT_TRAINS"].toInt();
}
Config& Config::set()
{
static Config instance;
return instance;
}
Config const& Config::get()
{
return set();
}