Cannot save or otherwise specify filenames
Closed this issue · 1 comments
ziz commented
Since there is no method for interrogating the client as to what filename to use for a save game or similar, one cannot save or restore using remglk at this time.
I have written an embarrassingly cheap hack to allow saving - basically, add a "savename" field to the line input you're returning before the system needs a filename.
diff --git a/rgdata.c b/rgdata.c
index 499fc58..1e73ae0 100644
--- a/rgdata.c
+++ b/rgdata.c
@@ -1023,6 +1023,11 @@ data_event_t *data_event_read()
dat = data_raw_struct_field(rawdata, "terminator");
if (dat)
input->terminator = data_raw_str_char(dat);
+
+ dat = data_raw_struct_field(rawdata, "savefile");
+ if (dat)
+ rgfref_set_nextsavename(data_raw_str_dup(dat), dat->count);
+
}
else if (data_raw_string_is(dat, "char")) {
input->dtag = dtag_Char;
diff --git a/rgdata.h b/rgdata.h
index 9568024..8904d38 100644
--- a/rgdata.h
+++ b/rgdata.h
@@ -163,3 +163,5 @@ extern data_line_t *data_line_alloc(void);
extern void data_line_free(data_line_t *data);
extern void data_line_add_span(data_line_t *data, short style, glui32 *str, long len);
extern void data_line_print(data_line_t *data, glui32 wintype);
+
+extern void rgfref_set_nextsavename(glui32 *filename, glui32 length);
diff --git a/rgfref.c b/rgfref.c
index e1bcb2a..e33694a 100644
--- a/rgfref.c
+++ b/rgfref.c
@@ -24,10 +24,23 @@ static fileref_t *gli_filereflist = NULL;
static char workingdir[BUFLEN] = ".";
static char lastsavename[BUFLEN] = "game.glksave";
+static char nextsavename[BUFLEN] = "game";
static char lastscriptname[BUFLEN] = "script.txt";
static char lastcmdname[BUFLEN] = "commands.txt";
static char lastdataname[BUFLEN] = "file.glkdata";
+void rgfref_set_nextsavename(glui32 *filename, glui32 length)
+{
+ glui32 ptr;
+ /* Silently avoid buffer overflows */
+ if (length >= BUFLEN)
+ return;
+ for (ptr = 0; ptr < length; ptr++) {
+ nextsavename[ptr] = filename[ptr];
+ }
+ nextsavename[length] = 0;
+}
+
fileref_t *gli_new_fileref(char *filename, glui32 usage, glui32 rock)
{
fileref_t *fref = (fileref_t *)malloc(sizeof(fileref_t));
@@ -246,10 +259,13 @@ frefid_t glk_fileref_create_by_prompt(glui32 usage, glui32 fmode,
val = 0;
}
+ strcpy(buf, nextsavename);
+ val = strlen(buf);
+
ix = NULL; /*### fetch somehow */
if (!ix) {
/* The player cancelled input. */
- return NULL;
+ /*return NULL; */
}
/* Trim whitespace from end and beginning. */
Example message (specifying a SAVE command, with a savefile name of 'foobar'):
{"type":"line","gen":1,"window":30,"value":"SAVE","savefile":"foobar"}
I don't recommend this at all for long-term use, but if you're impatient like me, it'll get you by until a real solution has been devised and implemented.
erkyrath commented
This went in with the 0.2.1 release. When prompting, the update call contains a specialinput object, and the event that comes back has type specialresponse.