diff --git a/achievement.cpp b/achievement.cpp index 3963daaf..98a71f31 100644 --- a/achievement.cpp +++ b/achievement.cpp @@ -174,7 +174,7 @@ EX void achievement_log(const char* s, char flags) { #if CAP_SAVE remove_emergency_save(); - FILE *f = fopen(scorefile, "at"); + FILE *f = fopen(scorefile.c_str(), "at"); if(!f) return; int t = (int) (time(NULL) - timerstart); diff --git a/commandline.cpp b/commandline.cpp index bb6c8c76..5fd4bb15 100644 --- a/commandline.cpp +++ b/commandline.cpp @@ -17,7 +17,7 @@ EX string rsrcdir = ""; #endif #if CAP_COMMANDLINE -EX const char *scorefile = "hyperrogue.log"; +EX string scorefile = "hyperrogue.log"; EX namespace arg { EX eLand readland(const string& ss) { @@ -63,7 +63,7 @@ EX void initializeCLI() { if(getenv("HOME")) { sbuf = getenv("HOME"); sbuf += "/."; sbuf += scorefile; cbuf = getenv("HOME"); cbuf += "/."; cbuf += conffile; - scorefile = sbuf.c_str(); + scorefile = sbuf; conffile = cbuf.c_str(); } #endif @@ -168,7 +168,8 @@ int arg::readCommon() { // first phase options - if(argis("-s")) { PHASE(1); shift(); scorefile = argcs(); } + if(argis("-s")) { PHASE(2); shift(); scorefile = args(); savefile_selection = false; } + else if(argis("-no-s")) { PHASE(2); scorefile = ""; savefile_selection = false; } else if(argis("-rsrc")) { PHASE(1); shift(); rsrcdir = args(); } else if(argis("-nogui")) { PHASE(1); noGUI = true; } #ifndef EMSCRIPTEN diff --git a/config.cpp b/config.cpp index 59eab198..b6822d6c 100644 --- a/config.cpp +++ b/config.cpp @@ -1811,6 +1811,8 @@ EX void configureOther() { dialog::addSelItem(XLAT("whatever"), fts(whatever[0]), 'j'); dialog::add_action([] { edit_whatever('f', 0); }); #endif + + add_edit(savefile_selection); dialog::addBreak(50); dialog::addBack(); @@ -2498,6 +2500,17 @@ EX int config3 = addHook(hooks_configfile, 100, [] { }); param_b(debug_tiles, "debug_tiles"); addsaver(vid.gp_autoscale_heights, "3D Goldberg autoscaling", true); + addsaver(scorefile, "savefile"); + param_b(savefile_selection, "savefile_selection") + -> editable("select the score/save file on startup", 's') + -> set_reaction([] { + if(savefile_selection) + addMessage(XLAT("Save the config and restart to select another score/save file.")); + else if(scorefile == "") + addMessage(XLAT("Save the config to always play without recording your progress.")); + else + addMessage(XLAT("Save the config to always use %1.", scorefile)); + }); }); EX void switchcolor(unsigned int& c, unsigned int* cs) { diff --git a/debug.cpp b/debug.cpp index a5f66f39..1a925ab6 100644 --- a/debug.cpp +++ b/debug.cpp @@ -611,8 +611,8 @@ int read_cheat_args() { else if(argis("-g")) { /* debugging mode */ if(curphase == 1) { - /* use a separate score file */ - scorefile = "xx"; + /* use no score file */ + scorefile = ""; /* set seed for reproducible results */ if(!fixseed) { fixseed = true; autocheat = true; diff --git a/fake-mobile.cpp b/fake-mobile.cpp index b30451a2..88b6de02 100644 --- a/fake-mobile.cpp +++ b/fake-mobile.cpp @@ -9,7 +9,7 @@ #include namespace hr { - const char *scorefile = "fakemobile_score.txt"; + string scorefile = "fakemobile_score.txt"; } #include diff --git a/hyper-main.cpp b/hyper-main.cpp index f399a9f7..4d0e4441 100644 --- a/hyper-main.cpp +++ b/hyper-main.cpp @@ -86,6 +86,7 @@ EX int hyper_main(int argc, char **argv) { pushScreen(showStartMenu); } #endif + progress_warning(); mainloop(); finishAll(); return 0; diff --git a/menus.cpp b/menus.cpp index 57e53970..9a1961fb 100644 --- a/menus.cpp +++ b/menus.cpp @@ -948,6 +948,7 @@ EX void showStartMenu() { resetModes(uni); clearMessages(); welcomeMessage(); + progress_warning(); stampbase = ticks; if(uni == 's') multi::configure(); @@ -1003,6 +1004,7 @@ EX void showStartMenu() { stampbase = ticks; clearMessages(); welcomeMessage(); + progress_warning(); } else if(sym == SDLK_F5) { #if CAP_STARTANIM diff --git a/scores.cpp b/scores.cpp index 7defd216..ff0a679e 100644 --- a/scores.cpp +++ b/scores.cpp @@ -287,10 +287,11 @@ void show() { } void load() { + if(scorefile == "") return; scores.clear(); - FILE *f = fopen(scorefile, "rt"); + FILE *f = fopen(scorefile.c_str(), "rt"); if(!f) { - printf("Could not open the score file '%s'!\n", scorefile); + printf("Could not open the score file '%s'!\n", scorefile.c_str()); addMessage(s0 + "Could not open the score file: " + scorefile); return; } diff --git a/system.cpp b/system.cpp index c979001d..c6186315 100644 --- a/system.cpp +++ b/system.cpp @@ -1001,9 +1001,10 @@ EX } long long saveposition = -1; EX void remove_emergency_save() { + if(scorefile == "") return; #if !ISWINDOWS if(saveposition >= 0) { - if(truncate(scorefile, saveposition)) {} + if(truncate(scorefile.c_str(), saveposition)) {} saveposition = -1; } #endif @@ -1015,6 +1016,7 @@ EX void saveStats(bool emergency IS(false)) { DEBBI(DF_INIT, ("saveStats [", scorefile, "]")); if(autocheat) return; + if(scorefile == "") return; #if CAP_TOUR if(tour::on) return; #endif @@ -1031,7 +1033,7 @@ EX void saveStats(bool emergency IS(false)) { xcode = modecode(); - FILE *f = fopen(scorefile, "at"); + FILE *f = fopen(scorefile.c_str(), "at"); if(!f) { // printf("Could not open the score file '%s'!\n", scorefile); @@ -1156,12 +1158,13 @@ bool tamper = false; // load the save EX void loadsave() { if(autocheat) return; + if(scorefile == "") return; #if CAP_TOUR if(tour::on) return; #endif DEBBI(DF_INIT, ("loadSave")); - FILE *f = fopen(scorefile, "rt"); + FILE *f = fopen(scorefile.c_str(), "rt"); havesave = f; if(!f) return; bool ok = false; @@ -1659,6 +1662,33 @@ EX eLand firstland0; EX purehookset hooks_initialize; +EX bool savefile_selection = false; + +EX void select_savefile() { + if(!savefile_selection) return; + start_game(); + bool canceled = true; + if(scorefile == "") scorefile = "hyperrogue.log"; + pushScreen([] { quitmainloop = true; }); + dialog::openFileDialog(scorefile, XLAT("choose your score/save file"), ".log", [&] { + println(hlog, "hook called"); + canceled = false; + quitmainloop = true; + return true; + }); + clearMessages(); + mainloop(); + quitmainloop = false; + stop_game(); + popScreenAll(); + if(canceled) scorefile = ""; + } + +EX void progress_warning() { + if(scorefile == "" && savefile_selection) + addMessage(XLAT("Your progress will not be saved.")); + } + EX void initAll() { callhooks(hooks_initialize); init_floorcolors(); @@ -1676,7 +1706,9 @@ EX void initAll() { // initlanguage(); initialize_all(); + #if CAP_SAVE + select_savefile(); loadsave(); if(IRREGULAR) irr::auto_creator(); #endif diff --git a/yendor.cpp b/yendor.cpp index 51dedfda..a02690d4 100644 --- a/yendor.cpp +++ b/yendor.cpp @@ -999,8 +999,11 @@ EX modecode_t modecode(int mode) { code_for[ss.s] = next; if(mode == 2) return next; + + if(scorefile == "") return next; - FILE *f = fopen(scorefile, "at"); + FILE *f = fopen(scorefile.c_str(), "at"); + if(!f) return next; string s = as_hexstring(ss.s); fprintf(f, "MODE %d %s\n", next, s.c_str()); fclose(f);