fix: Properly save achievements in web version
This commit is contained in:
parent
42c1f5601a
commit
248acd5e26
@ -215,7 +215,16 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto json = nlohmann::json::parse(file.readString());
|
#if defined(OS_WEB)
|
||||||
|
auto data = (char *) MAIN_THREAD_EM_ASM_INT({
|
||||||
|
let data = localStorage.getItem("achievements");
|
||||||
|
return data ? stringToNewUTF8(data) : null;
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
auto data = file.readString();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
auto json = nlohmann::json::parse(data);
|
||||||
|
|
||||||
for (const auto &[categoryName, achievements] : getAchievements()) {
|
for (const auto &[categoryName, achievements] : getAchievements()) {
|
||||||
for (const auto &[achievementName, achievement] : achievements) {
|
for (const auto &[achievementName, achievement] : achievements) {
|
||||||
@ -254,16 +263,23 @@ namespace hex {
|
|||||||
if (json.empty())
|
if (json.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const auto &directory : paths::Config.write()) {
|
#if defined(OS_WEB)
|
||||||
auto path = directory / AchievementsFile;
|
auto data = json.dump();
|
||||||
|
MAIN_THREAD_EM_ASM({
|
||||||
|
localStorage.setItem("config", UTF8ToString($0));
|
||||||
|
}, data.c_str());
|
||||||
|
#else
|
||||||
|
for (const auto &directory : paths::Config.write()) {
|
||||||
|
auto path = directory / AchievementsFile;
|
||||||
|
|
||||||
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
||||||
if (!file.isValid())
|
if (!file.isValid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
file.writeString(json.dump(4));
|
file.writeString(json.dump(4));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -30,7 +30,14 @@ namespace hex::plugin::builtin {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
m_showPopup = ContentRegistry::Settings::read<bool>("hex.builtin.setting.interface", "hex.builtin.setting.interface.achievement_popup", true);
|
{
|
||||||
|
bool defaultValue = true;
|
||||||
|
#if defined(OS_WEB)
|
||||||
|
defaultValue = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_showPopup = ContentRegistry::Settings::read<bool>("hex.builtin.setting.interface", "hex.builtin.setting.interface.achievement_popup", defaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewAchievements::~ViewAchievements() {
|
ViewAchievements::~ViewAchievements() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user