-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.cpp
More file actions
103 lines (83 loc) · 2.66 KB
/
Copy pathconfig.cpp
File metadata and controls
103 lines (83 loc) · 2.66 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "config.h"
#include "crossplatform.h"
#include <fstream>
SConfig SyobonGlobalConfig;
#ifdef __EMSCRIPTEN__
EM_JS(void, InitSaveFS, (const char* savepath), {
const mountPath = UTF8ToString(savepath);
Asyncify.handleSleep(function(wakeUp) {
try {
FS.mkdir(mountPath);
} catch (e) {}
try {
FS.mount(IDBFS, {}, mountPath);
} catch (e) {}
FS.syncfs(true, function(err) {
if (err)
console.error(err);
wakeUp();
});
});
});
EM_JS(void, FlushSaveFS, (), {
FS.syncfs(false, function(err) {
if (err)
console.error(err);
});
});
#endif
void SaveConfig()
{
const char * psave_dir = GetSavePath();
if(psave_dir)
{
char filepath[256] = {0};
snprintf(filepath, sizeof(filepath), "%s/save.txt", GetSavePath());
std::ofstream file(filepath);
for(auto &LevelFinished : SyobonGlobalConfig.LevelsFinished)
{
file << "LEVEL_FINISHED " << (int)LevelFinished.Game << " " << LevelFinished.World << " " << LevelFinished.Level << std::endl;
}
file << "FULLSCREEN " << (int)SyobonKZIsFullscreen() << std::endl;
file << "BETTER_GRAPHICS " << (int)SyobonGlobalConfig.BetterGraphics << std::endl;
file.close();
#ifdef __EMSCRIPTEN__
FlushSaveFS();
#endif
}
}
void LoadConfig()
{
#ifdef __EMSCRIPTEN__
InitSaveFS(SYOBONKZ_EMSCRIPTEN_SAVEPATH);
#endif
SyobonGlobalConfig.LevelsFinished.clear();
const char * psave_dir = GetSavePath();
if(psave_dir)
{
char filepath[256] = {0};
snprintf(filepath, sizeof(filepath), "%s/save.txt", psave_dir);
std::ifstream file(filepath);
std::string line;
while(std::getline(file, line))
{
if(strstr(line.c_str(), "LEVEL_FINISHED"))
{
SSyobonGameLevel temp;
int game;
sscanf(line.c_str(), "LEVEL_FINISHED %d %d %d", &game, &temp.World, &temp.Level);
temp.Game = (ESyobonActionGame)game;
SyobonGlobalConfig.LevelsFinished.insert(temp);
}
if(strstr(line.c_str(), "FULLSCREEN"))
{
sscanf(line.c_str(), "FULLSCREEN %d", &SyobonGlobalConfig.Fullscreen);
}
if(strstr(line.c_str(), "BETTER_GRAPHICS"))
{
sscanf(line.c_str(), "BETTER_GRAPHICS %d", &SyobonGlobalConfig.BetterGraphics);
}
}
file.close();
}
}