-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesettings.cpp
executable file
·65 lines (59 loc) · 2.13 KB
/
esettings.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
#include "esettings.h"
#include <fstream>
#include <iostream>
#include "egamedir.h"
#include "eloadtexthelper.h"
std::vector<eTileSize> eSettings::availableSizes() const {
std::vector<eTileSize> sizes;
if(fTinyTextures) {
sizes.push_back(eTileSize::s15);
}
if(fSmallTextures) {
sizes.push_back(eTileSize::s30);
}
if(fMediumTextures) {
sizes.push_back(eTileSize::s45);
}
if(fLargeTextures) {
sizes.push_back(eTileSize::s60);
}
return sizes;
}
void eSettings::write() const {
const auto path = eGameDir::settingsPath();
std::ofstream file;
file.open(path);
file << "tiny_textures" << " " <<
(fTinyTextures ? "\"true\"" : "\"false\"") << "\n";
file << "small_textures" << " " <<
(fSmallTextures ? "\"true\"" : "\"false\"") << "\n";
file << "medium_textures" << " " <<
(fMediumTextures ? "\"true\"" : "\"false\"") << "\n";
file << "large_textures" << " " <<
(fLargeTextures ? "\"true\"" : "\"false\"") << "\n";
file << "fullscreen" << " " <<
(fFullscreen ? "\"true\"" : "\"false\"") << "\n";
const auto wStr = std::to_string(fRes.width());
file << "width" << " " << "\"" << wStr << "\"" << "\n";
const auto hStr = std::to_string(fRes.height());
file << "height" << " " << "\"" << hStr << "\"" << "\n";
file.close();
}
void eSettings::read() {
const auto path = eGameDir::settingsPath();
std::map<std::string, std::string> settings;
const bool r = eLoadTextHelper::load(path, settings);
if(!r) return;
fTinyTextures = settings["tiny_textures"] == "true";
fSmallTextures = settings["small_textures"] == "true";
fMediumTextures = settings["medium_textures"] == "true";
fLargeTextures = settings["large_textures"] == "true";
fFullscreen = settings["fullscreen"] == "true";
const auto widthStr = settings["width"];
const auto heightStr = settings["height"];
if(!widthStr.empty() && !heightStr.empty()) {
const int width = std::stoi(widthStr);
const int height = std::stoi(heightStr);
fRes = eResolution(width, height);
}
}