diff options
author | Paul Gilbert | 2019-10-09 21:50:30 -0700 |
---|---|---|
committer | Paul Gilbert | 2019-10-11 18:43:34 -0700 |
commit | e779ebce4f5b68989708679fed13d06cad6197b2 (patch) | |
tree | f9ecad0b157244e890de7058b20439d5073a6bcd /engines/glk/jacl | |
parent | d41d11f390200c09b465d8b4147bf59e26799101 (diff) | |
download | scummvm-rg350-e779ebce4f5b68989708679fed13d06cad6197b2.tar.gz scummvm-rg350-e779ebce4f5b68989708679fed13d06cad6197b2.tar.bz2 scummvm-rg350-e779ebce4f5b68989708679fed13d06cad6197b2.zip |
GLK: JACL: Implement loading saves from the launcher
Diffstat (limited to 'engines/glk/jacl')
-rw-r--r-- | engines/glk/jacl/interpreter.cpp | 2 | ||||
-rw-r--r-- | engines/glk/jacl/jacl.cpp | 12 | ||||
-rw-r--r-- | engines/glk/jacl/jacl.h | 5 | ||||
-rw-r--r-- | engines/glk/jacl/jacl_main.cpp | 118 |
4 files changed, 84 insertions, 53 deletions
diff --git a/engines/glk/jacl/interpreter.cpp b/engines/glk/jacl/interpreter.cpp index 1203f65840..38c618a253 100644 --- a/engines/glk/jacl/interpreter.cpp +++ b/engines/glk/jacl/interpreter.cpp @@ -1094,7 +1094,7 @@ int execute(const char *funcname) { noproprun(); return (exit_function(TRUE)); } else { - if (g_vm->glk_image_draw(mainwin, (glui32) value_of(word[1], TRUE), imagealign_InlineDown, 0) == 0) { + if (!g_vm->loadingSavegame() && g_vm->glk_image_draw(mainwin, (glui32) value_of(word[1], TRUE), imagealign_InlineDown, 0) == 0) { sprintf(error_buffer, "Unable to draw image: %ld", value_of(word[1], FALSE)); log_error(error_buffer, PLUS_STDERR); } diff --git a/engines/glk/jacl/jacl.cpp b/engines/glk/jacl/jacl.cpp index daeffe9ab9..d299059e3a 100644 --- a/engines/glk/jacl/jacl.cpp +++ b/engines/glk/jacl/jacl.cpp @@ -22,6 +22,7 @@ #include "glk/jacl/jacl.h" #include "glk/jacl/prototypes.h" +#include "glk/jacl/types.h" #include "common/config-manager.h" namespace Glk { @@ -68,5 +69,16 @@ Common::Error JACL::writeGameData(Common::WriteStream *ws) { return success ? Common::kNoError : Common::kWritingFailed; } +bool JACL::loadLauncherSavegame() { + int saveSlot = _saveSlot; + _saveSlot = -1; + + if (loadGameState(saveSlot).getCode() == Common::kNoError) + return true; + + write_text(cstring_resolve("CANT_RESTORE")->value); + return false; +} + } // End of namespace JACL } // End of namespace Glk diff --git a/engines/glk/jacl/jacl.h b/engines/glk/jacl/jacl.h index b49b121b5d..958238d7c7 100644 --- a/engines/glk/jacl/jacl.h +++ b/engines/glk/jacl/jacl.h @@ -80,6 +80,11 @@ public: bool loadingSavegame() const { return _saveSlot != -1; } + + /** + * Does the actual loading of the savegame from a luancher + */ + bool loadLauncherSavegame(); }; extern JACL *g_vm; diff --git a/engines/glk/jacl/jacl_main.cpp b/engines/glk/jacl/jacl_main.cpp index 9059482ff1..1b6b34bf6b 100644 --- a/engines/glk/jacl/jacl_main.cpp +++ b/engines/glk/jacl/jacl_main.cpp @@ -262,6 +262,7 @@ void glk_main() { return; } + /* DUMMY RETRIEVE OF 'HERE' FOR TESTING OF GAME STATE */ get_here(); @@ -289,70 +290,82 @@ void glk_main() { jacl_set_window(inputwin); } - /* OUTPUT THE CUSTOM COMMAND PROMPT */ - write_text(string_resolve("command_prompt")->value); + // If loading a savegame from the launcher, do it now + if (g_vm->loadingSavegame()) { + // Load the game + if (g_vm->loadLauncherSavegame()) { + // Do a look action + const uint32 LOOK[5] = { 'l', 'o', 'o', 'k', 0 }; + Common::copy(LOOK, LOOK + 5, command_buffer_uni); + ev.val1 = 4; + } else { + continue; + } + } else { + /* OUTPUT THE CUSTOM COMMAND PROMPT */ + write_text(string_resolve("command_prompt")->value); #ifdef NOUNICODE - g_vm->glk_request_line_event(inputwin, command_buffer, 255, 0); + g_vm->glk_request_line_event(inputwin, command_buffer, 255, 0); #else - g_vm->glk_request_line_event_uni(inputwin, command_buffer_uni, 255, 0); + g_vm->glk_request_line_event_uni(inputwin, command_buffer_uni, 255, 0); #endif - jacl_set_window(inputwin); + jacl_set_window(inputwin); - gotline = FALSE; + gotline = FALSE; + + while (!gotline) { + /* GRAB AN EVENT. */ + g_vm->glk_select(&ev); + if (g_vm->shouldQuit()) + return; + + switch (ev.type) { + + case evtype_LineInput: + if (ev.window == inputwin) { + gotline = TRUE; + jacl_set_window(mainwin); + /* REALLY THE EVENT CAN *ONLY* BE FROM MAINWIN, + * BECAUSE WE NEVER REQUEST LINE INPUT FROM THE + * STATUS WINDOW. BUT WE DO A PARANOIA TEST, + * BECAUSE COMMANDBUF IS ONLY FILLED IF THE LINE + * EVENT COMES FROM THE MAINWIN REQUEST. IF THE + * LINE EVENT COMES FROM ANYWHERE ELSE, WE IGNORE + * IT. */ + } + break; - while (!gotline) { - /* GRAB AN EVENT. */ - g_vm->glk_select(&ev); - if (g_vm->shouldQuit()) - return; + case evtype_SoundNotify: + /* A SOUND HAS FINISHED PLAYING CALL +sound_finished + * WITH THE RESOUCE NUMBER AS THE FIRST ARGUMENT + * AND THE CHANNEL NUMBER AS THE SECOND ARGUMENT */ + sprintf(temp_buffer, "+sound_finished<%d<%d", (int) ev.val1, (int) ev.val2 - 1); + execute(temp_buffer); + break; - switch (ev.type) { + case evtype_Timer: + /* A TIMER EVENT IS TRIGGERED PERIODICALLY IF THE GAME + * REQUESTS THEM. THIS SIMPLY EXECUTES THE FUNCTION + * +timer WHICH IS LIKE +eachturn EXCEPT IT DOESN'T + * WAIT FOR THE PLAYER TO TYPE A COMMAND */ - case evtype_LineInput: - if (ev.window == inputwin) { - gotline = TRUE; jacl_set_window(mainwin); - /* REALLY THE EVENT CAN *ONLY* BE FROM MAINWIN, - * BECAUSE WE NEVER REQUEST LINE INPUT FROM THE - * STATUS WINDOW. BUT WE DO A PARANOIA TEST, - * BECAUSE COMMANDBUF IS ONLY FILLED IF THE LINE - * EVENT COMES FROM THE MAINWIN REQUEST. IF THE - * LINE EVENT COMES FROM ANYWHERE ELSE, WE IGNORE - * IT. */ - } - break; - - case evtype_SoundNotify: - /* A SOUND HAS FINISHED PLAYING CALL +sound_finished - * WITH THE RESOUCE NUMBER AS THE FIRST ARGUMENT - * AND THE CHANNEL NUMBER AS THE SECOND ARGUMENT */ - sprintf(temp_buffer, "+sound_finished<%d<%d", (int) ev.val1, (int) ev.val2 - 1); - execute(temp_buffer); - break; - - case evtype_Timer: - /* A TIMER EVENT IS TRIGGERED PERIODICALLY IF THE GAME - * REQUESTS THEM. THIS SIMPLY EXECUTES THE FUNCTION - * +timer WHICH IS LIKE +eachturn EXCEPT IT DOESN'T - * WAIT FOR THE PLAYER TO TYPE A COMMAND */ - - jacl_set_window(mainwin); - execute("+timer"); - break; + execute("+timer"); + break; - case evtype_Arrange: - /* WINDOWS HAVE CHANGED SIZE, SO WE HAVE TO REDRAW THE - * STATUS WINDOW. */ - status_line(); - break; + case evtype_Arrange: + /* WINDOWS HAVE CHANGED SIZE, SO WE HAVE TO REDRAW THE + * STATUS WINDOW. */ + status_line(); + break; - default: - break; + default: + break; + } } } - // THE PLAYER'S INPUT WILL BE UTF-32. CONVERT IT TO UTF-8 AND NULL TERMINATE IT #ifndef NOUNICODE convert_to_utf8(command_buffer_uni, ev.val1); @@ -707,8 +720,9 @@ void restore_game_state() { } void write_text(const char *string_buffer) { - int index, - length; + int index, length; + if (g_vm->loadingSavegame()) + return; if (!strcmp(string_buffer, "tilde")) { g_vm->glk_put_string("~"); |