Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit f575fe9

Browse files
author
serpentiem
committed
2.7 Mary Nightly 6 January 2022
1 parent 66e0717 commit f575fe9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+24701
-3581
lines changed

.gitignore

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,43 @@
1313
!Mary/*
1414
!Scripts
1515
!Scripts/*.js
16+
1617
!ThirdParty
1718
!ThirdParty/*
19+
1820
!ThirdParty/ImGui
1921
!ThirdParty/ImGui/*.cpp
2022
!ThirdParty/ImGui/*.h
2123
!ThirdParty/ImGui/LICENSE.txt
24+
2225
!ThirdParty/libzip
2326
!ThirdParty/libzip/*.c
2427
!ThirdParty/libzip/*.h
2528
!ThirdParty/libzip/AUTHORS
2629
!ThirdParty/libzip/LICENSE
30+
31+
!ThirdParty/rapidjson
32+
!ThirdParty/rapidjson/error
33+
!ThirdParty/rapidjson/error/*.h
34+
!ThirdParty/rapidjson/internal
35+
!ThirdParty/rapidjson/internal/*.h
36+
!ThirdParty/rapidjson/msinttypes
37+
!ThirdParty/rapidjson/msinttypes/*.h
38+
!ThirdParty/rapidjson/*.h
39+
!ThirdParty/rapidjson/license.txt
40+
2741
!ThirdParty/stb
2842
!ThirdParty/stb/*.h
2943
!ThirdParty/stb/LICENSE
44+
3045
!ThirdParty/zlib
3146
!ThirdParty/zlib/*.c
3247
!ThirdParty/zlib/*.h
3348
!ThirdParty/zlib/README
49+
3450
!/.gitattributes
3551
!/.gitignore
52+
!/ConfigFunctions.h
3653
!/core.js
3754
!/ddmk.js
3855
!/dinput8.cpp
@@ -42,5 +59,4 @@
4259
!/LICENSE.txt
4360
!/README.md
4461
!/run.js
45-
!/welcome.png
4662
prep_*

ConfigFunctions.h

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#ifdef NO_SAVE
2+
void SaveConfigFunction()
3+
#else
4+
export void SaveConfig()
5+
#endif
6+
{
7+
#ifndef NO_SAVE
8+
LogFunction();
9+
#endif
10+
11+
using namespace rapidjson;
12+
using namespace JSON;
13+
14+
15+
16+
ToJSON(queuedConfig);
17+
18+
19+
20+
StringBuffer stringBuffer;
21+
PrettyWriter<StringBuffer> prettyWriter(stringBuffer);
22+
23+
root.Accept(prettyWriter);
24+
25+
26+
27+
auto name = stringBuffer.GetString();
28+
auto size = strlen(name);
29+
30+
if
31+
(
32+
!SaveFile
33+
(
34+
location,
35+
name,
36+
size
37+
)
38+
)
39+
{
40+
Log("SaveFile failed.");
41+
}
42+
}
43+
44+
45+
46+
#ifdef NO_LOAD
47+
void LoadConfigFunction()
48+
#else
49+
export void LoadConfig()
50+
#endif
51+
{
52+
#ifndef NO_LOAD
53+
LogFunction();
54+
#endif
55+
56+
using namespace rapidjson;
57+
using namespace JSON;
58+
59+
60+
61+
auto file = LoadFile(location);
62+
if (!file)
63+
{
64+
Log("LoadFile failed.");
65+
66+
CreateMembers(defaultConfig);
67+
68+
SaveConfig();
69+
70+
return;
71+
}
72+
73+
74+
75+
auto name = const_cast<const char *>(reinterpret_cast<char *>(file));
76+
77+
if (root.Parse(name).HasParseError())
78+
{
79+
Log("Parse failed.");
80+
81+
return;
82+
}
83+
84+
85+
86+
CreateMembers(defaultConfig);
87+
88+
// At this point all file members have been applied. Extra or obsolete file members can exist.
89+
// If members were missing in the file they were created and have their default values.
90+
91+
92+
93+
// The actual configs are still untouched though.
94+
// Let's update them!
95+
96+
ToConfig(queuedConfig);
97+
98+
CopyMemory
99+
(
100+
&activeConfig,
101+
&queuedConfig,
102+
sizeof(activeConfig)
103+
);
104+
105+
106+
107+
SaveConfig();
108+
109+
// SaveConfig here in case new members were created.
110+
// This way we don't have to rely on a later SaveConfig to update the file.
111+
}
112+
113+
114+
115+
#ifdef NO_INIT
116+
void InitConfigFunction()
117+
#else
118+
export void InitConfig()
119+
#endif
120+
{
121+
#ifndef NO_INIT
122+
LogFunction();
123+
#endif
124+
125+
using namespace rapidjson;
126+
using namespace JSON;
127+
128+
CreateDirectoryA(directoryName, 0);
129+
130+
snprintf
131+
(
132+
location,
133+
sizeof(location),
134+
"%s/%s",
135+
directoryName,
136+
fileName
137+
);
138+
139+
root.SetObject();
140+
141+
g_allocator = &root.GetAllocator();
142+
}

0 commit comments

Comments
 (0)