summaryrefslogtreecommitdiff
path: root/Config.cpp
diff options
context:
space:
mode:
authorJonas Ask2009-10-20 12:23:52 +0000
committerJonas Ask2009-10-20 12:23:52 +0000
commit9b1b95b33e4ba93a6ab7fed504d4bcf6e2abee9a (patch)
tree2a7833db49114f38fd87fbaf39e0b69279bb8c2e /Config.cpp
parent002c766257789fabe04deeb9d79d2e3fbcefc195 (diff)
downloadstonesense-9b1b95b33e4ba93a6ab7fed504d4bcf6e2abee9a.tar.gz
stonesense-9b1b95b33e4ba93a6ab7fed504d4bcf6e2abee9a.tar.bz2
stonesense-9b1b95b33e4ba93a6ab7fed504d4bcf6e2abee9a.tar.xz
Adding all the code and resources for the first time. God speed!
Diffstat (limited to 'Config.cpp')
-rw-r--r--Config.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/Config.cpp b/Config.cpp
new file mode 100644
index 0000000..435d5a2
--- /dev/null
+++ b/Config.cpp
@@ -0,0 +1,100 @@
+#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;
+ 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("SEGMENTX") != -1){
+ int value = parseIntFromLine( "SEGMENTX", line );
+ if(value < 1) value = DEFAULT_SEGMENTSIZE_X;
+ if(value > 100) value = 100;
+ config.segmentSize.x = value;
+ }
+ if( line.find("SEGMENTY") != -1){
+ int value = parseIntFromLine( "SEGMENTY", line );
+ if(value < 1) value = DEFAULT_SEGMENTSIZE_Y;
+ if(value > 100) value = 100;
+ config.segmentSize.y = value;
+ }
+ if( line.find("SEGMENTZ") != -1){
+ int value = parseIntFromLine( "SEGMENTZ", line );
+ if(value < 1) value = DEFAULT_SEGMENTSIZE_Z;
+ if(value > 30) value = 30;
+ config.segmentSize.z = value;
+ }
+}
+
+
+bool loadConfigFile(){
+ string line;
+ ifstream myfile ("init.txt");
+ if (myfile.is_open() == false)
+ return false;
+
+ while ( !myfile.eof() )
+ {
+ getline (myfile,line);
+ cout << line << endl;
+ parseConfigLine( line );
+ }
+ myfile.close();
+
+
+ return true;
+} \ No newline at end of file