From d7334628bd59a8d4019be788d1a42b9171beae3b Mon Sep 17 00:00:00 2001 From: md5 Date: Thu, 5 May 2011 22:03:15 +0300 Subject: SWORD25: Moved the thumbnail handling code to its appropriate place PNGLoader is able to load images embedded in saved games already. This helps remove some duplicate code --- engines/sword25/gfx/image/renderedimage.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'engines/sword25/gfx') diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp index 806d9b27ad..65ff1c703d 100644 --- a/engines/sword25/gfx/image/renderedimage.cpp +++ b/engines/sword25/gfx/image/renderedimage.cpp @@ -36,6 +36,7 @@ // INCLUDES // ----------------------------------------------------------------------------- +#include "common/savefile.h" #include "sword25/package/packagemanager.h" #include "sword25/gfx/image/pngloader.h" #include "sword25/gfx/image/renderedimage.h" @@ -44,6 +45,14 @@ namespace Sword25 { +// Duplicated from kernel/persistenceservice.cpp +static Common::String generateSavegameFilename(uint slotID) { + char buffer[100]; + // NOTE: This is hardcoded to sword25 + snprintf(buffer, 100, "%s.%.3d", "sword25", slotID); + return Common::String(buffer); +} + // ----------------------------------------------------------------------------- // CONSTRUCTION / DESTRUCTION // ----------------------------------------------------------------------------- @@ -62,7 +71,20 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) : // Load file byte *pFileData; uint fileSize; - pFileData = pPackage->getFile(filename, &fileSize); + + if (filename.hasPrefix("/saves")) { + // A savegame thumbnail + Common::SaveFileManager *sfm = g_system->getSavefileManager(); + int slotNum = atoi(filename.c_str() + filename.size() - 3); + Common::InSaveFile *file = sfm->openForLoading(generateSavegameFilename(slotNum)); + fileSize = file->size(); + pFileData = new byte[fileSize]; + file->read(pFileData, fileSize); + delete file; + } else { + pFileData = pPackage->getFile(filename, &fileSize); + } + if (!pFileData) { error("File \"%s\" could not be loaded.", filename.c_str()); return; -- cgit v1.2.3