find_file to find files in HYPERPATH

This commit is contained in:
Zeno Rogue 2022-08-26 12:23:58 +02:00
parent 7be773ea03
commit 31b2bd9690
4 changed files with 21 additions and 4 deletions

View File

@ -1722,7 +1722,7 @@ auto hook = addHook(hooks_args, 100, readArgs);
EX bool in() { return geometry == gArbitrary; }
EX string tes = "tessellations/sample/marjorie-rice.tes";
EX string tes = find_file("tessellations/sample/marjorie-rice.tes");
EX bool linespattern(cell *c) {
return current.shapes[id_of(c->master)].flags & arcm::sfLINE;

View File

@ -207,7 +207,7 @@ EX bool loadMusicInfo() {
#endif
#ifdef FHS
|| loadMusicInfo("/usr/share/hyperrogue/hyperrogue-music.txt")
|| loadMusicInfo(s0 + getenv("HOME") + "/.hyperrogue-music.txt")
|| (getenv("HOME") && loadMusicInfo(s0 + getenv("HOME") + "/.hyperrogue-music.txt"))
#endif
;
}

View File

@ -28,6 +28,10 @@ struct textureinfo : basic_textureinfo {
};
#endif
#if HDR
string find_file(string s);
#endif
EX namespace texture {
#if HDR
@ -120,8 +124,8 @@ struct texture_config {
texture_config() {
// argh, no member initialization in some of my compilers
texturename = "textures/hyperrogue-texture.png";
configname = "textures/hyperrogue.txc";
texturename = find_file("textures/hyperrogue-texture.png");
configname = find_file("textures/hyperrogue.txc");
itt = Id;
grid_color = 0;
mesh_color = 0;

View File

@ -766,6 +766,19 @@ EX bool file_exists(string fname) {
return access(fname.c_str(), F_OK) != -1;
}
/** find a file named s, possibly in HYPERPATH */
EX string find_file(string s) {
string s1;
if(file_exists(s)) return s;
char *p = getenv("HYPERPATH");
if(p && file_exists(s1 = s0 + p + s)) return s1;
if(file_exists(s1 = HYPERPATH + s)) return s1;
#ifdef FHS
if(file_exists(s1 = "/usr/share/hyperrogue/" + s)) return s1;
#endif
return s;
}
EX void open_url(string s) {
#if ISWEB
EM_ASM_({