@@ -36,10 +36,14 @@ class Painter {
3636 // TODO: use map instead mapgen
3737 Painter (sf::RenderWindow *w, MapGenerator *m, std::string v)
3838 : window(w), mapgen(m), VERSION (v) {
39+
40+ auto dir = get_selfpath ();
41+ char path[100 ];
42+ sprintf (path, " %s/font.ttf" , dir.c_str ());
43+ mg::info (" Loading font:" , path);
44+ sffont.loadFromFile (path);
3945 loadIcons ();
4046 initProgressBar ();
41- // TODO: use whereami
42- sffont.loadFromFile (" ./font.ttf" );
4347
4448 sf::Vector2u windowSize = window->getSize ();
4549 cachedMap.create (windowSize.x , windowSize.y );
@@ -66,6 +70,20 @@ class Painter {
6670 sf::Clock clock;
6771 std::vector<Walker*> walkers;
6872
73+ std::string get_selfpath () {
74+ char buff[PATH_MAX ];
75+ #ifdef _WIN32
76+ GetModuleFileName (NULL ,buff,sizeof (buff));
77+ #else
78+ ssize_t len = ::readlink (" /proc/self/exe" , buff, sizeof (buff)-1 );
79+ if (len != -1 ) {
80+ buff[len] = ' \0 ' ;
81+ }
82+ #endif
83+ auto path = std::string (buff);
84+ return path.substr (0 , path.size ()-7 );
85+ }
86+
6987 void initProgressBar () {
7088 progressBar.setShowBackgroundAndFrame (true );
7189 progressBar.setSize (sf::Vector2f (400 , 10 ));
@@ -80,10 +98,14 @@ class Painter {
8098 {TRADE , " images/trade.png" }, {LIGHTHOUSE , " images/lighthouse.png" },
8199 {CAVE , " images/cave.png" }, {FORT , " images/fort.png" }};
82100
101+ auto dir = get_selfpath ();
102+ char path[100 ];
103+
83104 for (auto pair : iconMap) {
84105 sf::Texture *icon = new sf::Texture ();
85- mg::info (" Loading icon:" , pair.second );
86- icon->loadFromFile (pair.second );
106+ sprintf (path, " %s/%s" , dir.c_str (), pair.second .c_str ());
107+ mg::info (" Loading icon:" , path);
108+ icon->loadFromFile (path);
87109 icon->setSmooth (true );
88110 icons.insert (std::make_pair (pair.first , icon));
89111 }
0 commit comments