-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.cpp
123 lines (105 loc) · 2.93 KB
/
configure.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
#include <QSettings>
#include <QDebug>
#include "configure.h"
Configure::Configure() : config_file("./GAMCS-Lab.conf")
{
}
void Configure::setConfigFile(const QString &file)
{
config_file = file;
}
void Configure::load()
{
config_map.clear();
QSettings settings(config_file, QSettings::IniFormat);
QString key;
QVariant val;
key = "Scene/Size/Width";
val = settings.value(key);
if (!val.isNull()) // only check null, may be invalid
config_map.insert(key, val);
else
config_map.insert(key, 512);
key = "Scene/Size/Height";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 256);
key = "AvatarSpirit/Life/Mouse";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 30);
key = "AvatarSpirit/Life/Cat";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 50);
key = "AvatarSpirit/Life/Elephant";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 100);
key = "AvatarSpirit/ShareParams/ShareRange";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 0);
key = "AvatarSpirit/ShareParams/ShareFreq";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 5);
key = "AvatarSpirit/GAMCSParams/DiscountRate";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 0.9);
key = "AvatarSpirit/GAMCSParams/Accuracy";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 0.001);
key = "AvatarSpirit/GAMCSParams/LearningMode";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, QString("Online"));
key = "StaticSpirit/Life/Cheese";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 15);
key = "StaticSpirit/Life/Nail";
val = settings.value(key);
if (!val.isNull())
config_map.insert(key, val);
else
config_map.insert(key, 1.5);
}
void Configure::save()
{
QSettings settings(config_file, QSettings::IniFormat);
for (QMap<QString, QVariant>::iterator it = config_map.begin(); it != config_map.end(); ++it)
{
settings.setValue(it.key(), it.value());
}
}
QVariant Configure::getValue(const QString &what)
{
return config_map.value(what, QVariant());
}
void Configure::setValue(const QString &what, const QVariant &value)
{
config_map.insert(what, value);
}