1
0
mirror of synced 2025-01-31 12:03:46 +01:00

fix: Achievements resetting after restart (#1965)

### Problem description
Loading a file on the command line or using the context menu in windows
was triggering an achievement before the achievements file was loaded.
This resulted on the achievements.json file to be overwritten with all
the achievements reset except for the one to open files.

### Implementation description
This PR fixes the problem by introducing a boolean that is used to check
if the file has been loaded.

---------

Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
paxcut 2024-11-24 03:34:44 -07:00 committed by GitHub
parent e1a49b38a7
commit 7e0f60615b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -295,6 +295,7 @@ namespace hex {
};
class AchievementManager {
static bool s_initialized;
public:
AchievementManager() = delete;

View File

@ -196,8 +196,11 @@ namespace hex {
constexpr static auto AchievementsFile = "achievements.json";
bool AchievementManager::s_initialized = false;
void AchievementManager::loadProgress() {
if (s_initialized)
return;
for (const auto &directory : paths::Config.read()) {
auto path = directory / AchievementsFile;
@ -227,6 +230,8 @@ namespace hex {
}
}
}
s_initialized = true;
} catch (const std::exception &e) {
log::error("Failed to load achievements: {}", e.what());
}
@ -235,6 +240,8 @@ namespace hex {
}
void AchievementManager::storeProgress() {
if (!s_initialized)
loadProgress();
nlohmann::json json;
for (const auto &[categoryName, achievements] : getAchievements()) {
json[categoryName] = nlohmann::json::object();