about summary refs log tree commit diff stats
path: root/src/ap_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ap_state.cpp')
-rw-r--r--src/ap_state.cpp56
1 files changed, 25 insertions, 31 deletions
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 68a6902..4a15db0 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp
@@ -21,7 +21,6 @@
21#include <tuple> 21#include <tuple>
22 22
23#include "game_data.h" 23#include "game_data.h"
24#include "logger.h"
25#include "tracker_frame.h" 24#include "tracker_frame.h"
26#include "tracker_state.h" 25#include "tracker_state.h"
27 26
@@ -75,7 +74,7 @@ struct APState {
75 74
76 void Connect(std::string server, std::string player, std::string password) { 75 void Connect(std::string server, std::string player, std::string password) {
77 if (!initialized) { 76 if (!initialized) {
78 wxLogMessage("Initializing APState..."); 77 wxLogVerbose("Initializing APState...");
79 78
80 std::thread([this]() { 79 std::thread([this]() {
81 for (;;) { 80 for (;;) {
@@ -108,11 +107,10 @@ struct APState {
108 initialized = true; 107 initialized = true;
109 } 108 }
110 109
111 tracker_frame->SetStatusMessage("Connecting to Archipelago server...."); 110 wxLogStatus("Connecting to Archipelago server (%s)...", server);
112 wxLogMessage("Connecting to Archipelago server (%s)...", server);
113 111
114 { 112 {
115 wxLogMessage("Destroying old AP client..."); 113 wxLogVerbose("Destroying old AP client...");
116 114
117 std::lock_guard client_guard(client_mutex); 115 std::lock_guard client_guard(client_mutex);
118 116
@@ -156,12 +154,11 @@ struct APState {
156 apclient->set_room_info_handler([this, player, password]() { 154 apclient->set_room_info_handler([this, player, password]() {
157 inventory.clear(); 155 inventory.clear();
158 156
159 wxLogMessage("Connected to Archipelago server. Authenticating as %s %s", 157 wxLogStatus(
160 player,
161 (password.empty() ? " without password"
162 : " with password " + password));
163 tracker_frame->SetStatusMessage(
164 "Connected to Archipelago server. Authenticating..."); 158 "Connected to Archipelago server. Authenticating...");
159 wxLogVerbose("Authenticating as %s %s", player,
160 (password.empty() ? "without password"
161 : "with password " + password));
165 162
166 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"}, 163 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"},
167 {AP_MAJOR, AP_MINOR, AP_REVISION}); 164 {AP_MAJOR, AP_MINOR, AP_REVISION});
@@ -171,23 +168,19 @@ struct APState {
171 [this](const std::list<int64_t>& locations) { 168 [this](const std::list<int64_t>& locations) {
172 for (const int64_t location_id : locations) { 169 for (const int64_t location_id : locations) {
173 checked_locations.insert(location_id); 170 checked_locations.insert(location_id);
174 wxLogMessage("Location: %lld", location_id); 171 wxLogVerbose("Location: %lld", location_id);
175 } 172 }
176 173
177 RefreshTracker(false); 174 RefreshTracker(false);
178 }); 175 });
179 176
180 apclient->set_slot_disconnected_handler([this]() { 177 apclient->set_slot_disconnected_handler([this]() {
181 tracker_frame->SetStatusMessage( 178 wxLogStatus(
182 "Disconnected from Archipelago. Attempting to reconnect...");
183 wxLogMessage(
184 "Slot disconnected from Archipelago. Attempting to reconnect..."); 179 "Slot disconnected from Archipelago. Attempting to reconnect...");
185 }); 180 });
186 181
187 apclient->set_socket_disconnected_handler([this]() { 182 apclient->set_socket_disconnected_handler([this]() {
188 tracker_frame->SetStatusMessage( 183 wxLogStatus(
189 "Disconnected from Archipelago. Attempting to reconnect...");
190 wxLogMessage(
191 "Socket disconnected from Archipelago. Attempting to reconnect..."); 184 "Socket disconnected from Archipelago. Attempting to reconnect...");
192 }); 185 });
193 186
@@ -195,7 +188,7 @@ struct APState {
195 [this](const std::list<APClient::NetworkItem>& items) { 188 [this](const std::list<APClient::NetworkItem>& items) {
196 for (const APClient::NetworkItem& item : items) { 189 for (const APClient::NetworkItem& item : items) {
197 inventory[item.item]++; 190 inventory[item.item]++;
198 wxLogMessage("Item: %lld", item.item); 191 wxLogVerbose("Item: %lld", item.item);
199 } 192 }
200 193
201 RefreshTracker(false); 194 RefreshTracker(false);
@@ -219,8 +212,7 @@ struct APState {
219 212
220 apclient->set_slot_connected_handler([this]( 213 apclient->set_slot_connected_handler([this](
221 const nlohmann::json& slot_data) { 214 const nlohmann::json& slot_data) {
222 tracker_frame->SetStatusMessage("Connected to Archipelago!"); 215 wxLogStatus("Connected to Archipelago!");
223 wxLogMessage("Connected to Archipelago!");
224 216
225 data_storage_prefix = 217 data_storage_prefix =
226 "Lingo_" + std::to_string(apclient->get_player_number()) + "_"; 218 "Lingo_" + std::to_string(apclient->get_player_number()) + "_";
@@ -341,9 +333,7 @@ struct APState {
341 333
342 DestroyClient(); 334 DestroyClient();
343 335
344 tracker_frame->SetStatusMessage("Disconnected from Archipelago."); 336 wxLogStatus("Timeout while connecting to Archipelago server.");
345
346 wxLogMessage("Timeout while connecting to Archipelago server.");
347 wxMessageBox("Timeout while connecting to Archipelago server.", 337 wxMessageBox("Timeout while connecting to Archipelago server.",
348 "Connection failed", wxOK | wxICON_ERROR); 338 "Connection failed", wxOK | wxICON_ERROR);
349 } 339 }
@@ -363,11 +353,11 @@ struct APState {
363 void HandleDataStorage(const std::string& key, const nlohmann::json& value) { 353 void HandleDataStorage(const std::string& key, const nlohmann::json& value) {
364 if (value.is_boolean()) { 354 if (value.is_boolean()) {
365 data_storage[key] = value.get<bool>(); 355 data_storage[key] = value.get<bool>();
366 wxLogMessage("Data storage %s retrieved as %s", key, 356 wxLogVerbose("Data storage %s retrieved as %s", key,
367 (value.get<bool>() ? "true" : "false")); 357 (value.get<bool>() ? "true" : "false"));
368 } else if (value.is_number()) { 358 } else if (value.is_number()) {
369 data_storage[key] = value.get<int>(); 359 data_storage[key] = value.get<int>();
370 wxLogMessage("Data storage %s retrieved as %d", key, value.get<int>()); 360 wxLogVerbose("Data storage %s retrieved as %d", key, value.get<int>());
371 } else if (value.is_object()) { 361 } else if (value.is_object()) {
372 if (key.ends_with("PlayerPos")) { 362 if (key.ends_with("PlayerPos")) {
373 auto map_value = value.get<std::map<std::string, int>>(); 363 auto map_value = value.get<std::map<std::string, int>>();
@@ -376,7 +366,7 @@ struct APState {
376 data_storage[key] = value.get<std::map<std::string, int>>(); 366 data_storage[key] = value.get<std::map<std::string, int>>();
377 } 367 }
378 368
379 wxLogMessage("Data storage %s retrieved as dictionary", key); 369 wxLogVerbose("Data storage %s retrieved as dictionary", key);
380 } else if (value.is_null()) { 370 } else if (value.is_null()) {
381 if (key.ends_with("PlayerPos")) { 371 if (key.ends_with("PlayerPos")) {
382 player_pos = std::nullopt; 372 player_pos = std::nullopt;
@@ -384,15 +374,19 @@ struct APState {
384 data_storage.erase(key); 374 data_storage.erase(key);
385 } 375 }
386 376
387 wxLogMessage("Data storage %s retrieved as null", key); 377 wxLogVerbose("Data storage %s retrieved as null", key);
388 } else if (value.is_array()) { 378 } else if (value.is_array()) {
379 auto list_value = value.get<std::vector<std::string>>();
380
389 if (key.ends_with("Paintings")) { 381 if (key.ends_with("Paintings")) {
390 data_storage[key] = value.get<std::set<std::string>>(); 382 data_storage[key] =
383 std::set<std::string>(list_value.begin(), list_value.end());
391 } else { 384 } else {
392 data_storage[key] = value.get<std::vector<std::string>>(); 385 data_storage[key] = list_value;
393 } 386 }
394 387
395 wxLogMessage("Data storage %s retrieved as list", key); 388 wxLogVerbose("Data storage %s retrieved as list: [%s]", key,
389 hatkirby::implode(list_value, ", "));
396 } 390 }
397 } 391 }
398 392
@@ -425,7 +419,7 @@ struct APState {
425 } 419 }
426 420
427 void RefreshTracker(bool reset) { 421 void RefreshTracker(bool reset) {
428 wxLogMessage("Refreshing display..."); 422 wxLogVerbose("Refreshing display...");
429 423
430 RecalculateReachability(); 424 RecalculateReachability();
431 425