savefile selection / an option to use no savefile

This commit is contained in:
Zeno Rogue 2022-09-15 12:38:39 +02:00
parent a20063c119
commit 308fcd90aa
10 changed files with 66 additions and 13 deletions

View File

@ -174,7 +174,7 @@ EX void achievement_log(const char* s, char flags) {
#if CAP_SAVE #if CAP_SAVE
remove_emergency_save(); remove_emergency_save();
FILE *f = fopen(scorefile, "at"); FILE *f = fopen(scorefile.c_str(), "at");
if(!f) return; if(!f) return;
int t = (int) (time(NULL) - timerstart); int t = (int) (time(NULL) - timerstart);

View File

@ -17,7 +17,7 @@ EX string rsrcdir = "";
#endif #endif
#if CAP_COMMANDLINE #if CAP_COMMANDLINE
EX const char *scorefile = "hyperrogue.log"; EX string scorefile = "hyperrogue.log";
EX namespace arg { EX namespace arg {
EX eLand readland(const string& ss) { EX eLand readland(const string& ss) {
@ -63,7 +63,7 @@ EX void initializeCLI() {
if(getenv("HOME")) { if(getenv("HOME")) {
sbuf = getenv("HOME"); sbuf += "/."; sbuf += scorefile; sbuf = getenv("HOME"); sbuf += "/."; sbuf += scorefile;
cbuf = getenv("HOME"); cbuf += "/."; cbuf += conffile; cbuf = getenv("HOME"); cbuf += "/."; cbuf += conffile;
scorefile = sbuf.c_str(); scorefile = sbuf;
conffile = cbuf.c_str(); conffile = cbuf.c_str();
} }
#endif #endif
@ -168,7 +168,8 @@ int arg::readCommon() {
// first phase options // 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("-rsrc")) { PHASE(1); shift(); rsrcdir = args(); }
else if(argis("-nogui")) { PHASE(1); noGUI = true; } else if(argis("-nogui")) { PHASE(1); noGUI = true; }
#ifndef EMSCRIPTEN #ifndef EMSCRIPTEN

View File

@ -1811,6 +1811,8 @@ EX void configureOther() {
dialog::addSelItem(XLAT("whatever"), fts(whatever[0]), 'j'); dialog::addSelItem(XLAT("whatever"), fts(whatever[0]), 'j');
dialog::add_action([] { edit_whatever('f', 0); }); dialog::add_action([] { edit_whatever('f', 0); });
#endif #endif
add_edit(savefile_selection);
dialog::addBreak(50); dialog::addBreak(50);
dialog::addBack(); dialog::addBack();
@ -2498,6 +2500,17 @@ EX int config3 = addHook(hooks_configfile, 100, [] {
}); });
param_b(debug_tiles, "debug_tiles"); param_b(debug_tiles, "debug_tiles");
addsaver(vid.gp_autoscale_heights, "3D Goldberg autoscaling", true); 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) { EX void switchcolor(unsigned int& c, unsigned int* cs) {

View File

@ -611,8 +611,8 @@ int read_cheat_args() {
else if(argis("-g")) { else if(argis("-g")) {
/* debugging mode */ /* debugging mode */
if(curphase == 1) { if(curphase == 1) {
/* use a separate score file */ /* use no score file */
scorefile = "xx"; scorefile = "";
/* set seed for reproducible results */ /* set seed for reproducible results */
if(!fixseed) { if(!fixseed) {
fixseed = true; autocheat = true; fixseed = true; autocheat = true;

View File

@ -9,7 +9,7 @@
#include <string> #include <string>
namespace hr { namespace hr {
const char *scorefile = "fakemobile_score.txt"; string scorefile = "fakemobile_score.txt";
} }
#include <SDL/SDL.h> #include <SDL/SDL.h>

View File

@ -86,6 +86,7 @@ EX int hyper_main(int argc, char **argv) {
pushScreen(showStartMenu); pushScreen(showStartMenu);
} }
#endif #endif
progress_warning();
mainloop(); mainloop();
finishAll(); finishAll();
return 0; return 0;

View File

@ -948,6 +948,7 @@ EX void showStartMenu() {
resetModes(uni); resetModes(uni);
clearMessages(); clearMessages();
welcomeMessage(); welcomeMessage();
progress_warning();
stampbase = ticks; stampbase = ticks;
if(uni == 's') if(uni == 's')
multi::configure(); multi::configure();
@ -1003,6 +1004,7 @@ EX void showStartMenu() {
stampbase = ticks; stampbase = ticks;
clearMessages(); clearMessages();
welcomeMessage(); welcomeMessage();
progress_warning();
} }
else if(sym == SDLK_F5) { else if(sym == SDLK_F5) {
#if CAP_STARTANIM #if CAP_STARTANIM

View File

@ -287,10 +287,11 @@ void show() {
} }
void load() { void load() {
if(scorefile == "") return;
scores.clear(); scores.clear();
FILE *f = fopen(scorefile, "rt"); FILE *f = fopen(scorefile.c_str(), "rt");
if(!f) { 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); addMessage(s0 + "Could not open the score file: " + scorefile);
return; return;
} }

View File

@ -1001,9 +1001,10 @@ EX }
long long saveposition = -1; long long saveposition = -1;
EX void remove_emergency_save() { EX void remove_emergency_save() {
if(scorefile == "") return;
#if !ISWINDOWS #if !ISWINDOWS
if(saveposition >= 0) { if(saveposition >= 0) {
if(truncate(scorefile, saveposition)) {} if(truncate(scorefile.c_str(), saveposition)) {}
saveposition = -1; saveposition = -1;
} }
#endif #endif
@ -1015,6 +1016,7 @@ EX void saveStats(bool emergency IS(false)) {
DEBBI(DF_INIT, ("saveStats [", scorefile, "]")); DEBBI(DF_INIT, ("saveStats [", scorefile, "]"));
if(autocheat) return; if(autocheat) return;
if(scorefile == "") return;
#if CAP_TOUR #if CAP_TOUR
if(tour::on) return; if(tour::on) return;
#endif #endif
@ -1031,7 +1033,7 @@ EX void saveStats(bool emergency IS(false)) {
xcode = modecode(); xcode = modecode();
FILE *f = fopen(scorefile, "at"); FILE *f = fopen(scorefile.c_str(), "at");
if(!f) { if(!f) {
// printf("Could not open the score file '%s'!\n", scorefile); // printf("Could not open the score file '%s'!\n", scorefile);
@ -1156,12 +1158,13 @@ bool tamper = false;
// load the save // load the save
EX void loadsave() { EX void loadsave() {
if(autocheat) return; if(autocheat) return;
if(scorefile == "") return;
#if CAP_TOUR #if CAP_TOUR
if(tour::on) return; if(tour::on) return;
#endif #endif
DEBBI(DF_INIT, ("loadSave")); DEBBI(DF_INIT, ("loadSave"));
FILE *f = fopen(scorefile, "rt"); FILE *f = fopen(scorefile.c_str(), "rt");
havesave = f; havesave = f;
if(!f) return; if(!f) return;
bool ok = false; bool ok = false;
@ -1659,6 +1662,33 @@ EX eLand firstland0;
EX purehookset hooks_initialize; 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() { EX void initAll() {
callhooks(hooks_initialize); callhooks(hooks_initialize);
init_floorcolors(); init_floorcolors();
@ -1676,7 +1706,9 @@ EX void initAll() {
// initlanguage(); // initlanguage();
initialize_all(); initialize_all();
#if CAP_SAVE #if CAP_SAVE
select_savefile();
loadsave(); loadsave();
if(IRREGULAR) irr::auto_creator(); if(IRREGULAR) irr::auto_creator();
#endif #endif

View File

@ -999,8 +999,11 @@ EX modecode_t modecode(int mode) {
code_for[ss.s] = next; code_for[ss.s] = next;
if(mode == 2) return 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); string s = as_hexstring(ss.s);
fprintf(f, "MODE %d %s\n", next, s.c_str()); fprintf(f, "MODE %d %s\n", next, s.c_str());
fclose(f); fclose(f);