diff --git a/engines/hopkins/detection.cpp b/engines/hopkins/detection.cpp index 0be43378627..8724802552c 100644 --- a/engines/hopkins/detection.cpp +++ b/engines/hopkins/detection.cpp @@ -33,6 +33,8 @@ #include "hopkins/hopkins.h" +#define MAX_SAVES 99 + namespace Hopkins { struct HopkinsGameDescription { @@ -113,29 +115,65 @@ SaveStateList HopkinsMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String saveDesc; - Common::String pattern = "hopkins.0??"; + Common::String pattern = Common::String::format("%s.0??", target); filenames = saveFileMan->listSavefiles(pattern); - sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + sort(filenames.begin(), filenames.end()); // Sort to get the files in numerical order + + Hopkins::hopkinsSavegameHeader header; SaveStateList saveList; - // TODO + for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { + const char *ext = strrchr(file->c_str(), '.'); + int slot = ext ? atoi(ext + 1) : -1; + + if (slot >= 0 && slot < MAX_SAVES) { + Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); + + if (in) { + if (Hopkins::SaveLoadManager::readSavegameHeader(in, header)) { + saveList.push_back(SaveStateDescriptor(slot, header.saveName)); + + header.thumbnail->free(); + delete header.thumbnail; + } + + delete in; + } + } + } return saveList; } int HopkinsMetaEngine::getMaximumSaveSlot() const { - return 99; + return MAX_SAVES; } void HopkinsMetaEngine::removeSaveState(const char *target, int slot) const { - Common::String filename = "todo"; - + Common::String filename = Common::String::format("%s.%03d", target, slot); g_system->getSavefileManager()->removeSavefile(filename); } SaveStateDescriptor HopkinsMetaEngine::querySaveMetaInfos(const char *target, int slot) const { - // TODO + Common::String filename = Common::String::format("%s.%03d", target, slot); + Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(filename); + + if (f) { + Hopkins::hopkinsSavegameHeader header; + Hopkins::SaveLoadManager::readSavegameHeader(f, header); + delete f; + + // Create the return descriptor + SaveStateDescriptor desc(slot, header.saveName); + desc.setThumbnail(header.thumbnail); + desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); + desc.setSaveTime(header.saveHour, header.saveMinutes); + desc.setPlayTime(header.totalFrames * GAME_FRAME_TIME); + + return desc; + } + return SaveStateDescriptor(); } diff --git a/engines/hopkins/events.cpp b/engines/hopkins/events.cpp index ea88e1de5af..dbdd0fce811 100644 --- a/engines/hopkins/events.cpp +++ b/engines/hopkins/events.cpp @@ -205,11 +205,11 @@ void EventsManager::checkForNextFrameCounter() { while ((milli - _priorCounterTime) >= 10) { _priorCounterTime += 10; lItCounter += 3; - ++_gameCounter; } // Check for next game frame if ((milli - _priorFrameTime) >= GAME_FRAME_TIME) { + ++_gameCounter; _priorFrameTime = milli; g_system->updateScreen(); diff --git a/engines/hopkins/hopkins.cpp b/engines/hopkins/hopkins.cpp index 6143219283b..32108fb846a 100644 --- a/engines/hopkins/hopkins.cpp +++ b/engines/hopkins/hopkins.cpp @@ -59,6 +59,38 @@ HopkinsEngine::HopkinsEngine(OSystem *syst, const HopkinsGameDescription *gameDe HopkinsEngine::~HopkinsEngine() { } +Common::String HopkinsEngine::generateSaveName(int slot) { + return Common::String::format("%s.%03d", _targetName.c_str(), slot); +} + +/** + * Returns true if it is currently okay to restore a game + */ +bool HopkinsEngine::canLoadGameStateCurrently() { + return !_globals.SORTIE && !_globals.PLAN_FLAG; +} + +/** + * Returns true if it is currently okay to save the game + */ +bool HopkinsEngine::canSaveGameStateCurrently() { + return !_globals.SORTIE && !_globals.PLAN_FLAG; +} + +/** + * Load the savegame at the specified slot index + */ +Common::Error HopkinsEngine::loadGameState(int slot) { + return _saveLoadManager.restore(slot); +} + +/** + * Save the game to the given slot index, and with the given name + */ +Common::Error HopkinsEngine::saveGameState(int slot, const Common::String &desc) { + return _saveLoadManager.save(slot, desc); +} + Common::Error HopkinsEngine::run() { _saveLoadManager.initSaves(); @@ -959,8 +991,4 @@ void HopkinsEngine::PUBQUIT() { _graphicsManager.FADE_OUTW(); } -Common::String HopkinsEngine::generateSaveName(int slot) { - return Common::String::format("%s.%03d", _targetName.c_str(), slot); -} - } // End of namespace Hopkins diff --git a/engines/hopkins/hopkins.h b/engines/hopkins/hopkins.h index 82bc3317b08..706a4efda73 100644 --- a/engines/hopkins/hopkins.h +++ b/engines/hopkins/hopkins.h @@ -126,6 +126,10 @@ public: int getRandomNumber(int maxNumber); Common::String generateSaveName(int slotNumber); + virtual bool canLoadGameStateCurrently(); + virtual bool canSaveGameStateCurrently(); + virtual Common::Error loadGameState(int slot); + virtual Common::Error saveGameState(int slot, const Common::String &desc); /** * Run the introduction sequence