From 023a587b5b2c8aad5c8770b3619e15bc35f0271f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Nov 2019 18:47:16 -0800 Subject: GLK: ARCHETYPE: Allowing savegames from launcher --- engines/glk/archetype/archetype.cpp | 25 +++++++++++++++++++++++-- engines/glk/archetype/archetype.h | 7 ++++++- engines/glk/archetype/sys_object.cpp | 6 +++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/engines/glk/archetype/archetype.cpp b/engines/glk/archetype/archetype.cpp index 204bd9fb2f..fb1d277bb1 100644 --- a/engines/glk/archetype/archetype.cpp +++ b/engines/glk/archetype/archetype.cpp @@ -87,6 +87,9 @@ bool Archetype::initialize() { _mainWindow = glk_window_open(0, 0, 0, wintype_TextBuffer); glk_set_window(_mainWindow); + // Check for savegame to load + _saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; + return true; } @@ -104,6 +107,12 @@ Common::Error Archetype::writeGameData(Common::WriteStream *ws) { return Common::kNoError; } +Common::Error Archetype::loadLauncherSavegame() { + Common::Error result = loadGameState(_saveSlot); + _saveSlot = -2; + return result; +} + void Archetype::interpret() { Translating = false; bool success = load_game(&_gameFile); @@ -130,7 +139,9 @@ void Archetype::write(const String fmt, ...) { va_end(ap); _lastOutputText = s; - glk_put_buffer(s.c_str(), s.size()); + + if (!loadingSavegame()) + glk_put_buffer(s.c_str(), s.size()); } void Archetype::writeln(const String fmt, ...) { @@ -141,7 +152,9 @@ void Archetype::writeln(const String fmt, ...) { s += '\n'; _lastOutputText = s; - glk_put_buffer(s.c_str(), s.size()); + + if (!loadingSavegame()) + glk_put_buffer(s.c_str(), s.size()); } String Archetype::readLine() { @@ -153,6 +166,14 @@ String Archetype::readLine() { if (text.contains("save") || text.contains("load")) { writeln(); return ""; + + } else if (loadingSavegame()) { + // Automatically trigger a load action if a savegame needs loading from the launcher + return String("load"); + + } else if (_saveSlot == -2) { + _saveSlot = -1; + return String("look"); } event_t ev; diff --git a/engines/glk/archetype/archetype.h b/engines/glk/archetype/archetype.h index beb67b6680..643f5e0007 100644 --- a/engines/glk/archetype/archetype.h +++ b/engines/glk/archetype/archetype.h @@ -159,9 +159,14 @@ public: * Returns true if a savegame is being loaded directly from the ScummVM launcher */ bool loadingSavegame() const { - return _saveSlot != -1; + return _saveSlot >= 0; } + /** + * Handles loading the savegame specified in the ScummVM launcher + */ + Common::Error loadLauncherSavegame(); + /** * Write some text to the screen */ diff --git a/engines/glk/archetype/sys_object.cpp b/engines/glk/archetype/sys_object.cpp index 784d9a4cd7..ec98038be3 100644 --- a/engines/glk/archetype/sys_object.cpp +++ b/engines/glk/archetype/sys_object.cpp @@ -282,7 +282,11 @@ void send_to_system(int transport, String &strmsg, ResultType &result, ContextTy break; case LOAD_STATE: { - Common::ErrorCode errCode = g_vm->loadGame().getCode(); + Common::ErrorCode errCode; + if (g_vm->loadingSavegame()) + errCode = g_vm->loadLauncherSavegame().getCode(); + else + errCode = g_vm->loadGame().getCode(); if (errCode == Common::kNoError) { result._kind = RESERVED; -- cgit v1.2.3