1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-20 11:54:48 +00:00

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
remove_emergency_save();
FILE *f = fopen(scorefile, "at");
FILE *f = fopen(scorefile.c_str(), "at");
if(!f) return;
int t = (int) (time(NULL) - timerstart);

View File

@ -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

View File

@ -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) {

View File

@ -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;

View File

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

View File

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

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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);