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:
parent
e1a49b38a7
commit
7e0f60615b
@ -295,6 +295,7 @@ namespace hex {
|
||||
};
|
||||
|
||||
class AchievementManager {
|
||||
static bool s_initialized;
|
||||
public:
|
||||
AchievementManager() = delete;
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user