1
0
mirror of synced 2025-01-11 05:42:15 +01:00

fix: Properly save achievements in web version

This commit is contained in:
WerWolv 2024-12-25 16:17:33 +01:00
parent 42c1f5601a
commit 248acd5e26
2 changed files with 33 additions and 10 deletions

View File

@ -215,7 +215,16 @@ namespace hex {
}
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 &[achievementName, achievement] : achievements) {
@ -254,16 +263,23 @@ namespace hex {
if (json.empty())
return;
for (const auto &directory : paths::Config.write()) {
auto path = directory / AchievementsFile;
#if defined(OS_WEB)
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);
if (!file.isValid())
continue;
wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid())
continue;
file.writeString(json.dump(4));
break;
}
file.writeString(json.dump(4));
break;
}
#endif
}
}

View File

@ -30,7 +30,14 @@ namespace hex::plugin::builtin {
});
// 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() {