forked from DFHack/stonesense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cpp
156 lines (136 loc) · 4.36 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <fstream>
#include <string>
#include "common.h"
using namespace std;
string parseStrFromLine( string keyword, string line ){
string retVal = "";
string trimString = "";
trimString += "[";
trimString += keyword;
trimString += ":";
int length = (int)trimString.length();
if( line.compare(0,length, trimString) == 0){
line.replace(0,length,"");
line.replace(line.length()-1,1,"");
retVal = line;
}
return retVal;
}
int parseIntFromLine( string keyword, string line ){
int retVal = 0;
string trimString = "";
trimString += "[";
trimString += keyword;
trimString += ":";
int length = (int)trimString.length();
if( line.compare(0,length, trimString) == 0){
line.replace(0,length,"");
line.replace(line.length()-1,1,"");
retVal = atoi( line.c_str() );
}
return retVal;
}
void parseConfigLine( string line ){
char c = line[0];
if( c != '[') return;
//some systems don't remove the \r char as a part of the line change:
if(line.size() > 0 && line[line.size() -1 ] == '\r' )
line.resize(line.size() -1);
c = line[ line.length() -1 ];
if( c != ']' ) return;
if( line.find("WIDTH") != -1){
int width = parseIntFromLine( "WIDTH", line );
config.screenWidth = width;
}
if( line.find("HEIGHT") != -1){
int height = parseIntFromLine( "HEIGHT", line );
config.screenHeight = height;
}
if( line.find("WINDOWED") != -1){
string result = parseStrFromLine( "WINDOWED", line );
config.Fullscreen = (result == "NO");
}
if( line.find("SEGMENTSIZE_XY") != -1){
int value = parseIntFromLine( "SEGMENTSIZE_XY", line );
if(value < 5) value = DEFAULT_SEGMENTSIZE;
if(value > 100) value = 100;
//plus 2 to allow edge readings
config.segmentSize.x = value+2;
config.segmentSize.y = value+2;
}
if( line.find("SEGMENTSIZE_Z") != -1){
int value = parseIntFromLine( "SEGMENTSIZE_Z", line );
if(value < 1) value = DEFAULT_SEGMENTSIZE_Z;
if(value > 30) value = 30;
config.segmentSize.z = value;
}
if( line.find("ALLCREATURES") != -1){
string result = parseStrFromLine( "ALLCREATURES", line );
config.show_all_creatures = (result == "YES");
}
if( line.find("AUTO_RELOAD_STEP") != -1){
int value = parseIntFromLine( "AUTO_RELOAD_STEP", line);
if(value < 50) value = 50;
config.automatic_reload_step = value;
}
if( line.find("AUTO_RELOAD_TIME") != -1){
int value = parseIntFromLine( "AUTO_RELOAD_TIME", line);
if(value < 0) value = 0;
config.automatic_reload_time = value;
}
if( line.find("DEBUGMODE") != -1){
string result = parseStrFromLine( "DEBUGMODE", line );
config.debug_mode = (result == "YES");
}
if( line.find("LIFTSEGMENT") != -1){
int value = parseIntFromLine( "LIFTSEGMENT", line);
config.lift_segment_offscreen = value;
}
if( line.find("ANIMATION_RATE") != -1){
int value = parseIntFromLine( "ANIMATION_RATE", line );
if(value < 50) value = 50;
config.animation_step = value;
}
if( line.find("VERBOSE_LOGGING") != -1){
string result = parseStrFromLine( "VERBOSE_LOGGING", line );
config.verbose_logging = (result == "YES");
}
if( line.find("TRACK_CENTER") != -1){
string result = parseStrFromLine( "TRACK_CENTER", line );
config.track_center = (result == "YES");
}
if( line.find("FOLLOW_DF_SCREEN") != -1){
string result = parseStrFromLine( "FOLLOW_DF_SCREEN", line );
config.follow_DFscreen = (result == "YES");
}
if( line.find("SHOW_CREATURE_NAMES") != -1){
string result = parseStrFromLine( "SHOW_CREATURE_NAMES", line );
config.show_creature_names = (result == "YES");
}
if( line.find("SHOW_OSD") != -1){
string result = parseStrFromLine( "SHOW_OSD", line );
config.show_osd = (result == "YES");
}
if( line.find("INTRO") != -1){
string result = parseStrFromLine( "INTRO", line );
config.show_intro = !(result == "OFF");
}
}
bool loadConfigFile(){
string line;
ifstream myfile ("init.txt");
if (myfile.is_open() == false)
{
cout << "Cannot find init file" << endl;
return false;
}
while ( !myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
parseConfigLine( line );
}
myfile.close();
return true;
}