From 8755ebc0aa9526966bfa5001e0ce811df91166e5 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 24 Aug 2011 10:39:05 +0300 Subject: DRASCULA: Separated the save name syncing code, and added a TODO --- engines/drascula/saveload.cpp | 109 ++++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 47 deletions(-) (limited to 'engines/drascula/saveload.cpp') diff --git a/engines/drascula/saveload.cpp b/engines/drascula/saveload.cpp index 664a082eb4..c8622f3c92 100644 --- a/engines/drascula/saveload.cpp +++ b/engines/drascula/saveload.cpp @@ -26,20 +26,26 @@ namespace Drascula { -bool DrasculaEngine::saveLoadScreen() { - char names[10][23]; - Common::String file; - int n, n2, num_sav = 0, y = 27; +/** + * Loads the save names from the EPA index file. + * + * TODO: We should move the save names in their respective save files and get + * rid of this completely. A good example is the sword1 engine, which also used + * to have an index file for its saves, that has been removed. + * sword1 contains code that converts the old index-based saves into the new + * format without the index file, so we could apply this idea to drascula as + * well. + */ +void DrasculaEngine::loadSaveNames() { Common::InSaveFile *sav; - - clearRoom(); - Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str()); + + // Create and initialize the index file, if it doesn't exist if (!(sav = _saveFileMan->openForLoading(fileEpa))) { Common::OutSaveFile *epa; if (!(epa = _saveFileMan->openForSaving(fileEpa))) error("Can't open %s file", fileEpa.c_str()); - for (n = 0; n < NUM_SAVES; n++) + for (int n = 0; n < NUM_SAVES; n++) epa->writeString("*\n"); epa->finalize(); delete epa; @@ -47,11 +53,47 @@ bool DrasculaEngine::saveLoadScreen() { error("Can't open %s file", fileEpa.c_str()); } } - for (n = 0; n < NUM_SAVES; n++) { - strncpy(names[n], sav->readLine().c_str(), 23); - names[n][22] = '\0'; // make sure the savegame name is 0-terminated + + // Load the index file + for (int n = 0; n < NUM_SAVES; n++) { + strncpy(_saveNames[n], sav->readLine().c_str(), 23); + _saveNames[n][22] = '\0'; // make sure the savegame name is 0-terminated } delete sav; +} + +/** + * Saves the save names into the EPA index file. + * + * TODO: We should move the save names in their respective save files and get + * rid of this completely. A good example is the sword1 engine, which also used + * to have an index file for its saves, that has been removed. + * sword1 contains code that converts the old index-based saves into the new + * format without the index file, so we could apply this idea to drascula as + * well. + */ +void DrasculaEngine::saveSaveNames() { + Common::OutSaveFile *tsav; + Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str()); + + if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { + error("Can't open %s file", fileEpa.c_str()); + } + for (int n = 0; n < NUM_SAVES; n++) { + tsav->writeString(_saveNames[n]); + tsav->writeString("\n"); + } + tsav->finalize(); + delete tsav; +} + +bool DrasculaEngine::saveLoadScreen() { + Common::String file; + int n, n2, num_sav = 0, y = 27; + + clearRoom(); + + loadSaveNames(); loadPic("savescr.alg", bgSurface, HALF_PAL); @@ -66,7 +108,7 @@ bool DrasculaEngine::saveLoadScreen() { y = 27; copyBackground(); for (n = 0; n < NUM_SAVES; n++) { - print_abc(names[n], 116, y); + print_abc(_saveNames[n], 116, y); y = y + 9; } print_abc(select, 117, 15); @@ -79,33 +121,24 @@ bool DrasculaEngine::saveLoadScreen() { delay(50); for (n = 0; n < NUM_SAVES; n++) { if (mouseX > 115 && mouseY > y + (9 * n) && mouseX < 115 + 175 && mouseY < y + 10 + (9 * n)) { - strcpy(select, names[n]); + strcpy(select, _saveNames[n]); if (strcmp(select, "*")) selectionMade = 1; else { enterName(); - strcpy(names[n], select); + strcpy(_saveNames[n], select); if (selectionMade == 1) { file = Common::String::format("%s%02d", _targetName.c_str(), n + 1); saveGame(file.c_str()); - Common::OutSaveFile *tsav; - if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa.c_str()); - } - for (n = 0; n < NUM_SAVES; n++) { - tsav->writeString(names[n]); - tsav->writeString("\n"); - } - tsav->finalize(); - delete tsav; + saveSaveNames(); } } print_abc(select, 117, 15); y = 27; for (n2 = 0; n2 < NUM_SAVES; n2++) { - print_abc(names[n2], 116, y); + print_abc(_saveNames[n2], 116, y); y = y + 9; } if (selectionMade == 1) { @@ -117,27 +150,18 @@ bool DrasculaEngine::saveLoadScreen() { if (mouseX > 117 && mouseY > 15 && mouseX < 295 && mouseY < 24 && selectionMade == 1) { enterName(); - strcpy(names[num_sav], select); + strcpy(_saveNames[num_sav], select); print_abc(select, 117, 15); y = 27; for (n2 = 0; n2 < NUM_SAVES; n2++) { - print_abc(names[n2], 116, y); + print_abc(_saveNames[n2], 116, y); y = y + 9; } if (selectionMade == 1) { file = Common::String::format("%s%02d", _targetName.c_str(), n + 1); saveGame(file.c_str()); - Common::OutSaveFile *tsav; - if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa.c_str()); - } - for (n = 0; n < NUM_SAVES; n++) { - tsav->writeString(names[n]); - tsav->writeString("\n"); - } - tsav->finalize(); - delete tsav; + saveSaveNames(); } } @@ -149,16 +173,7 @@ bool DrasculaEngine::saveLoadScreen() { break; } else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) { saveGame(file.c_str()); - Common::OutSaveFile *tsav; - if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { - error("Can't open %s file", fileEpa.c_str()); - } - for (n = 0; n < NUM_SAVES; n++) { - tsav->writeString(names[n]); - tsav->writeString("\n"); - } - tsav->finalize(); - delete tsav; + saveSaveNames(); } else if (mouseX > 168 && mouseY > 154 && mouseX < 242 && mouseY < 180) break; else if (selectionMade == 0) { -- cgit v1.2.3