/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "common/savefile.h" #include "common/translation.h" #include "gui/saveload.h" #include "mtropolis/mtropolis.h" #include "mtropolis/runtime.h" namespace MTropolis { CompoundVarSaver::CompoundVarSaver(RuntimeObject *object) : _object(object) { } bool CompoundVarSaver::writeSave(Common::WriteStream *stream) { if (_object == nullptr || !_object->isModifier()) return false; Modifier *modifier = static_cast(_object); Common::SharedPtr saveLoad = modifier->getSaveLoad(); if (!saveLoad) return false; saveLoad->save(modifier, stream); return !stream->err(); } SaveLoadHooks::~SaveLoadHooks() { } void SaveLoadHooks::onLoad(Runtime *runtime, Modifier *saveLoadModifier, Modifier *varModifier) { } void SaveLoadHooks::onSave(Runtime *runtime, Modifier *saveLoadModifier, Modifier *varModifier) { } bool MTropolisEngine::promptSave(ISaveWriter *writer) { Common::String desc; int slot; Common::SharedPtr dialog(new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true)); slot = dialog->runModalWithCurrentTarget(); desc = dialog->getResultString(); if (desc.empty()) { // create our own description for the saved game, the user didnt enter it desc = dialog->createDefaultSaveDescription(slot); } if (slot < 0) return true; Common::String saveFileName = getSaveStateName(slot); Common::SharedPtr out(_saveFileMan->openForSaving(saveFileName, false)); if (!writer->writeSave(out.get()) || out->err()) warning("An error occurred while writing file '%s'", saveFileName.c_str()); getMetaEngine()->appendExtendedSave(out.get(), getTotalPlayTime(), desc, false); return true; } bool MTropolisEngine::promptLoad(ISaveReader *reader) { Common::String desc; int slot; { Common::SharedPtr dialog(new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false)); slot = dialog->runModalWithCurrentTarget(); } if (slot < 0) return true; Common::String saveFileName = getSaveStateName(slot); Common::SharedPtr in(_saveFileMan->openForLoading(saveFileName)); if (!reader->readSave(in.get())) { warning("An error occurred while reading file '%s'", saveFileName.c_str()); return false; } return true; } bool MTropolisEngine::autoSave(ISaveWriter *writer) { const int slot = 0; Common::String saveFileName = getSaveStateName(slot); Common::SharedPtr out(_saveFileMan->openForSaving(saveFileName, false)); if (!writer->writeSave(out.get()) || out->err()) warning("An error occurred while writing file '%s'", saveFileName.c_str()); getMetaEngine()->appendExtendedSave(out.get(), getTotalPlayTime(), "Auto Save", true); return true; } } // End of namespace MTropolis