blob: 844bf3962c85e55de9f72d9c5cb819d2389ad7d8 (
plain)
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
|
#include <config.hpp>
#include <ui.hpp>
#include <SDL2/SDL_mixer.h>
#include <tinyxml2.h>
using namespace tinyxml2;
namespace game {
unsigned int HLINE;
unsigned int SCREEN_WIDTH;
unsigned int SCREEN_HEIGHT;
bool FULLSCREEN;
namespace config {
static XMLDocument xml;
static XMLElement *vol;
float VOLUME_MASTER;
float VOLUME_MUSIC;
float VOLUME_SFX;
std::string xmlFolder;
void read(void) {
xml.LoadFile("config/settings.xml");
auto exml = xml.FirstChildElement("screen");
if (exml->QueryUnsignedAttribute("width", &SCREEN_WIDTH) != XML_NO_ERROR)
SCREEN_WIDTH = 1024;
if (exml->QueryUnsignedAttribute("height", &SCREEN_HEIGHT) != XML_NO_ERROR)
SCREEN_HEIGHT = 768;
if (exml->QueryBoolAttribute("fullscreen", &FULLSCREEN) != XML_NO_ERROR)
FULLSCREEN = false;
if (xml.FirstChildElement("hline")->QueryUnsignedAttribute("size", &HLINE) != XML_NO_ERROR)
HLINE = 3;
vol = exml = xml.FirstChildElement("volume");
if (exml->FirstChildElement("master")->QueryFloatAttribute("volume", &VOLUME_MASTER) != XML_NO_ERROR)
VOLUME_MASTER = 50;
if (exml->FirstChildElement("music")->QueryFloatAttribute("volume", &VOLUME_MUSIC) != XML_NO_ERROR)
VOLUME_MUSIC = 50;
if (exml->FirstChildElement("sfx")->QueryFloatAttribute("volume", &VOLUME_SFX) != XML_NO_ERROR)
VOLUME_SFX = 50;
xmlFolder = xml.FirstChildElement("world")->StrAttribute("start");
if (xmlFolder.empty())
xmlFolder = "xml/";
ui::initFonts();
ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
if (xml.FirstChildElement("debug"))
ui::debug = ui::posFlag = true;
config::update();
}
void update(void) {
Mix_Volume(0, static_cast<int>(VOLUME_SFX * (VOLUME_MASTER / 100)));
Mix_VolumeMusic(static_cast<int>(VOLUME_MUSIC * (VOLUME_MASTER / 100)));
}
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);
}
}
}
|