about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--connection_dialog.cpp11
-rw-r--r--main.cpp3
-rw-r--r--tracker_config.cpp33
-rw-r--r--tracker_config.h19
-rw-r--r--tracker_frame.cpp6
6 files changed, 70 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d616e5..6e29d18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -39,6 +39,7 @@ add_executable(lingo_ap_tracker
39 connection_dialog.cpp 39 connection_dialog.cpp
40 eye_indicator.cpp 40 eye_indicator.cpp
41 tracker_state.cpp 41 tracker_state.cpp
42 tracker_config.cpp
42) 43)
43set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD 20) 44set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD 20)
44set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD_REQUIRED ON) 45set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD_REQUIRED ON)
diff --git a/connection_dialog.cpp b/connection_dialog.cpp index 55f68eb..9dd9984 100644 --- a/connection_dialog.cpp +++ b/connection_dialog.cpp
@@ -1,10 +1,15 @@
1#include "connection_dialog.h" 1#include "connection_dialog.h"
2 2
3#include "tracker_config.h"
4
3ConnectionDialog::ConnectionDialog() 5ConnectionDialog::ConnectionDialog()
4 : wxDialog(nullptr, wxID_ANY, "Connect to Archipelago") { 6 : wxDialog(nullptr, wxID_ANY, "Connect to Archipelago") {
5 server_box_ = new wxTextCtrl(this, -1, "", wxDefaultPosition, {300, -1}); 7 server_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_server, wxDefaultPosition,
6 player_box_ = new wxTextCtrl(this, -1, "", wxDefaultPosition, {300, -1}); 8 {300, -1});
7 password_box_ = new wxTextCtrl(this, -1, "", wxDefaultPosition, {300, -1}); 9 player_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_player, wxDefaultPosition,
10 {300, -1});
11 password_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_password,
12 wxDefaultPosition, {300, -1});
8 13
9 wxFlexGridSizer* form_sizer = new wxFlexGridSizer(2, 10, 10); 14 wxFlexGridSizer* form_sizer = new wxFlexGridSizer(2, 10, 10);
10 15
diff --git a/main.cpp b/main.cpp index 4fbbe72..fe9aceb 100644 --- a/main.cpp +++ b/main.cpp
@@ -4,11 +4,14 @@
4#include <wx/wx.h> 4#include <wx/wx.h>
5#endif 5#endif
6 6
7#include "tracker_config.h"
7#include "tracker_frame.h" 8#include "tracker_frame.h"
8 9
9class TrackerApp : public wxApp { 10class TrackerApp : public wxApp {
10 public: 11 public:
11 virtual bool OnInit() { 12 virtual bool OnInit() {
13 GetTrackerConfig().Load();
14
12 TrackerFrame *frame = new TrackerFrame(); 15 TrackerFrame *frame = new TrackerFrame();
13 frame->Show(true); 16 frame->Show(true);
14 return true; 17 return true;
diff --git a/tracker_config.cpp b/tracker_config.cpp new file mode 100644 index 0000000..96bb60a --- /dev/null +++ b/tracker_config.cpp
@@ -0,0 +1,33 @@
1#include "tracker_config.h"
2
3#include <fstream>
4#include <yaml-cpp/yaml.h>
5
6constexpr const char* CONFIG_FILE_NAME = "config.yaml";
7
8void TrackerConfig::Load() {
9 try {
10 YAML::Node file = YAML::LoadFile(CONFIG_FILE_NAME);
11
12 ap_server = file["ap_server"].as<std::string>();
13 ap_player = file["ap_player"].as<std::string>();
14 ap_password = file["ap_password"].as<std::string>();
15 } catch (const std::exception&) {
16 // It's fine if the file can't be loaded.
17 }
18}
19
20void TrackerConfig::Save() {
21 YAML::Node output;
22 output["ap_server"] = ap_server;
23 output["ap_player"] = ap_player;
24 output["ap_password"] = ap_password;
25
26 std::ofstream filewriter(CONFIG_FILE_NAME);
27 filewriter << output;
28}
29
30TrackerConfig& GetTrackerConfig() {
31 static TrackerConfig* instance = new TrackerConfig();
32 return *instance;
33}
diff --git a/tracker_config.h b/tracker_config.h new file mode 100644 index 0000000..e2e6cd7 --- /dev/null +++ b/tracker_config.h
@@ -0,0 +1,19 @@
1#ifndef TRACKER_CONFIG_H_36CDD648
2#define TRACKER_CONFIG_H_36CDD648
3
4#include <string>
5
6class TrackerConfig {
7 public:
8 void Load();
9
10 void Save();
11
12 std::string ap_server;
13 std::string ap_player;
14 std::string ap_password;
15};
16
17TrackerConfig& GetTrackerConfig();
18
19#endif /* end of include guard: TRACKER_CONFIG_H_36CDD648 */
diff --git a/tracker_frame.cpp b/tracker_frame.cpp index 37a8281..774b710 100644 --- a/tracker_frame.cpp +++ b/tracker_frame.cpp
@@ -2,6 +2,7 @@
2 2
3#include "ap_state.h" 3#include "ap_state.h"
4#include "connection_dialog.h" 4#include "connection_dialog.h"
5#include "tracker_config.h"
5#include "tracker_panel.h" 6#include "tracker_panel.h"
6 7
7enum TrackerFrameIds { ID_CONNECT = 1 }; 8enum TrackerFrameIds { ID_CONNECT = 1 };
@@ -64,6 +65,11 @@ void TrackerFrame::OnConnect(wxCommandEvent &event) {
64 ConnectionDialog dlg; 65 ConnectionDialog dlg;
65 66
66 if (dlg.ShowModal() == wxID_OK) { 67 if (dlg.ShowModal() == wxID_OK) {
68 GetTrackerConfig().ap_server = dlg.GetServerValue();
69 GetTrackerConfig().ap_player = dlg.GetPlayerValue();
70 GetTrackerConfig().ap_password = dlg.GetPasswordValue();
71 GetTrackerConfig().Save();
72
67 GetAPState().Connect(dlg.GetServerValue(), dlg.GetPlayerValue(), 73 GetAPState().Connect(dlg.GetServerValue(), dlg.GetPlayerValue(),
68 dlg.GetPasswordValue()); 74 dlg.GetPasswordValue());
69 } 75 }