about summary refs log tree commit diff stats
path: root/src/ap_state.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-05-21 13:16:25 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-05-21 13:16:25 -0400
commitbb12ecd88fe16e4009b0d8927c5653d72972e284 (patch)
tree69e2e23b43605ffa24fe2c64251a1fab8ff0dfd7 /src/ap_state.cpp
parent0e69963e29fd7e3f9e4bdf876246c400d2f07f19 (diff)
downloadlingo-ap-tracker-bb12ecd88fe16e4009b0d8927c5653d72972e284.tar.gz
lingo-ap-tracker-bb12ecd88fe16e4009b0d8927c5653d72972e284.tar.bz2
lingo-ap-tracker-bb12ecd88fe16e4009b0d8927c5653d72972e284.zip
Show list of achievements on the side
Diffstat (limited to 'src/ap_state.cpp')
-rw-r--r--src/ap_state.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 8a3aaf9..0f2246b 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp
@@ -45,8 +45,11 @@ struct APState {
45 bool connected = false; 45 bool connected = false;
46 bool has_connection_result = false; 46 bool has_connection_result = false;
47 47
48 std::list<std::string> tracked_data_storage_keys;
49
48 std::map<int64_t, int> inventory; 50 std::map<int64_t, int> inventory;
49 std::set<int64_t> checked_locations; 51 std::set<int64_t> checked_locations;
52 std::map<std::string, bool> data_storage;
50 53
51 std::map<std::tuple<int, int>, int64_t> ap_id_by_location_id; 54 std::map<std::tuple<int, int>, int64_t> ap_id_by_location_id;
52 std::map<std::string, int64_t> ap_id_by_item_name; 55 std::map<std::string, int64_t> ap_id_by_item_name;
@@ -78,6 +81,11 @@ struct APState {
78 } 81 }
79 }).detach(); 82 }).detach();
80 83
84 for (int panel_id : GD_GetAchievementPanels()) {
85 tracked_data_storage_keys.push_back(
86 "Achievement|" + GD_GetPanel(panel_id).achievement_name);
87 }
88
81 initialized = true; 89 initialized = true;
82 } 90 }
83 91
@@ -104,6 +112,7 @@ struct APState {
104 112
105 inventory.clear(); 113 inventory.clear();
106 checked_locations.clear(); 114 checked_locations.clear();
115 data_storage.clear();
107 door_shuffle_mode = kNO_DOORS; 116 door_shuffle_mode = kNO_DOORS;
108 color_shuffle = false; 117 color_shuffle = false;
109 painting_shuffle = false; 118 painting_shuffle = false;
@@ -162,6 +171,31 @@ struct APState {
162 RefreshTracker(); 171 RefreshTracker();
163 }); 172 });
164 173
174 apclient->set_retrieved_handler(
175 [this](const std::map<std::string, nlohmann::json>& data) {
176 for (const auto& [key, value] : data) {
177 if (value.is_boolean()) {
178 data_storage[key] = value.get<bool>();
179 TrackerLog("Data storage " + key + " retrieved as " +
180 (value.get<bool>() ? "true" : "false"));
181 }
182 }
183
184 RefreshTracker();
185 });
186
187 apclient->set_set_reply_handler([this](const std::string& key,
188 const nlohmann::json& value,
189 const nlohmann::json&) {
190 if (value.is_boolean()) {
191 data_storage[key] = value.get<bool>();
192 TrackerLog("Data storage " + key + " set to " +
193 (value.get<bool>() ? "true" : "false"));
194
195 RefreshTracker();
196 }
197 });
198
165 apclient->set_slot_connected_handler([this]( 199 apclient->set_slot_connected_handler([this](
166 const nlohmann::json& slot_data) { 200 const nlohmann::json& slot_data) {
167 tracker_frame->SetStatusMessage("Connected to Archipelago!"); 201 tracker_frame->SetStatusMessage("Connected to Archipelago!");
@@ -187,6 +221,9 @@ struct APState {
187 has_connection_result = true; 221 has_connection_result = true;
188 222
189 RefreshTracker(); 223 RefreshTracker();
224
225 apclient->Get(tracked_data_storage_keys);
226 apclient->SetNotify(tracked_data_storage_keys);
190 }); 227 });
191 228
192 apclient->set_slot_refused_handler( 229 apclient->set_slot_refused_handler(
@@ -325,6 +362,11 @@ struct APState {
325 } 362 }
326 } 363 }
327 364
365 bool HasAchievement(const std::string& name) {
366 std::string key = "Achievement|" + name;
367 return data_storage.count(key) && data_storage.at(key);
368 }
369
328 void RefreshTracker() { 370 void RefreshTracker() {
329 TrackerLog("Refreshing display..."); 371 TrackerLog("Refreshing display...");
330 372
@@ -386,3 +428,7 @@ const std::map<std::string, std::string> AP_GetPaintingMapping() {
386int AP_GetMasteryRequirement() { return GetState().mastery_requirement; } 428int AP_GetMasteryRequirement() { return GetState().mastery_requirement; }
387 429
388bool AP_IsReduceChecks() { return GetState().reduce_checks; } 430bool AP_IsReduceChecks() { return GetState().reduce_checks; }
431
432bool AP_HasAchievement(const std::string& achievement_name) {
433 return GetState().HasAchievement(achievement_name);
434}