diff options
author | Paul Gilbert | 2018-11-17 16:52:47 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | b05a16a0ad0dcc2881aeda81e0d1a84a752eccab (patch) | |
tree | e7f0468357c5c3248591bd334b1a4d42a999b550 /engines/glk/scott | |
parent | 326f69136eb4fee72391a8175ad722a317f84ca6 (diff) | |
download | scummvm-rg350-b05a16a0ad0dcc2881aeda81e0d1a84a752eccab.tar.gz scummvm-rg350-b05a16a0ad0dcc2881aeda81e0d1a84a752eccab.tar.bz2 scummvm-rg350-b05a16a0ad0dcc2881aeda81e0d1a84a752eccab.zip |
GLK: Centralizing more of the savegame code in GlkEngine
Diffstat (limited to 'engines/glk/scott')
-rw-r--r-- | engines/glk/scott/scott.cpp | 45 | ||||
-rw-r--r-- | engines/glk/scott/scott.h | 10 |
2 files changed, 7 insertions, 48 deletions
diff --git a/engines/glk/scott/scott.cpp b/engines/glk/scott/scott.cpp index fed31f014e..cbc5886130 100644 --- a/engines/glk/scott/scott.cpp +++ b/engines/glk/scott/scott.cpp @@ -309,7 +309,7 @@ void Scott::loadDatabase(Common::SeekableReadStream *f, bool loud) { if (loud) debug("Reading %d actions.", na); - for (uint idx = 0; idx < na + 1; ++idx) { + for (int idx = 0; idx < na + 1; ++idx) { Action &a = _actions[idx]; readInts(f, 8, &a._vocab, &a._condition[0], &a._condition[1], &a._condition[2], @@ -503,26 +503,8 @@ void Scott::lineInput(char *buf, size_t n) { buf[ev.val1] = 0; } -void Scott::saveGame(void) { - frefid_t ref = glk_fileref_create_by_prompt(fileusage_TextMode | fileusage_SavedGame, - filemode_Write, 0); - if (ref == nullptr) - return; - - int slot = ref->_slotNumber; - Common::String desc = ref->_description; - glk_fileref_destroy(ref); - - saveGameState(slot, desc); -} - -Common::Error Scott::saveGameState(int slot, const Common::String &desc) { +Common::Error Scott::saveGameData(strid_t file) { Common::String msg; - FileReference ref(slot, desc, fileusage_TextMode | fileusage_SavedGame); - - strid_t file = glk_stream_open_file(&ref, filemode_Write, 0); - if (file == nullptr) - return Common::kWritingFailed; for (int ct = 0; ct < 16; ct++) { msg = Common::String::format("%d %d\n", _counters[ct], _roomSaved[ct]); @@ -539,37 +521,16 @@ Common::Error Scott::saveGameState(int slot, const Common::String &desc) { glk_put_string_stream(file, msg.c_str()); } - glk_stream_close(file, nullptr); output("Saved.\n"); - return Common::kNoError; } -void Scott::loadGame(void) { - frefid_t ref = glk_fileref_create_by_prompt(fileusage_TextMode | fileusage_SavedGame, - filemode_Read, 0); - if (ref == nullptr) - return; - - int slotNumber = ref->_slotNumber; - glk_fileref_destroy(ref); - - loadGameState(slotNumber); -} - -Common::Error Scott::loadGameState(int slot) { - strid_t file; +Common::Error Scott::loadGameData(strid_t file) { char buf[128]; int ct = 0; short lo; short darkFlag; - FileReference ref(slot, "", fileusage_SavedGame | fileusage_TextMode); - - file = glk_stream_open_file(&ref, filemode_Read, 0); - if (file == nullptr) - return Common::kReadingFailed; - for (ct = 0; ct < 16; ct++) { glk_get_line_stream(file, buf, sizeof buf); sscanf(buf, "%d %d", &_counters[ct], &_roomSaved[ct]); diff --git a/engines/glk/scott/scott.h b/engines/glk/scott/scott.h index 4741892687..a22f88bf94 100644 --- a/engines/glk/scott/scott.h +++ b/engines/glk/scott/scott.h @@ -153,8 +153,6 @@ private: void look(void); int whichWord(const char *word, const Common::StringArray &list); void lineInput(char *buf, size_t n); - void saveGame(void); - void loadGame(void); int getInput(int *vb, int *no); int performLine(int ct); int performActions(int vb, int no); @@ -174,14 +172,14 @@ public: virtual void runGame(Common::SeekableReadStream *gameFile) override; /** - * Load a savegame + * Load a savegame from the passed stream */ - virtual Common::Error loadGameState(int slot) override; + virtual Common::Error loadGameData(strid_t file) override; /** - * Save the game + * Save the game to the passed stream */ - virtual Common::Error saveGameState(int slot, const Common::String &desc) override; + virtual Common::Error saveGameData(strid_t file) override; }; } // End of namespace Scott |