aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.cpp')
-rw-r--r--src/config.cpp101
1 files changed, 54 insertions, 47 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 45bab3f..e076528 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -1,5 +1,10 @@
#include <config.h>
+#include <iostream>
+
+#include <SDL2/SDL_mixer.h>
+
+#include <tinyxml2.h>
#include <ui.h>
using namespace tinyxml2;
@@ -17,55 +22,57 @@ XMLDocument xml;
XMLElement *scr;
XMLElement *vol;
-void readConfig(){
- unsigned int uval;
- float fval;
- bool bval;
-
- xml.LoadFile("config/settings.xml");
- scr = xml.FirstChildElement("screen");
-
- if(scr->QueryUnsignedAttribute("width",&uval) == XML_NO_ERROR)
- SCREEN_WIDTH = uval;
- else SCREEN_WIDTH = 1280;
- if(scr->QueryUnsignedAttribute("height",&uval) == XML_NO_ERROR)
- SCREEN_HEIGHT = uval;
- else SCREEN_HEIGHT = 800;
- if(scr->QueryBoolAttribute("fullscreen",&bval) == XML_NO_ERROR)
- FULLSCREEN = bval;
- else FULLSCREEN = false;
- if(xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR)
- HLINE = uval;
- else HLINE = 3;
-
- vol = xml.FirstChildElement("volume");
-
- if(vol->FirstChildElement("master")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
- VOLUME_MASTER = fval;
- else VOLUME_MASTER = 50;
- if(vol->FirstChildElement("music")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
- VOLUME_MUSIC = fval;
- else VOLUME_MUSIC = 50;
- if(vol->FirstChildElement("sfx")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
- VOLUME_SFX = fval;
- else VOLUME_SFX = 50;
-
- ui::initFonts();
- ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
- updateConfig();
-}
+namespace config {
-void updateConfig(){
+ void read( void ) {
+ unsigned int uval;
+ float fval;
+ bool bval;
- Mix_Volume(0,VOLUME_MASTER);
- Mix_Volume(1,VOLUME_SFX * (VOLUME_MASTER/100.0f));
- Mix_VolumeMusic(VOLUME_MUSIC * (VOLUME_MASTER/100.0f));
-}
+ xml.LoadFile("config/settings.xml");
+ scr = xml.FirstChildElement("screen");
+
+ if(scr->QueryUnsignedAttribute("width",&uval) == XML_NO_ERROR)
+ SCREEN_WIDTH = uval;
+ else SCREEN_WIDTH = 1280;
+ if(scr->QueryUnsignedAttribute("height",&uval) == XML_NO_ERROR)
+ SCREEN_HEIGHT = uval;
+ else SCREEN_HEIGHT = 800;
+ if(scr->QueryBoolAttribute("fullscreen",&bval) == XML_NO_ERROR)
+ FULLSCREEN = bval;
+ else FULLSCREEN = false;
+ if(xml.FirstChildElement("hline")->QueryUnsignedAttribute("size",&uval) == XML_NO_ERROR)
+ HLINE = uval;
+ else HLINE = 3;
+
+ vol = xml.FirstChildElement("volume");
+
+ if(vol->FirstChildElement("master")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
+ VOLUME_MASTER = fval;
+ else VOLUME_MASTER = 50;
+ if(vol->FirstChildElement("music")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
+ VOLUME_MUSIC = fval;
+ else VOLUME_MUSIC = 50;
+ if(vol->FirstChildElement("sfx")->QueryFloatAttribute("volume",&fval) == XML_NO_ERROR)
+ VOLUME_SFX = fval;
+ else VOLUME_SFX = 50;
+
+ ui::initFonts();
+ ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
+ config::update();
+ }
+
+ void update( void ) {
+ Mix_Volume(0,VOLUME_MASTER);
+ Mix_Volume(1,VOLUME_SFX * (VOLUME_MASTER/100.0f));
+ Mix_VolumeMusic(VOLUME_MUSIC * (VOLUME_MASTER/100.0f));
+ }
-void saveConfig(){
- vol->FirstChildElement("master")->SetAttribute("volume",VOLUME_MASTER);
- vol->FirstChildElement("music")->SetAttribute("volume",VOLUME_MUSIC);
- vol->FirstChildElement("sfx")->SetAttribute("volume", VOLUME_SFX);
+ void save( void ) {
+ vol->FirstChildElement("master")->SetAttribute("volume",VOLUME_MASTER);
+ vol->FirstChildElement("music")->SetAttribute("volume",VOLUME_MUSIC);
+ vol->FirstChildElement("sfx")->SetAttribute("volume", VOLUME_SFX);
- xml.SaveFile("config/settings.xml", false);
+ xml.SaveFile("config/settings.xml", false);
+ }
}