From bee4194f9e12c9d2210a5ecba7249bdfe3f3deda Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 14 May 2024 12:53:59 -0400 Subject: Switch to wx logging --- src/ap_state.cpp | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'src/ap_state.cpp') diff --git a/src/ap_state.cpp b/src/ap_state.cpp index b057beb..e5ff74d 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp @@ -75,7 +75,7 @@ struct APState { void Connect(std::string server, std::string player, std::string password) { if (!initialized) { - TrackerLog("Initializing APState..."); + wxLogMessage("Initializing APState..."); std::thread([this]() { for (;;) { @@ -108,10 +108,10 @@ struct APState { } tracker_frame->SetStatusMessage("Connecting to Archipelago server...."); - TrackerLog("Connecting to Archipelago server (" + server + ")..."); + wxLogMessage("Connecting to Archipelago server (%s)...", server); { - TrackerLog("Destroying old AP client..."); + wxLogMessage("Destroying old AP client..."); std::lock_guard client_guard(client_mutex); @@ -155,10 +155,10 @@ struct APState { apclient->set_room_info_handler([this, player, password]() { inventory.clear(); - TrackerLog("Connected to Archipelago server. Authenticating as " + - player + - (password.empty() ? " without password" - : " with password " + password)); + wxLogMessage("Connected to Archipelago server. Authenticating as %s %s", + player, + (password.empty() ? " without password" + : " with password " + password)); tracker_frame->SetStatusMessage( "Connected to Archipelago server. Authenticating..."); @@ -170,7 +170,7 @@ struct APState { [this](const std::list& locations) { for (const int64_t location_id : locations) { checked_locations.insert(location_id); - TrackerLog("Location: " + std::to_string(location_id)); + wxLogMessage("Location: %lld", location_id); } RefreshTracker(false); @@ -179,14 +179,14 @@ struct APState { apclient->set_slot_disconnected_handler([this]() { tracker_frame->SetStatusMessage( "Disconnected from Archipelago. Attempting to reconnect..."); - TrackerLog( + wxLogMessage( "Slot disconnected from Archipelago. Attempting to reconnect..."); }); apclient->set_socket_disconnected_handler([this]() { tracker_frame->SetStatusMessage( "Disconnected from Archipelago. Attempting to reconnect..."); - TrackerLog( + wxLogMessage( "Socket disconnected from Archipelago. Attempting to reconnect..."); }); @@ -194,7 +194,7 @@ struct APState { [this](const std::list& items) { for (const APClient::NetworkItem& item : items) { inventory[item.item]++; - TrackerLog("Item: " + std::to_string(item.item)); + wxLogMessage("Item: %lld", item.item); } RefreshTracker(false); @@ -219,7 +219,7 @@ struct APState { apclient->set_slot_connected_handler([this]( const nlohmann::json& slot_data) { tracker_frame->SetStatusMessage("Connected to Archipelago!"); - TrackerLog("Connected to Archipelago!"); + wxLogMessage("Connected to Archipelago!"); data_storage_prefix = "Lingo_" + std::to_string(apclient->get_player_number()) + "_"; @@ -323,7 +323,7 @@ struct APState { } std::string full_message = hatkirby::implode(error_messages, " "); - TrackerLog(full_message); + wxLogError(wxString(full_message)); wxMessageBox(full_message, "Connection failed", wxOK | wxICON_ERROR); }); @@ -342,7 +342,7 @@ struct APState { tracker_frame->SetStatusMessage("Disconnected from Archipelago."); - TrackerLog("Timeout while connecting to Archipelago server."); + wxLogMessage("Timeout while connecting to Archipelago server."); wxMessageBox("Timeout while connecting to Archipelago server.", "Connection failed", wxOK | wxICON_ERROR); } @@ -362,12 +362,11 @@ struct APState { void HandleDataStorage(const std::string& key, const nlohmann::json& value) { if (value.is_boolean()) { data_storage[key] = value.get(); - TrackerLog("Data storage " + key + " retrieved as " + - (value.get() ? "true" : "false")); + wxLogMessage("Data storage %s retrieved as %s", key, + (value.get() ? "true" : "false")); } else if (value.is_number()) { data_storage[key] = value.get(); - TrackerLog("Data storage " + key + " retrieved as " + - std::to_string(value.get())); + wxLogMessage("Data storage %s retrieved as %d", key, value.get()); } else if (value.is_object()) { if (key.ends_with("PlayerPos")) { auto map_value = value.get>(); @@ -376,7 +375,7 @@ struct APState { data_storage[key] = value.get>(); } - TrackerLog("Data storage " + key + " retrieved as dictionary"); + wxLogMessage("Data storage %s retrieved as dictionary", key); } else if (value.is_null()) { if (key.ends_with("PlayerPos")) { player_pos = std::nullopt; @@ -384,7 +383,7 @@ struct APState { data_storage.erase(key); } - TrackerLog("Data storage " + key + " retrieved as null"); + wxLogMessage("Data storage %s retrieved as null", key); } } @@ -408,7 +407,7 @@ struct APState { } void RefreshTracker(bool reset) { - TrackerLog("Refreshing display..."); + wxLogMessage("Refreshing display..."); RecalculateReachability(); @@ -422,7 +421,7 @@ struct APState { int64_t GetItemId(const std::string& item_name) { int64_t ap_id = apclient->get_item_id(item_name); if (ap_id == APClient::INVALID_NAME_ID) { - TrackerLog("Could not find AP item ID for " + item_name); + wxLogError("Could not find AP item ID for %s", item_name); } return ap_id; -- cgit 1.4.1