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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
core/parser.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "auxiliary/functions.h"
#include "core/parser.h"
#include "sys/sys.h"
namespace core
{
bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
{
if (!entity)
return false;
math::Vector3f v;
math::Color color;
std::string shapename;
std::string strval;
float yaw, pitch, roll;
float f;
bool blnval;
if (inifile.got_key_string("shape", shapename)) {
if (shapename.compare("axis") == 0) {
entity->set_shape(core::Entity::Axis);
return true;
} else if (shapename.compare("cube") == 0) {
entity->set_shape(core::Entity::Cube);
return true;
} else if (shapename.compare("diamond") == 0) {
entity->set_shape(core::Entity::Diamond);
return true;
} else if (shapename.compare("sphere") == 0) {
entity->set_shape(core::Entity::Sphere);
return true;
} else {
con_warn << inifile.name() << " unknown shape '" << shapename << "' at line " << inifile.line() << std::endl;
return false;
}
} else if (inifile.got_key_string("info", strval)) {
Info *info = Info::find(entity->info());
if (!info) {
std::string labelstr;
if (entity->zone()) {
labelstr.append(entity->zone()->label());
labelstr += ':';
}
labelstr.append(entity->label());
info = new Info(Entity::infotype(), labelstr.c_str());
entity->set_info(info);
}
info->add_text(strval);
return true;
} else if (inifile.got_key_label("label", strval)) {
entity->set_label(strval);
return true;
} else if (inifile.got_key_string("name", strval)) {
entity->set_name(strval);
return true;
} else if (inifile.got_key_string("model", strval)) {
entity->set_modelname(strval);
return true;
} else if (inifile.got_key_bool("showonmap", blnval)) {
if (blnval)
entity->set_flag(Entity::ShowOnMap);
else
entity->unset_flag(Entity::ShowOnMap);
return true;
} else if (inifile.got_key_bool("nonsolid", blnval)) {
if (blnval)
entity->set_flag(Entity::NonSolid);
else
entity->unset_flag(Entity::NonSolid);
return true;
} else if (inifile.got_key_float("angle", yaw)) {
if (yaw == model::ANGLEUP) {
entity->get_axis().change_pitch(-90.0f);
} else if (yaw == model::ANGLEDOWN) {
entity->get_axis().change_pitch(90.0f);
} else {
entity->get_axis().change_direction(yaw);
}
return true;
} else if (inifile.got_key("angles")) {
std::istringstream str(inifile.value());
if (str >> pitch >> yaw >> roll) {
entity->get_axis().assign(yaw, pitch, roll);
} else {
inifile.unknown_value();
}
return true;
} else if (inifile.got_key_angle("yaw", yaw)) {
entity->get_axis().change_direction(yaw);
return true;
} else if (inifile.got_key_angle("pitch", pitch)) {
entity->get_axis().change_pitch(-pitch);
return true;
} else if (inifile.got_key_angle("roll", roll)) {
entity->get_axis().change_roll(-roll);
return true;
} else if (inifile.got_key_angle("radius", f)) {
entity->set_radius(f);
return true;
} else if (inifile.got_key_vector3f("location", v)) {
entity->get_location().assign(v);
return true;
} else if (inifile.got_key_color("colorsecond", color)) {
entity->get_color_second().assign(color);
return true;
} else if (inifile.got_key_color("color", color)) {
entity->get_color().assign(color);
return true;
}
// special globe keys
if (entity->type() == Entity::Globe) {
EntityGlobe *globe = static_cast<EntityGlobe *>(entity);
if (inifile.got_key_string("texture", strval)) {
globe->set_texturename(strval);
return true;
} else if (inifile.got_key_string("corona", strval)) {
globe->set_coronaname(strval);
return true;
} else if (inifile.got_key_float("rotationspeed", f)) {
globe->set_rotationspeed(f);
return true;
} else if (inifile.got_key_bool("bright", blnval)) {
if (blnval) {
globe->set_flag(core::Entity::Bright);
} else {
globe->unset_flag(core::Entity::Bright);
}
return true;
}
}
return false;
}
}
|