diff options
author | Filippos Karapetis | 2011-08-24 10:39:05 +0300 |
---|---|---|
committer | Filippos Karapetis | 2011-08-24 10:39:05 +0300 |
commit | 8755ebc0aa9526966bfa5001e0ce811df91166e5 (patch) | |
tree | 4ef913e3fadc6b539b004995d6138894aec71129 | |
parent | d13a9270a74309ffb65eee24496184b0fdc83239 (diff) | |
download | scummvm-rg350-8755ebc0aa9526966bfa5001e0ce811df91166e5.tar.gz scummvm-rg350-8755ebc0aa9526966bfa5001e0ce811df91166e5.tar.bz2 scummvm-rg350-8755ebc0aa9526966bfa5001e0ce811df91166e5.zip |
DRASCULA: Separated the save name syncing code, and added a TODO
-rw-r--r-- | engines/drascula/drascula.h | 3 | ||||
-rw-r--r-- | engines/drascula/saveload.cpp | 109 |
2 files changed, 65 insertions, 47 deletions
diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h index 5ec4684723..6f98c50fdc 100644 --- a/engines/drascula/drascula.h +++ b/engines/drascula/drascula.h @@ -495,6 +495,8 @@ public: void updateVolume(Audio::Mixer::SoundType soundType, int prevVolume); void volumeControls(); bool saveLoadScreen(); + void loadSaveNames(); + void saveSaveNames(); void print_abc(const char *, int, int); void delay(int ms); bool confirmExit(); @@ -775,6 +777,7 @@ private: RoomUpdate *_roomPreUpdates, *_roomUpdates; RoomTalkAction *_roomActions; TalkSequenceCommand *_talkSequences; + char _saveNames[10][23]; char **loadTexts(Common::File &in); void freeTexts(char **ptr); 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) { |