From 9b9e0384382eef86d0a44361503cd132444fbb85 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 12 May 2015 17:18:51 -0700 Subject: [PATCH] press F3 to save game in editor. --- src/gmtool.c | 39 ++++++++++++++++++++++++++++----------- src/kernel/save.c | 2 +- src/kernel/save.h | 2 +- src/kernel/save.test.c | 2 +- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/gmtool.c b/src/gmtool.c index fc9fccdb9..5afb61a36 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -761,6 +761,29 @@ static void select_regions(state * st, int selectmode) st->wnd_map->update |= 3; } +void loaddata(state *st) { + char datafile[MAX_PATH]; + + askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); + if (strlen(datafile) > 0) { + create_backup(datafile); + readgame(datafile, false); + st->modified = 0; + } +} + +void savedata(state *st) { + char datafile[MAX_PATH]; + + askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); + if (strlen(datafile) > 0) { + create_backup(datafile); + remove_empty_units(); + writegame(datafile); + st->modified = 0; + } +} + static void handlekey(state * st, int c) { window *wnd; @@ -816,17 +839,11 @@ static void handlekey(state * st, int c) case 'S': case KEY_SAVE: case KEY_F(2): - /* if (st->modified) */ { - char datafile[MAX_PATH]; - - askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); - if (strlen(datafile) > 0) { - create_backup(datafile); - remove_empty_units(); - writegame(datafile); - st->modified = 0; - } - } + savedata(st); + break; + case KEY_F(3): + case KEY_OPEN: + loaddata(st); break; case 'B': /* diff --git a/src/kernel/save.c b/src/kernel/save.c index d9a18f2b3..ad0c51f61 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1348,7 +1348,7 @@ void writefaction(struct gamedata *data, const faction * f) write_spellbook(f->spellbook, data->store); } -int readgame(const char *filename, int backup) +int readgame(const char *filename, bool backup) { int n, p, nread; faction *f, **fp; diff --git a/src/kernel/save.h b/src/kernel/save.h index ee731fab8..11b53d620 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -44,7 +44,7 @@ extern "C" { int readorders(const char *filename); int creategame(void); - int readgame(const char *filename, int backup); + int readgame(const char *filename, bool backup); int writegame(const char *filename); /* Versionsänderungen: */ diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index cdbdbd3bf..26f48a07f 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -15,7 +15,7 @@ static void test_readwrite_data(CuTest * tc) test_cleanup(); sprintf(path, "%s/%s", datapath(), filename); CuAssertIntEquals(tc, 0, writegame(filename)); - CuAssertIntEquals(tc, 0, readgame(filename, 0)); + CuAssertIntEquals(tc, 0, readgame(filename, false)); CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version); CuAssertIntEquals(tc, 0, remove(path)); test_cleanup();