about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-11-26 14:05:29 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2023-11-26 14:05:29 -0500
commit2adce1795211fd0a42c3b4e03ab35a90bb01bccf (patch)
tree7fda2f874f0653e4c74edaaf1547fe9802b2005a /src
parent7fc0e0f50ae961efbe0cac1032b03a42d41d87d5 (diff)
downloadlingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.tar.gz
lingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.tar.bz2
lingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.zip
Stop relying on correctly set working directory
Diffstat (limited to 'src')
-rw-r--r--src/eye_indicator.cpp10
-rw-r--r--src/game_data.cpp12
-rw-r--r--src/global.cpp24
-rw-r--r--src/global.h11
-rw-r--r--src/logger.cpp4
-rw-r--r--src/tracker_config.cpp9
-rw-r--r--src/tracker_config.h5
-rw-r--r--src/tracker_panel.cpp4
8 files changed, 65 insertions, 14 deletions
diff --git a/src/eye_indicator.cpp b/src/eye_indicator.cpp index 03e234e..61ad780 100644 --- a/src/eye_indicator.cpp +++ b/src/eye_indicator.cpp
@@ -1,5 +1,7 @@
1#include "eye_indicator.h" 1#include "eye_indicator.h"
2 2
3#include "global.h"
4
3EyeIndicator::EyeIndicator(wxWindow* parent) : wxWindow(parent, wxID_ANY) { 5EyeIndicator::EyeIndicator(wxWindow* parent) : wxWindow(parent, wxID_ANY) {
4 SetMinSize({32, 32}); 6 SetMinSize({32, 32});
5 7
@@ -17,14 +19,14 @@ void EyeIndicator::SetChecked(bool checked) {
17} 19}
18 20
19const wxImage& EyeIndicator::GetUncheckedImage() { 21const wxImage& EyeIndicator::GetUncheckedImage() {
20 static wxImage* unchecked_image = 22 static wxImage* unchecked_image = new wxImage(
21 new wxImage("assets/unchecked.png", wxBITMAP_TYPE_PNG); 23 GetAbsolutePath("assets/unchecked.png").c_str(), wxBITMAP_TYPE_PNG);
22 return *unchecked_image; 24 return *unchecked_image;
23} 25}
24 26
25const wxImage& EyeIndicator::GetCheckedImage() { 27const wxImage& EyeIndicator::GetCheckedImage() {
26 static wxImage* checked_image = 28 static wxImage* checked_image = new wxImage(
27 new wxImage("assets/checked.png", wxBITMAP_TYPE_PNG); 29 GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG);
28 return *checked_image; 30 return *checked_image;
29} 31}
30 32
diff --git a/src/game_data.cpp b/src/game_data.cpp index 31e23ec..5204262 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp
@@ -6,6 +6,7 @@
6#include <iostream> 6#include <iostream>
7#include <sstream> 7#include <sstream>
8 8
9#include "global.h"
9#include "logger.h" 10#include "logger.h"
10 11
11namespace { 12namespace {
@@ -61,10 +62,13 @@ struct GameData {
61 std::set<std::string> malconfigured_areas_; 62 std::set<std::string> malconfigured_areas_;
62 63
63 GameData() { 64 GameData() {
64 YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); 65 YAML::Node lingo_config =
65 YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); 66 YAML::LoadFile(GetAbsolutePath("assets/LL1.yaml"));
66 YAML::Node pilgrimage_config = YAML::LoadFile("assets/pilgrimage.yaml"); 67 YAML::Node areas_config =
67 YAML::Node ids_config = YAML::LoadFile("assets/ids.yaml"); 68 YAML::LoadFile(GetAbsolutePath("assets/areas.yaml"));
69 YAML::Node pilgrimage_config =
70 YAML::LoadFile(GetAbsolutePath("assets/pilgrimage.yaml"));
71 YAML::Node ids_config = YAML::LoadFile(GetAbsolutePath("assets/ids.yaml"));
68 72
69 auto init_color_id = [this, &ids_config](const std::string &color_name) { 73 auto init_color_id = [this, &ids_config](const std::string &color_name) {
70 if (ids_config["special_items"] && 74 if (ids_config["special_items"] &&
diff --git a/src/global.cpp b/src/global.cpp new file mode 100644 index 0000000..3ee4f58 --- /dev/null +++ b/src/global.cpp
@@ -0,0 +1,24 @@
1#include "global.h"
2
3#include <whereami.h>
4
5#include <filesystem>
6#include <string>
7#include <string_view>
8
9const std::filesystem::path& GetExecutableDirectory() {
10 static const std::filesystem::path* executable_directory = []() {
11 int length = wai_getExecutablePath(NULL, 0, NULL);
12 std::string buf(length, 0);
13 wai_getExecutablePath(buf.data(), length, NULL);
14
15 std::filesystem::path exec_path(buf);
16 return new std::filesystem::path(exec_path.parent_path());
17 }();
18
19 return *executable_directory;
20}
21
22std::string GetAbsolutePath(std::string_view path) {
23 return (GetExecutableDirectory() / path).string();
24}
diff --git a/src/global.h b/src/global.h new file mode 100644 index 0000000..2eb7884 --- /dev/null +++ b/src/global.h
@@ -0,0 +1,11 @@
1#ifndef GLOBAL_H_44945DBA
2#define GLOBAL_H_44945DBA
3
4#include <filesystem>
5#include <string_view>
6
7const std::filesystem::path& GetExecutableDirectory();
8
9std::string GetAbsolutePath(std::string_view path);
10
11#endif /* end of include guard: GLOBAL_H_44945DBA */
diff --git a/src/logger.cpp b/src/logger.cpp index ccb721a..4b722c8 100644 --- a/src/logger.cpp +++ b/src/logger.cpp
@@ -4,11 +4,13 @@
4#include <fstream> 4#include <fstream>
5#include <mutex> 5#include <mutex>
6 6
7#include "global.h"
8
7namespace { 9namespace {
8 10
9class Logger { 11class Logger {
10 public: 12 public:
11 Logger() : logfile_("debug.log") {} 13 Logger() : logfile_(GetAbsolutePath("debug.log")) {}
12 14
13 void LogLine(const std::string& text) { 15 void LogLine(const std::string& text) {
14 std::lock_guard guard(file_mutex_); 16 std::lock_guard guard(file_mutex_);
diff --git a/src/tracker_config.cpp b/src/tracker_config.cpp index 11e1cec..b0f4ac4 100644 --- a/src/tracker_config.cpp +++ b/src/tracker_config.cpp
@@ -4,11 +4,11 @@
4 4
5#include <fstream> 5#include <fstream>
6 6
7constexpr const char* CONFIG_FILE_NAME = "config.yaml"; 7#include "global.h"
8 8
9void TrackerConfig::Load() { 9void TrackerConfig::Load() {
10 try { 10 try {
11 YAML::Node file = YAML::LoadFile(CONFIG_FILE_NAME); 11 YAML::Node file = YAML::LoadFile(filename_);
12 12
13 ap_server = file["ap_server"].as<std::string>(); 13 ap_server = file["ap_server"].as<std::string>();
14 ap_player = file["ap_player"].as<std::string>(); 14 ap_player = file["ap_player"].as<std::string>();
@@ -32,11 +32,12 @@ void TrackerConfig::Save() {
32 output["hybrid_areas"] = hybrid_areas; 32 output["hybrid_areas"] = hybrid_areas;
33 output["show_hunt_panels"] = show_hunt_panels; 33 output["show_hunt_panels"] = show_hunt_panels;
34 34
35 std::ofstream filewriter(CONFIG_FILE_NAME); 35 std::ofstream filewriter(filename_);
36 filewriter << output; 36 filewriter << output;
37} 37}
38 38
39TrackerConfig& GetTrackerConfig() { 39TrackerConfig& GetTrackerConfig() {
40 static TrackerConfig* instance = new TrackerConfig(); 40 static TrackerConfig* instance =
41 new TrackerConfig(GetAbsolutePath("config.yaml"));
41 return *instance; 42 return *instance;
42} 43}
diff --git a/src/tracker_config.h b/src/tracker_config.h index 0a29d2c..b95194e 100644 --- a/src/tracker_config.h +++ b/src/tracker_config.h
@@ -5,6 +5,8 @@
5 5
6class TrackerConfig { 6class TrackerConfig {
7 public: 7 public:
8 explicit TrackerConfig(const std::string& filename) : filename_(filename) {}
9
8 void Load(); 10 void Load();
9 11
10 void Save(); 12 void Save();
@@ -16,6 +18,9 @@ class TrackerConfig {
16 bool should_check_for_updates = false; 18 bool should_check_for_updates = false;
17 bool hybrid_areas = false; 19 bool hybrid_areas = false;
18 bool show_hunt_panels = false; 20 bool show_hunt_panels = false;
21
22 private:
23 std::string filename_;
19}; 24};
20 25
21TrackerConfig& GetTrackerConfig(); 26TrackerConfig& GetTrackerConfig();
diff --git a/src/tracker_panel.cpp b/src/tracker_panel.cpp index 5e035af..81cb595 100644 --- a/src/tracker_panel.cpp +++ b/src/tracker_panel.cpp
@@ -3,6 +3,7 @@
3#include "ap_state.h" 3#include "ap_state.h"
4#include "area_popup.h" 4#include "area_popup.h"
5#include "game_data.h" 5#include "game_data.h"
6#include "global.h"
6#include "tracker_config.h" 7#include "tracker_config.h"
7#include "tracker_state.h" 8#include "tracker_state.h"
8 9
@@ -11,7 +12,8 @@ constexpr int AREA_BORDER_SIZE = 5;
11constexpr int AREA_EFFECTIVE_SIZE = AREA_ACTUAL_SIZE + AREA_BORDER_SIZE * 2; 12constexpr int AREA_EFFECTIVE_SIZE = AREA_ACTUAL_SIZE + AREA_BORDER_SIZE * 2;
12 13
13TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { 14TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
14 map_image_ = wxImage("assets/lingo_map.png", wxBITMAP_TYPE_PNG); 15 map_image_ = wxImage(GetAbsolutePath("assets/lingo_map.png").c_str(),
16 wxBITMAP_TYPE_PNG);
15 if (!map_image_.IsOk()) { 17 if (!map_image_.IsOk()) {
16 return; 18 return;
17 } 19 }