aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst_state.cpp
diff options
context:
space:
mode:
authorDavid Fioramonti2018-04-28 06:58:12 -0700
committerBastien Bouclet2018-05-19 17:56:05 +0200
commit719c2b83742495f1619d62088d14f8b63fd50aaa (patch)
tree2125be2de2cbcc9bfe42f87ea467b5bf1fbe488c /engines/mohawk/myst_state.cpp
parent43babaeef8ff385b1f10be1c2fa917085afd2f88 (diff)
downloadscummvm-rg350-719c2b83742495f1619d62088d14f8b63fd50aaa.tar.gz
scummvm-rg350-719c2b83742495f1619d62088d14f8b63fd50aaa.tar.bz2
scummvm-rg350-719c2b83742495f1619d62088d14f8b63fd50aaa.zip
MOHAWK: MYST: Autosave to Slot 0
The game will autosave to slot 0 using the save period given in the scummvm config file or when the user exits using the GMM. Autosaves are only allowed when an autosave is in slot 0 or there is no save in slot 0. This will not override any saves the player has previously put in save slot 0. If there is a save in slot 0 that is not an autosave then there will be no autosaving.
Diffstat (limited to 'engines/mohawk/myst_state.cpp')
-rw-r--r--engines/mohawk/myst_state.cpp44
1 files changed, 36 insertions, 8 deletions
diff --git a/engines/mohawk/myst_state.cpp b/engines/mohawk/myst_state.cpp
index ab98da1f00..5de336ac49 100644
--- a/engines/mohawk/myst_state.cpp
+++ b/engines/mohawk/myst_state.cpp
@@ -41,10 +41,11 @@ MystSaveMetadata::MystSaveMetadata() {
saveHour = 0;
saveMinute = 0;
totalPlayTime = 0;
+ autoSave = false;
}
bool MystSaveMetadata::sync(Common::Serializer &s) {
- static const Common::Serializer::Version kCurrentVersion = 1;
+ static const Common::Serializer::Version kCurrentVersion = 2;
if (!s.syncVersion(kCurrentVersion)) {
return false;
@@ -57,6 +58,7 @@ bool MystSaveMetadata::sync(Common::Serializer &s) {
s.syncAsByte(saveMinute);
s.syncString(saveDescription);
s.syncAsUint32LE(totalPlayTime);
+ s.syncAsByte(autoSave, 2);
return true;
}
@@ -180,12 +182,12 @@ void MystGameState::loadMetadata(int slot) {
delete metadataFile;
}
-bool MystGameState::save(int slot, const Common::String &desc) {
+bool MystGameState::save(int slot, const Common::String &desc, bool autoSave) {
if (!saveState(slot)) {
return false;
}
- updateMetadateForSaving(desc);
+ updateMetadateForSaving(desc, autoSave);
return saveMetadata(slot);
}
@@ -216,7 +218,7 @@ Common::String MystGameState::buildMetadataFilename(int slot) {
return Common::String::format("myst-%03d.mym", slot);
}
-void MystGameState::updateMetadateForSaving(const Common::String &desc) {
+void MystGameState::updateMetadateForSaving(const Common::String &desc, bool autoSave) {
// Update save creation info
TimeDate t;
g_system->getTimeAndDate(t);
@@ -227,6 +229,7 @@ void MystGameState::updateMetadateForSaving(const Common::String &desc) {
_metadata.saveMinute = t.tm_min;
_metadata.saveDescription = desc;
_metadata.totalPlayTime = _vm->getTotalPlayTime();
+ _metadata.autoSave = autoSave;
}
bool MystGameState::saveMetadata(int slot) {
@@ -251,12 +254,36 @@ bool MystGameState::saveMetadata(int slot) {
return true;
}
+bool MystGameState::isAutoSaveAllowed() {
+ // Open autosave slot and see if it an autosave
+ // Autosaving will be enabled if it is an autosave or if there is no save in that slot
+ Common::String filename = buildMetadataFilename(Mohawk::kAutoSaveSlot);
+ Common::ScopedPtr<Common::InSaveFile> metadataFile(g_system->getSavefileManager()->openForLoading(filename));
+ if (!metadataFile) { // There is no save in the autosave slot, enable autosave
+ return true;
+ }
+
+ Common::Serializer m(metadataFile.get(), nullptr);
+
+ // Read the metadata file
+ Mohawk::MystSaveMetadata metadata;
+ if (!metadata.sync(m)) { // the save in the autosave slot is corrupted, enable autosave
+ return true;
+ }
+
+ return metadata.autoSave;
+}
+
SaveStateDescriptor MystGameState::querySaveMetaInfos(int slot) {
// Open the metadata file
Common::String filename = buildMetadataFilename(slot);
Common::InSaveFile *metadataFile = g_system->getSavefileManager()->openForLoading(filename);
+
+ SaveStateDescriptor desc;
+ desc.setWriteProtectedFlag(slot == Mohawk::kAutoSaveSlot);
+
if (!metadataFile) {
- return SaveStateDescriptor();
+ return desc;
}
Common::Serializer m(metadataFile, nullptr);
@@ -265,19 +292,20 @@ SaveStateDescriptor MystGameState::querySaveMetaInfos(int slot) {
Mohawk::MystSaveMetadata metadata;
if (!metadata.sync(m)) {
delete metadataFile;
- return SaveStateDescriptor();
+ return desc;
}
// Set the save description
- SaveStateDescriptor desc;
desc.setDescription(metadata.saveDescription);
desc.setSaveDate(metadata.saveYear, metadata.saveMonth, metadata.saveDay);
desc.setSaveTime(metadata.saveHour, metadata.saveMinute);
desc.setPlayTime(metadata.totalPlayTime);
+ desc.setDeletableFlag(slot != Mohawk::kAutoSaveSlot);
+
Graphics::Surface *thumbnail;
if (!Graphics::loadThumbnail(*metadataFile, thumbnail)) {
delete metadataFile;
- return SaveStateDescriptor();
+ return desc;
}
desc.setThumbnail(thumbnail);