diff options
author | Paul Gilbert | 2013-07-13 19:10:03 -0400 |
---|---|---|
committer | Paul Gilbert | 2013-07-13 19:10:03 -0400 |
commit | e14278eb583253504e85c3f4db9d56d3b3d945fb (patch) | |
tree | ab366756453b737742d95d470a93264424c606a0 /engines/mortevielle | |
parent | 364cfaf9d264045d752280a7b3fe3d3ca3e42aa4 (diff) | |
download | scummvm-rg350-e14278eb583253504e85c3f4db9d56d3b3d945fb.tar.gz scummvm-rg350-e14278eb583253504e85c3f4db9d56d3b3d945fb.tar.bz2 scummvm-rg350-e14278eb583253504e85c3f4db9d56d3b3d945fb.zip |
MORTEVIELLE: Changed savegames to use the game target to generate filenames
Diffstat (limited to 'engines/mortevielle')
-rw-r--r-- | engines/mortevielle/detection.cpp | 3 | ||||
-rw-r--r-- | engines/mortevielle/mortevielle.cpp | 15 | ||||
-rw-r--r-- | engines/mortevielle/mortevielle.h | 2 | ||||
-rw-r--r-- | engines/mortevielle/saveload.cpp | 42 | ||||
-rw-r--r-- | engines/mortevielle/saveload.h | 15 |
5 files changed, 54 insertions, 23 deletions
diff --git a/engines/mortevielle/detection.cpp b/engines/mortevielle/detection.cpp index 9fe0927706..28cbc77b8b 100644 --- a/engines/mortevielle/detection.cpp +++ b/engines/mortevielle/detection.cpp @@ -89,7 +89,8 @@ SaveStateList MortevielleMetaEngine::listSaves(const char *target) const { } SaveStateDescriptor MortevielleMetaEngine::querySaveMetaInfos(const char *target, int slot) const { - return Mortevielle::SavegameManager::querySaveMetaInfos(slot); + Common::String filename = Mortevielle::MortevielleEngine::generateSaveFilename(target, slot); + return Mortevielle::SavegameManager::querySaveMetaInfos(filename); } diff --git a/engines/mortevielle/mortevielle.cpp b/engines/mortevielle/mortevielle.cpp index 2734f8cc93..8ed6751b50 100644 --- a/engines/mortevielle/mortevielle.cpp +++ b/engines/mortevielle/mortevielle.cpp @@ -55,6 +55,7 @@ MortevielleEngine::MortevielleEngine(OSystem *system, const ADGameDescription *g _text.setParent(this); _soundManager.setParent(this); _speechManager.setParent(this); + _savegameManager.setParent(this); _lastGameFrame = 0; _mouseClick = false; @@ -147,6 +148,18 @@ Common::Error MortevielleEngine::saveGameState(int slot, const Common::String &d } /** + * Support method that generates a savegame name + * @param slot Slot number + */ +Common::String MortevielleEngine::generateSaveFilename(const Common::String &target, int slot) { + if (slot == 0) + // Initial game state loaded when the game starts + return "sav0.mor"; + + return Common::String::format("%s.%03d", target.c_str(), slot); +} + +/** * Initialise the game state */ Common::ErrorCode MortevielleEngine::initialise() { @@ -335,7 +348,7 @@ Common::Error MortevielleEngine::run() { // Either load the initial game state savegame, or the specified savegame number adzon(); - _savegameManager.loadSavegame(loadSlot); + _savegameManager.loadSavegame(generateSaveFilename(loadSlot)); // Run the main game loop mainGame(); diff --git a/engines/mortevielle/mortevielle.h b/engines/mortevielle/mortevielle.h index dcb61a6057..5255865cc5 100644 --- a/engines/mortevielle/mortevielle.h +++ b/engines/mortevielle/mortevielle.h @@ -498,6 +498,8 @@ public: virtual Common::Error run(); uint32 getGameFlags() const; Common::Language getLanguage() const; + static Common::String generateSaveFilename(const Common::String &target, int slot); + Common::String generateSaveFilename(int slot) { return generateSaveFilename(_targetName, slot); } int getChar(); bool keyPressed(); diff --git a/engines/mortevielle/saveload.cpp b/engines/mortevielle/saveload.cpp index 093f22e9cf..382fd14277 100644 --- a/engines/mortevielle/saveload.cpp +++ b/engines/mortevielle/saveload.cpp @@ -36,8 +36,8 @@ namespace Mortevielle { static const char SAVEGAME_ID[4] = { 'M', 'O', 'R', 'T' }; -Common::String SavegameManager::generateSaveName(int slotNumber) { - return Common::String::format("sav%d.mor", slotNumber); +void SavegameManager::setParent(MortevielleEngine *vm) { + _vm = vm; } /** @@ -71,14 +71,10 @@ void SavegameManager::sync_save(Common::Serializer &sz) { * Inner code for loading a saved game * @remarks Originally called 'takesav' */ -void SavegameManager::loadSavegame(int n) { - // -- Load the file - Common::String filename = generateSaveName(n); - +void SavegameManager::loadSavegame(const Common::String &filename) { // Try loading first from the save area Common::SeekableReadStream *stream = g_system->getSavefileManager()->openForLoading(filename); - // If not present, try loading from the program folder Common::File f; if (stream == NULL) { if (!f.open(filename)) @@ -115,10 +111,10 @@ void SavegameManager::loadSavegame(int n) { /** * Load a saved game */ -Common::Error SavegameManager::loadGame(int n) { +Common::Error SavegameManager::loadGame(const Common::String &filename) { g_vm->_mouse.hideMouse(); g_vm->displayEmptyHand(); - loadSavegame(n); + loadSavegame(filename); /* Initialization */ g_vm->charToHour(); @@ -144,7 +140,7 @@ Common::Error SavegameManager::saveGame(int n, const Common::String &saveName) { if (g_vm->_saveStruct._currPlace == ROOM26) g_vm->_saveStruct._currPlace = LANDING; - Common::String filename = generateSaveName(n); + Common::String filename = _vm->generateSaveFilename(n); f = g_system->getSavefileManager()->openForSaving(filename); // Write out the savegame header @@ -168,6 +164,14 @@ Common::Error SavegameManager::saveGame(int n, const Common::String &saveName) { return Common::kNoError; } +Common::Error SavegameManager::loadGame(int slot) { + return loadGame(_vm->generateSaveFilename(slot)); +} + +Common::Error SavegameManager::saveGame(int slot) { + return saveGame(slot, _vm->generateSaveFilename(slot)); +} + void SavegameManager::writeSavegameHeader(Common::OutSaveFile *out, const Common::String &saveName) { // Write out a savegame header out->writeByte(SAVEGAME_VERSION); @@ -226,8 +230,10 @@ bool SavegameManager::readSavegameHeader(Common::InSaveFile *in, SavegameHeader return true; } -SaveStateList SavegameManager::listSaves(const char *target) { - Common::String pattern = "sav*.mor"; +SaveStateList SavegameManager::listSaves(const Common::String &target) { + Common::String pattern = target; + pattern += ".???"; + Common::StringArray files = g_system->getSavefileManager()->listSavefiles(pattern); sort(files.begin(), files.end()); // Sort (hopefully ensuring we are sorted numerically..) @@ -235,7 +241,7 @@ SaveStateList SavegameManager::listSaves(const char *target) { for (Common::StringArray::const_iterator file = files.begin(); file != files.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot const Common::String &fname = *file; - int slotNumber = atoi(fname.c_str() + 3); + int slotNumber = atoi(fname.c_str() + fname.size() - 3); Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(fname); if (in) { @@ -274,11 +280,15 @@ SaveStateList SavegameManager::listSaves(const char *target) { return saveList; } -SaveStateDescriptor SavegameManager::querySaveMetaInfos(int slot) { - Common::String fileName = Mortevielle::SavegameManager::generateSaveName(slot); +SaveStateDescriptor SavegameManager::querySaveMetaInfos(const Common::String &fileName) { Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName); if (f) { + // Get the slot number + int slot = 1; + if (fileName.size() > 4 && fileName[fileName.size() - 4] == '.') + slot = atoi(fileName.c_str() + fileName.size() - 3); + // Check to see if it's a ScummVM savegame or not char buffer[4]; f->read(buffer, 4); @@ -289,7 +299,7 @@ SaveStateDescriptor SavegameManager::querySaveMetaInfos(int slot) { // Original savegame perhaps? delete f; - SaveStateDescriptor desc(slot, Common::String::format("Savegame #%d", slot)); + SaveStateDescriptor desc(slot, Common::String::format("Savegame - %s", slot)); desc.setDeletableFlag(slot != 0); desc.setWriteProtectedFlag(slot == 0); return desc; diff --git a/engines/mortevielle/saveload.h b/engines/mortevielle/saveload.h index 140b039b51..6613b62ac7 100644 --- a/engines/mortevielle/saveload.h +++ b/engines/mortevielle/saveload.h @@ -47,21 +47,26 @@ struct SavegameHeader { int totalFrames; }; +class MortevielleEngine; + class SavegameManager { private: + MortevielleEngine *_vm; byte _tabdonSaveBuffer[391]; void sync_save(Common::Serializer &sz); public: - void loadSavegame(int n); - Common::Error loadGame(int n); + void setParent(MortevielleEngine *vm); + void loadSavegame(const Common::String &filename); + Common::Error loadGame(const Common::String &filename); Common::Error saveGame(int n, const Common::String &saveName); + Common::Error loadGame(int slot); + Common::Error saveGame(int slot); void writeSavegameHeader(Common::OutSaveFile *out, const Common::String &saveName); static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); - static Common::String generateSaveName(int slotNumber); - static SaveStateList listSaves(const char *target); - static SaveStateDescriptor querySaveMetaInfos(int slot); + static SaveStateList listSaves(const Common::String &target); + static SaveStateDescriptor querySaveMetaInfos(const Common::String &fileName); }; } // End of namespace Mortevielle |