ASYLUM: append metadata to the saves made via the game menu

This commit is contained in:
alxpnv 2021-09-17 13:06:55 +03:00
parent 3c4159cfe1
commit b49f9e755b
10 changed files with 53 additions and 42 deletions

View File

@ -660,7 +660,7 @@ Common::Error AsylumEngine::saveGameState(int slot, const Common::String &desc,
savegame()->loadList();
savegame()->setIndex(slot);
savegame()->setName(slot, desc);
savegame()->save(true);
savegame()->save();
return Common::kNoError;
}

View File

@ -194,6 +194,7 @@ public:
bool isAltDemo() { return Common::File::exists("asylum.dat"); }
Common::Language getLanguage() { return _gameDescription->language; }
Common::String getMoviesFileName() { return Common::String::format("%s.movies", _targetName.c_str()); }
bool isMenuVisible() { return _handler == (EventHandler *)_menu; }
// Save/Load
bool canLoadGameStateCurrently();

View File

@ -31,8 +31,12 @@
#include "engines/advancedDetector.h"
#include "graphics/scaler.h"
#include "asylum/system/savegame.h"
#include "asylum/views/scene.h"
#include "asylum/asylum.h"
#include "asylum/shared.h"
@ -47,7 +51,8 @@ public:
}
int getMaximumSaveSlot() const override { return 25; }
SaveStateList listSaves(const char *target) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
void getSavegameThumbnail(Graphics::Surface &thumb) override;
Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const override;
Common::KeymapArray initKeymaps(const char *target) const override;
const Common::AchievementDescriptionList *getAchievementDescriptionList() const override;
@ -60,36 +65,31 @@ bool Asylum::AsylumEngine::hasFeature(EngineFeature f) const {
(f == kSupportsSavingDuringRuntime);
}
SaveStateList AsylumMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String pattern(getSavegameFilePattern(target));
void AsylumMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
Asylum::AsylumEngine *engine = (Asylum::AsylumEngine *)g_engine;
filenames = saveFileMan->listSavefiles(pattern);
if (engine->isMenuVisible()) {
const Graphics::Surface &savedScreen = engine->scene()->getSavedScreen();
::createThumbnail(&thumb, (const byte *)savedScreen.getPixels(), savedScreen.w, savedScreen.h, engine->scene()->getSavedPalette());
} else {
::createThumbnailFromScreen(&thumb);
}
}
SaveStateList saveList;
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 3);
SaveStateDescriptor AsylumMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
SaveStateDescriptor desc = MetaEngine::querySaveMetaInfos(target, slot);
if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) {
SaveStateDescriptor desc = querySaveMetaInfos(target, slotNum);
if (desc.getSaveSlot() == -1) {
Common::InSaveFile *in(saveFileMan->openForLoading(*file));
if (in && in->size()) {
(void)(uint32)Asylum::Savegame::read(in, "Chapter");
desc.setSaveSlot(slotNum);
desc.setDescription(Asylum::Savegame::read(in, 45, "Game Name"));
}
}
if (desc.getSaveSlot() == -1) {
Common::InSaveFile *in(g_system->getSavefileManager()->openForLoading(getSavegameFile(slot, target)));
saveList.push_back(desc);
if (in && in->size()) {
(void)(uint32)Asylum::Savegame::read(in, "Chapter");
desc.setSaveSlot(slot);
desc.setDescription(Asylum::Savegame::read(in, 45, "Game Name"));
}
}
// Sort saves based on slot number.
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
return saveList;
return desc;
}
Common::Error AsylumMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {

View File

@ -96,7 +96,7 @@ bool PuzzleWritings::init(const AsylumEvent &) {
getText()->drawCentered(Common::Point(10, 375), 590, getText()->get(MAKE_RESOURCE(kResourcePackText, textId++)));
getText()->drawCentered(Common::Point(10, 405), 590, getText()->get(MAKE_RESOURCE(kResourcePackText, textId)));
_textSurface.copyFrom(*getScreen()->getSurface());
_textSurface.copyFrom(getScreen()->getSurface());
return false;
}

View File

@ -130,11 +130,11 @@ bool Savegame::quickLoad() {
return true;
}
void Savegame::save(bool appendExtended) {
void Savegame::save() {
// Original creates a folder to hold saved games and checks for disk space, we can skip that
getCursor()->hide();
if (saveData(getFilename(_index), _names[_index], getWorld()->chapter, appendExtended)) {
if (saveData(getFilename(_index), _names[_index], getWorld()->chapter)) {
_savegames[_index] = true;
getMenu()->setDword455C78(true);
@ -292,7 +292,7 @@ bool Savegame::loadData(const Common::String &filename) {
return true;
}
bool Savegame::saveData(const Common::String &filename, const Common::String &name, ChapterIndex chapter, bool appendExtended) {
bool Savegame::saveData(const Common::String &filename, const Common::String &name, ChapterIndex chapter) {
Common::OutSaveFile *file = g_system->getSavefileManager()->openForSaving(filename);
if (!file)
return false;
@ -311,10 +311,7 @@ bool Savegame::saveData(const Common::String &filename, const Common::String &na
write(file, _vm->getTick(), "Time");
if (appendExtended)
_vm->getMetaEngine()->appendExtendedSaveToStream(file, _vm->getTotalPlayTime() / 1000, name, false);
else
file->writeUint32LE(0);
_vm->getMetaEngine()->appendExtendedSaveToStream(file, _vm->getTotalPlayTime() / 1000, name, false);
delete file;

View File

@ -69,11 +69,9 @@ public:
/**
* Saves a game
*
* @param appendExtended Append the extended savegame header to the stream.
*
* @return true if it succeeds, false if it fails.
*/
void save(bool appendExtended = false);
void save();
/**
* Quick saves a game
@ -255,11 +253,10 @@ private:
* @param filename Filename of the file.
* @param name The name.
* @param chapter The chapter.
* @param appendExtended Append the extended savegame header to the stream.
*
* @return true if it succeeds, false if it fails.
*/
bool saveData(const Common::String &filename, const Common::String &name, ChapterIndex chapter, bool appendExtended = false);
bool saveData(const Common::String &filename, const Common::String &name, ChapterIndex chapter);
};
} // End of namespace Asylum

View File

@ -33,7 +33,7 @@
namespace Asylum {
#define PALETTE_SIZE 256 * 3
#define PALETTE_SIZE (256 * 3)
class AsylumEngine;
class GraphicResource;
@ -95,6 +95,7 @@ public:
// Palette
void setPalette(ResourceId id);
const byte *getPalette() { return _mainPalette; }
void setMainPalette(const byte *data);
void loadGrayPalette();
void updatePalette();
@ -135,7 +136,7 @@ public:
void copyToBackBufferClipped(Graphics::Surface *surface, int16 x, int16 y);
// Used by Writings puzzle
const Graphics::Surface *getSurface() const { return &_backBuffer; };
const Graphics::Surface &getSurface() const { return _backBuffer; };
protected:
// Palette fading Timer

View File

@ -69,6 +69,8 @@ Scene::Scene(AsylumEngine *engine): _vm(engine),
_musicVolume = 0;
_frameCounter = 0;
_savedScreen.create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
g_debugActors = 0;
g_debugObjects = 0;
g_debugPolygons = 0;
@ -83,6 +85,8 @@ Scene::~Scene() {
// Clear script queue
getScript()->reset();
_savedScreen.free();
delete _polygons;
delete _ws;
}
@ -472,8 +476,11 @@ bool Scene::key(const AsylumEvent &evt) {
if (getCursor()->isHidden())
break;
if (!_vm->checkGameVersion("Demo"))
if (!_vm->checkGameVersion("Demo")) {
_savedScreen.copyFrom(getScreen()->getSurface());
memcpy(_savedPalette, getScreen()->getPalette(), sizeof(_savedPalette));
_vm->switchEventHandler(_vm->menu());
}
}
break;

View File

@ -29,6 +29,8 @@
#include "graphics/surface.h"
#include "asylum/system/screen.h"
#include "asylum/eventhandler.h"
#include "asylum/shared.h"
@ -196,6 +198,9 @@ public:
WorldStats *worldstats() { return _ws; }
uint32 getFrameCounter() { return _frameCounter; }
const byte *getSavedPalette() { return _savedPalette; }
const Graphics::Surface &getSavedScreen() { return _savedScreen; }
private:
AsylumEngine *_vm;
@ -215,6 +220,9 @@ private:
Common::Array<UpdateItem> _updateList;
uint32 _frameCounter;
Graphics::Surface _savedScreen;
byte _savedPalette[PALETTE_SIZE];
//////////////////////////////////////////////////////////////////////////
// Message handling
void activate();

View File

@ -111,7 +111,7 @@ bool VideoPlayer::handleEvent(const AsylumEvent &evt) {
getText()->draw(0, 99, kTextCenter, Common::Point(10, y), 20, 620, text);
if (_vm->checkGameVersion("Steam")) {
Graphics::Surface *st = getScreen()->getSurface()->convertTo(g_system->getScreenFormat(), _subtitlePalette);
Graphics::Surface *st = getScreen()->getSurface().convertTo(g_system->getScreenFormat(), _subtitlePalette);
g_system->copyRectToScreen((const byte *)st->getBasePtr(0, 400), st->pitch, 0, 400, 640, 80);
st->free();
delete st;