-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cpp
More file actions
86 lines (73 loc) · 1.92 KB
/
Copy pathConfig.cpp
File metadata and controls
86 lines (73 loc) · 1.92 KB
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
/**
* @file Config.cpp
* @author Bastien Brunnenstein
*/
#include "Config.hpp"
#include <iostream>
#include <fstream>
namespace Config
{
unsigned width = WINDOW_WIDTH;
unsigned height = WINDOW_HEIGHT;
bool fullscreen = WINDOW_FULLSCREEN;
bool borderless = WINDOW_BORDERLESS;
bool pause_enabled = false;
}
void Config::save()
{
std::ofstream file (CONFIG_FILE.toAnsiString().c_str());
if (!file.is_open())
{
std::cerr << "Unable to write configuration file : "
<< CONFIG_FILE.toAnsiString() << std::endl;
return;
}
file << "width " << Config::width << "\n"
<< "height " << Config::height << "\n"
<< "fullscreen " << ((int) Config::fullscreen) << "\n"
<< "borderless " << ((int) Config::borderless) << std::endl;
file.flush();
}
void Config::load()
{
std::ifstream file (CONFIG_FILE.toAnsiString().c_str());
std::string text;
if (!file.is_open())
return;
file >> std::ws;
while (!file.eof())
{
file >> text;
if (text == std::string("width"))
{
int w;
file >> w;
Config::width = w;
}
else if (text == std::string("height"))
{
int h;
file >> h;
Config::height = h;
}
else if (text == std::string("fullscreen"))
{
bool f;
file >> f;
Config::fullscreen = f;
}
else if (text == std::string("borderless"))
{
bool b;
file >> b;
Config::borderless = b;
}
else
{
std::cerr << "Unknown configuration option : "
<< text << std::endl;
file >> text;
}
file >> std::ws;
}
}