From 829bffa5912f1b6da4ebba580450cfba6d320295 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 21 Mar 2025 13:00:13 -0400 Subject: Use sync panels for achievement state --- src/achievements_pane.cpp | 13 +++++++------ src/achievements_pane.h | 6 +++++- src/ap_state.cpp | 20 -------------------- src/ap_state.h | 2 -- src/tracker_frame.cpp | 6 +++++- src/tracker_frame.h | 1 - 6 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/achievements_pane.cpp b/src/achievements_pane.cpp index b255f3b..d23c434 100644 --- a/src/achievements_pane.cpp +++ b/src/achievements_pane.cpp @@ -8,13 +8,14 @@ AchievementsPane::AchievementsPane(wxWindow* parent) AppendColumn("Achievement"); for (int panel_id : GD_GetAchievementPanels()) { - achievement_names_.push_back(GD_GetPanel(panel_id).achievement_name); + const Panel& panel = GD_GetPanel(panel_id); + achievements_.emplace_back(panel.achievement_name, panel.solve_index); } - std::sort(std::begin(achievement_names_), std::end(achievement_names_)); + std::sort(std::begin(achievements_), std::end(achievements_)); - for (int i = 0; i < achievement_names_.size(); i++) { - InsertItem(i, achievement_names_.at(i)); + for (int i = 0; i < achievements_.size(); i++) { + InsertItem(i, std::get<0>(achievements_.at(i))); } SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER); @@ -23,8 +24,8 @@ AchievementsPane::AchievementsPane(wxWindow* parent) } void AchievementsPane::UpdateIndicators() { - for (int i = 0; i < achievement_names_.size(); i++) { - if (AP_HasAchievement(achievement_names_.at(i))) { + for (int i = 0; i < achievements_.size(); i++) { + if (AP_IsPanelSolved(std::get<1>(achievements_.at(i)))) { SetItemTextColour(i, *wxBLACK); } else { SetItemTextColour(i, *wxRED); diff --git a/src/achievements_pane.h b/src/achievements_pane.h index ac88cac..941b5e3 100644 --- a/src/achievements_pane.h +++ b/src/achievements_pane.h @@ -9,6 +9,10 @@ #include +#include +#include +#include + class AchievementsPane : public wxListView { public: explicit AchievementsPane(wxWindow* parent); @@ -16,7 +20,7 @@ class AchievementsPane : public wxListView { void UpdateIndicators(); private: - std::vector achievement_names_; + std::vector> achievements_; // name, solve index }; #endif /* end of include guard: ACHIEVEMENTS_PANE_H_C320D0B8 */ \ No newline at end of file diff --git a/src/ap_state.cpp b/src/ap_state.cpp index c1147f6..a969892 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp @@ -232,14 +232,6 @@ struct APState { return HasItem(item_id, quantity); } - bool HasAchievement(const std::string& name) { - std::lock_guard state_guard(state_mutex); - - std::string key = - fmt::format("{}Achievement|{}", data_storage_prefix, name); - return data_storage.count(key) && std::any_cast(data_storage.at(key)); - } - const std::set& GetCheckedPaintings() { std::lock_guard state_guard(state_mutex); @@ -298,11 +290,6 @@ struct APState { std::thread([this]() { Thread(); }).detach(); - for (int panel_id : GD_GetAchievementPanels()) { - tracked_data_storage_keys.push_back(fmt::format( - "Achievement|{}", GD_GetPanel(panel_id).achievement_name)); - } - for (int i = 0; i < PANEL_BITFIELDS; i++) { tracked_data_storage_keys.push_back(fmt::format("Panels_{}", i)); } @@ -608,9 +595,6 @@ struct APState { TrackerLog(fmt::format("Data storage {} retrieved as {}", key, (value.get() ? "true" : "false"))); - if (key.find("Achievement|") != std::string::npos) { - state_update.achievements = true; - } } else if (value.is_number()) { data_storage[key] = value.get(); TrackerLog(fmt::format("Data storage {} retrieved as {}", key, @@ -844,10 +828,6 @@ VictoryCondition AP_GetVictoryCondition() { return GetState().victory_condition; } -bool AP_HasAchievement(const std::string& achievement_name) { - return GetState().HasAchievement(achievement_name); -} - bool AP_HasEarlyColorHallways() { std::lock_guard state_guard(GetState().state_mutex); diff --git a/src/ap_state.h b/src/ap_state.h index 54e1187..a757d89 100644 --- a/src/ap_state.h +++ b/src/ap_state.h @@ -93,8 +93,6 @@ PanelShuffleMode AP_GetPanelShuffleMode(); VictoryCondition AP_GetVictoryCondition(); -bool AP_HasAchievement(const std::string& achievement_name); - bool AP_HasEarlyColorHallways(); bool AP_IsPilgrimageEnabled(); diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index c0b070b..e8d7ef6 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp @@ -341,7 +341,11 @@ void TrackerFrame::OnStateChanged(StateChangedEvent &event) { } } - if (state.achievements) { + if (std::any_of(state.panels.begin(), state.panels.end(), + [](int solve_index) { + return GD_GetPanel(GD_GetPanelBySolveIndex(solve_index)) + .achievement; + })) { achievements_pane_->UpdateIndicators(); } diff --git a/src/tracker_frame.h b/src/tracker_frame.h index 2167852..00bbe70 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h @@ -53,7 +53,6 @@ struct StateUpdate { std::vector items; bool progression_items = false; std::vector paintings; - bool achievements = false; bool cleared_locations = false; std::set panels; bool player_position = false; -- cgit 1.4.1