mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-23 20:51:14 +00:00
MOHAWK: Switch Riven saves to a slot based naming scheme
Existing saves are compatible but must be renamed to riven-###.rvn
This commit is contained in:
parent
f78bb08b18
commit
504ffd2aba
@ -199,6 +199,7 @@ public:
|
||||
virtual bool hasFeature(MetaEngineFeature f) const;
|
||||
virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
|
||||
virtual SaveStateList listSaves(const char *target) const;
|
||||
SaveStateList listSavesForPrefix(const char *prefix, const char *extension) const;
|
||||
virtual int getMaximumSaveSlot() const { return 999; }
|
||||
virtual void removeSaveState(const char *target, int slot) const;
|
||||
virtual SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
|
||||
@ -215,41 +216,55 @@ bool MohawkMetaEngine::hasFeature(MetaEngineFeature f) const {
|
||||
|| (f == kSavesSupportPlayTime);
|
||||
}
|
||||
|
||||
SaveStateList MohawkMetaEngine::listSavesForPrefix(const char *prefix, const char *extension) const {
|
||||
Common::String pattern = Common::String::format("%s-###.%s", prefix, extension);
|
||||
Common::StringArray filenames = g_system->getSavefileManager()->listSavefiles(pattern);
|
||||
size_t prefixLen = strlen(prefix);
|
||||
|
||||
SaveStateList saveList;
|
||||
for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
|
||||
// Extract the slot number from the filename
|
||||
char slot[4];
|
||||
slot[0] = (*filename)[prefixLen + 1];
|
||||
slot[1] = (*filename)[prefixLen + 2];
|
||||
slot[2] = (*filename)[prefixLen + 3];
|
||||
slot[3] = '\0';
|
||||
|
||||
int slotNum = atoi(slot);
|
||||
|
||||
saveList.push_back(SaveStateDescriptor(slotNum, ""));
|
||||
}
|
||||
|
||||
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
|
||||
|
||||
return saveList;
|
||||
}
|
||||
|
||||
SaveStateList MohawkMetaEngine::listSaves(const char *target) const {
|
||||
Common::StringArray filenames;
|
||||
SaveStateList saveList;
|
||||
|
||||
// Loading games is only supported in Myst/Riven currently.
|
||||
#ifdef ENABLE_MYST
|
||||
if (strstr(target, "myst")) {
|
||||
filenames = g_system->getSavefileManager()->listSavefiles("myst-###.mys");
|
||||
size_t prefixLen = sizeof("myst") - 1;
|
||||
|
||||
for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
|
||||
// Extract the slot number from the filename
|
||||
char slot[4];
|
||||
slot[0] = (*filename)[prefixLen + 1];
|
||||
slot[1] = (*filename)[prefixLen + 2];
|
||||
slot[2] = (*filename)[prefixLen + 3];
|
||||
slot[3] = '\0';
|
||||
|
||||
int slotNum = atoi(slot);
|
||||
saveList = listSavesForPrefix("myst", "mys");
|
||||
|
||||
for (SaveStateList::iterator save = saveList.begin(); save != saveList.end(); ++save) {
|
||||
// Read the description from the save
|
||||
Common::String description = Mohawk::MystGameState::querySaveDescription(slotNum);
|
||||
saveList.push_back(SaveStateDescriptor(slotNum, description));
|
||||
int slot = save->getSaveSlot();
|
||||
Common::String description = Mohawk::MystGameState::querySaveDescription(slot);
|
||||
save->setDescription(description);
|
||||
}
|
||||
|
||||
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_RIVEN
|
||||
if (strstr(target, "riven")) {
|
||||
filenames = g_system->getSavefileManager()->listSavefiles("*.rvn");
|
||||
saveList = listSavesForPrefix("riven", "rvn");
|
||||
|
||||
for (uint32 i = 0; i < filenames.size(); i++) {
|
||||
Common::String description = Mohawk::RivenSaveLoad::querySaveDescription(filenames[i]);
|
||||
saveList.push_back(SaveStateDescriptor(i, description));
|
||||
for (SaveStateList::iterator save = saveList.begin(); save != saveList.end(); ++save) {
|
||||
// Read the description from the save
|
||||
int slot = save->getSaveSlot();
|
||||
Common::String description = Mohawk::RivenSaveLoad::querySaveDescription(slot);
|
||||
save->setDescription(description);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -263,12 +278,13 @@ void MohawkMetaEngine::removeSaveState(const char *target, int slot) const {
|
||||
#ifdef ENABLE_MYST
|
||||
if (strstr(target, "myst")) {
|
||||
Mohawk::MystGameState::deleteSave(slot);
|
||||
} else
|
||||
#endif
|
||||
if (strstr(target, "riven")) {
|
||||
Common::StringArray filenames = g_system->getSavefileManager()->listSavefiles("*.rvn");
|
||||
g_system->getSavefileManager()->removeSavefile(filenames[slot].c_str());
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_RIVEN
|
||||
if (strstr(target, "riven")) {
|
||||
Mohawk::RivenSaveLoad::deleteSave(slot);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SaveStateDescriptor MohawkMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
|
||||
@ -279,8 +295,7 @@ SaveStateDescriptor MohawkMetaEngine::querySaveMetaInfos(const char *target, int
|
||||
#endif
|
||||
#ifdef ENABLE_RIVEN
|
||||
if (strstr(target, "riven")) {
|
||||
Common::StringArray filenames = g_system->getSavefileManager()->listSavefiles("*.rvn");
|
||||
return Mohawk::RivenSaveLoad::querySaveMetaInfos(filenames[slot].c_str());
|
||||
return Mohawk::RivenSaveLoad::querySaveMetaInfos(slot);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
@ -176,13 +176,10 @@ Common::Error MohawkEngine_Riven::run() {
|
||||
changeToCard(6);
|
||||
} else if (ConfMan.hasKey("save_slot")) {
|
||||
// Load game from launcher/command line if requested
|
||||
uint32 gameToLoad = ConfMan.getInt("save_slot");
|
||||
Common::StringArray savedGamesList = _saveLoad->generateSaveGameList();
|
||||
if (gameToLoad > savedGamesList.size())
|
||||
error ("Could not find saved game");
|
||||
int gameToLoad = ConfMan.getInt("save_slot");
|
||||
|
||||
// Attempt to load the game. On failure, just send us to the main menu.
|
||||
if (_saveLoad->loadGame(savedGamesList[gameToLoad]).getCode() != Common::kNoError) {
|
||||
if (_saveLoad->loadGame(gameToLoad).getCode() != Common::kNoError) {
|
||||
changeToStack(kStackAspit);
|
||||
changeToCard(1);
|
||||
}
|
||||
@ -734,16 +731,11 @@ void MohawkEngine_Riven::runLoadDialog() {
|
||||
}
|
||||
|
||||
Common::Error MohawkEngine_Riven::loadGameState(int slot) {
|
||||
return _saveLoad->loadGame(_saveLoad->generateSaveGameList()[slot]);
|
||||
return _saveLoad->loadGame(slot);
|
||||
}
|
||||
|
||||
Common::Error MohawkEngine_Riven::saveGameState(int slot, const Common::String &desc) {
|
||||
Common::StringArray saveList = _saveLoad->generateSaveGameList();
|
||||
|
||||
if ((uint)slot < saveList.size())
|
||||
_saveLoad->deleteSave(saveList[slot]);
|
||||
|
||||
return _saveLoad->saveGame(desc);
|
||||
return _saveLoad->saveGame(slot, desc);
|
||||
}
|
||||
|
||||
Common::String MohawkEngine_Riven::getStackName(uint16 stack) const {
|
||||
|
@ -62,11 +62,12 @@ RivenSaveLoad::RivenSaveLoad(MohawkEngine_Riven *vm, Common::SaveFileManager *sa
|
||||
RivenSaveLoad::~RivenSaveLoad() {
|
||||
}
|
||||
|
||||
Common::StringArray RivenSaveLoad::generateSaveGameList() {
|
||||
return _saveFileMan->listSavefiles("*.rvn");
|
||||
Common::String RivenSaveLoad::buildSaveFilename(const int slot) {
|
||||
return Common::String::format("riven-%03d.rvn", slot);
|
||||
}
|
||||
|
||||
Common::String RivenSaveLoad::querySaveDescription(const Common::String &filename) {
|
||||
Common::String RivenSaveLoad::querySaveDescription(const int slot) {
|
||||
Common::String filename = buildSaveFilename(slot);
|
||||
Common::InSaveFile *loadFile = g_system->getSavefileManager()->openForLoading(filename);
|
||||
if (!loadFile) {
|
||||
return "";
|
||||
@ -99,7 +100,8 @@ Common::String RivenSaveLoad::querySaveDescription(const Common::String &filenam
|
||||
return metadata.saveDescription;
|
||||
}
|
||||
|
||||
SaveStateDescriptor RivenSaveLoad::querySaveMetaInfos(const Common::String &filename) {
|
||||
SaveStateDescriptor RivenSaveLoad::querySaveMetaInfos(const int slot) {
|
||||
Common::String filename = buildSaveFilename(slot);
|
||||
Common::InSaveFile *loadFile = g_system->getSavefileManager()->openForLoading(filename);
|
||||
if (!loadFile) {
|
||||
return SaveStateDescriptor();
|
||||
@ -151,10 +153,11 @@ SaveStateDescriptor RivenSaveLoad::querySaveMetaInfos(const Common::String &file
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
Common::Error RivenSaveLoad::loadGame(Common::String filename) {
|
||||
Common::Error RivenSaveLoad::loadGame(const int slot) {
|
||||
if (_vm->getFeatures() & GF_DEMO) // Don't load games in the demo
|
||||
return Common::kNoError;
|
||||
|
||||
Common::String filename = buildSaveFilename(slot);
|
||||
Common::InSaveFile *loadFile = _saveFileMan->openForLoading(filename);
|
||||
if (!loadFile)
|
||||
return Common::kReadingFailed;
|
||||
@ -388,7 +391,7 @@ Common::MemoryWriteStreamDynamic *RivenSaveLoad::genMETASection(const Common::St
|
||||
return stream;
|
||||
}
|
||||
|
||||
Common::Error RivenSaveLoad::saveGame(Common::String filename) {
|
||||
Common::Error RivenSaveLoad::saveGame(const int slot, const Common::String &description) {
|
||||
// NOTE: This code is designed to only output a Mohawk archive
|
||||
// for a Riven saved game. It's hardcoded to do this because
|
||||
// (as of right now) this is the only place in the engine
|
||||
@ -396,9 +399,7 @@ Common::Error RivenSaveLoad::saveGame(Common::String filename) {
|
||||
// games need this, we should think about coming up with some
|
||||
// more common way of outputting resources to an archive.
|
||||
|
||||
// Make sure we have the right extension
|
||||
if (!filename.matchString("*.rvn", true))
|
||||
filename += ".rvn";
|
||||
Common::String filename = buildSaveFilename(slot);
|
||||
|
||||
// Convert class variables to variable numbers
|
||||
_vm->_vars["currentstackid"] = _vm->getCurStack();
|
||||
@ -410,7 +411,7 @@ Common::Error RivenSaveLoad::saveGame(Common::String filename) {
|
||||
|
||||
debug (0, "Saving game to \'%s\'", filename.c_str());
|
||||
|
||||
Common::MemoryWriteStreamDynamic *metaSection = genMETASection(filename);
|
||||
Common::MemoryWriteStreamDynamic *metaSection = genMETASection(description);
|
||||
Common::MemoryWriteStreamDynamic *nameSection = genNAMESection();
|
||||
Common::MemoryWriteStreamDynamic *thmbSection = genTHMBSection();
|
||||
Common::MemoryWriteStreamDynamic *varsSection = genVARSSection();
|
||||
@ -576,9 +577,11 @@ Common::Error RivenSaveLoad::saveGame(Common::String filename) {
|
||||
return Common::kNoError;
|
||||
}
|
||||
|
||||
void RivenSaveLoad::deleteSave(Common::String saveName) {
|
||||
debug (0, "Deleting save file \'%s\'", saveName.c_str());
|
||||
_saveFileMan->removeSavefile(saveName);
|
||||
void RivenSaveLoad::deleteSave(const int slot) {
|
||||
Common::String filename = buildSaveFilename(slot);
|
||||
|
||||
debug (0, "Deleting save file \'%s\'", filename.c_str());
|
||||
g_system->getSavefileManager()->removeSavefile(filename);
|
||||
}
|
||||
|
||||
} // End of namespace Mohawk
|
||||
|
@ -60,18 +60,19 @@ public:
|
||||
RivenSaveLoad(MohawkEngine_Riven*, Common::SaveFileManager*);
|
||||
~RivenSaveLoad();
|
||||
|
||||
Common::StringArray generateSaveGameList();
|
||||
Common::Error loadGame(Common::String);
|
||||
Common::Error saveGame(Common::String);
|
||||
void deleteSave(Common::String);
|
||||
Common::Error loadGame(const int slot);
|
||||
Common::Error saveGame(const int slot, const Common::String &description);
|
||||
static void deleteSave(const int slot);
|
||||
|
||||
static SaveStateDescriptor querySaveMetaInfos(const Common::String &filename);
|
||||
static Common::String querySaveDescription(const Common::String &filename);
|
||||
static SaveStateDescriptor querySaveMetaInfos(const int slot);
|
||||
static Common::String querySaveDescription(const int slot);
|
||||
|
||||
private:
|
||||
MohawkEngine_Riven *_vm;
|
||||
Common::SaveFileManager *_saveFileMan;
|
||||
|
||||
static Common::String buildSaveFilename(const int slot);
|
||||
|
||||
Common::MemoryWriteStreamDynamic *genNAMESection();
|
||||
Common::MemoryWriteStreamDynamic *genMETASection(const Common::String &desc) const;
|
||||
Common::MemoryWriteStreamDynamic *genTHMBSection() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user