mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-10 20:01:25 +00:00
GOB: save/load drawings for "Paint" game in Adibou1
This commit is contained in:
parent
bda696d019
commit
f57d2b189c
@ -540,6 +540,8 @@ protected:
|
||||
void setupOpcodesFunc() override;
|
||||
void setupOpcodesGob() override;
|
||||
|
||||
void oAdibou1_writeSprite(OpGobParams ¶ms);
|
||||
void oAdibou1_readSprite(OpGobParams ¶ms);
|
||||
void oAdibou1_fillAreaAtPoint(OpGobParams ¶ms);
|
||||
void oAdibou1_getAppliNameFromId(OpGobParams ¶ms);
|
||||
void oAdibou1_listApplications(OpGobParams ¶ms);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "gob/inter.h"
|
||||
#include "gob/game.h"
|
||||
#include "gob/script.h"
|
||||
#include "gob/save/saveload.h"
|
||||
|
||||
|
||||
namespace Gob {
|
||||
@ -45,11 +46,54 @@ void Inter_Adibou1::setupOpcodesFunc() {
|
||||
}
|
||||
|
||||
void Inter_Adibou1::setupOpcodesGob() {
|
||||
OPCODEGOB(0, oAdibou1_writeSprite);
|
||||
OPCODEGOB(1, oAdibou1_readSprite);
|
||||
OPCODEGOB(2, oAdibou1_fillAreaAtPoint);
|
||||
OPCODEGOB(10, oAdibou1_getAppliNameFromId);
|
||||
OPCODEGOB(11, oAdibou1_listApplications);
|
||||
}
|
||||
|
||||
void Inter_Adibou1::oAdibou1_writeSprite(OpGobParams ¶ms) {
|
||||
int16 spriteIndex = _vm->_game->_script->readInt16();
|
||||
uint16 varResult = _vm->_game->_script->readUint16();
|
||||
uint16 varFileName = _vm->_game->_script->readUint16();
|
||||
|
||||
WRITE_VAR(varResult, 0);
|
||||
|
||||
const char *filename = GET_VAR_STR(varFileName);
|
||||
|
||||
SaveLoad::SaveMode mode = _vm->_saveLoad ? _vm->_saveLoad->getSaveMode(filename) : SaveLoad::kSaveModeNone;
|
||||
if (mode == SaveLoad::kSaveModeSave) {
|
||||
if (_vm->_saveLoad->save(filename, 0, -spriteIndex - 1, 0)) {
|
||||
WRITE_VAR(varResult, 1);
|
||||
}
|
||||
} else if (mode == SaveLoad::kSaveModeIgnore)
|
||||
return;
|
||||
else if (mode == SaveLoad::kSaveModeNone)
|
||||
warning("Attempted to write to file \"%s\"", filename);
|
||||
}
|
||||
|
||||
void Inter_Adibou1::oAdibou1_readSprite(OpGobParams ¶ms) {
|
||||
int16 spriteIndex = _vm->_game->_script->readInt16();
|
||||
uint16 varResult = _vm->_game->_script->readUint16();
|
||||
uint16 varFileName = _vm->_game->_script->readUint16();
|
||||
|
||||
WRITE_VAR(varResult, 0);
|
||||
|
||||
const char *filename = GET_VAR_STR(varFileName);
|
||||
|
||||
SaveLoad::SaveMode mode = _vm->_saveLoad ? _vm->_saveLoad->getSaveMode(filename) : SaveLoad::kSaveModeNone;
|
||||
if (mode == SaveLoad::kSaveModeSave) {
|
||||
if (_vm->_saveLoad->load(filename, 0, -spriteIndex - 1, 0)) {
|
||||
WRITE_VAR(varResult, 1);
|
||||
}
|
||||
} else if (mode == SaveLoad::kSaveModeIgnore)
|
||||
return;
|
||||
else if (mode == SaveLoad::kSaveModeNone)
|
||||
warning("Attempted to write to file \"%s\"", filename);
|
||||
}
|
||||
|
||||
|
||||
void Inter_Adibou1::oAdibou1_fillAreaAtPoint(OpGobParams ¶ms) {
|
||||
uint16 varX = _vm->_game->_script->readUint16();
|
||||
uint16 varY = _vm->_game->_script->readUint16();
|
||||
|
@ -305,6 +305,25 @@ protected:
|
||||
const char *description;
|
||||
};
|
||||
|
||||
class SpriteHandler : public TempSpriteHandler {
|
||||
public:
|
||||
SpriteHandler(GobEngine *vm, const Common::String &target, const Common::String &ext);
|
||||
~SpriteHandler() override;
|
||||
|
||||
int32 getSize() override;
|
||||
bool load(int16 dataVar, int32 size, int32 offset) override;
|
||||
bool save(int16 dataVar, int32 size, int32 offset) override;
|
||||
|
||||
private:
|
||||
class File : public SlotFileStatic {
|
||||
public:
|
||||
File(GobEngine *vm, const Common::String &base, const Common::String &ext);
|
||||
~File() override;
|
||||
};
|
||||
|
||||
File _file;
|
||||
};
|
||||
|
||||
class GameFileHandler : public SaveHandler {
|
||||
public:
|
||||
GameFileHandler(GobEngine *vm, const Common::String &target, const Common::String &ext);
|
||||
@ -331,6 +350,7 @@ protected:
|
||||
static SaveFile _saveFiles[];
|
||||
|
||||
GameFileHandler *_bouHandler;
|
||||
SpriteHandler *_drawingHandler;
|
||||
|
||||
SaveHandler *getHandler(const char *fileName) const override;
|
||||
const char *getDescription(const char *fileName) const override;
|
||||
|
@ -28,18 +28,83 @@ namespace Gob {
|
||||
|
||||
SaveLoad_Adibou1::SaveFile SaveLoad_Adibou1::_saveFiles[] = {
|
||||
{ "bou.inf", kSaveModeSave, nullptr, "adibou1"},
|
||||
{ "dessin.inf", kSaveModeSave, nullptr, "paint game drawing"},
|
||||
};
|
||||
|
||||
SaveLoad_Adibou1::SaveLoad_Adibou1(GobEngine *vm, const char *targetName) :
|
||||
SaveLoad(vm) {
|
||||
|
||||
_saveFiles[0].handler = _bouHandler = new GameFileHandler(vm, targetName, "bouinf");
|
||||
_saveFiles[1].handler = _drawingHandler = new SpriteHandler(vm, targetName, "drawing");
|
||||
}
|
||||
|
||||
SaveLoad_Adibou1::~SaveLoad_Adibou1() {
|
||||
delete _bouHandler;
|
||||
}
|
||||
|
||||
SaveLoad_Adibou1::SpriteHandler::File::File(GobEngine *vm, const Common::String &base, const Common::String &ext) :
|
||||
SlotFileStatic(vm, base, ext) {
|
||||
}
|
||||
|
||||
SaveLoad_Adibou1::SpriteHandler::File::~File() {
|
||||
}
|
||||
|
||||
SaveLoad_Adibou1::SpriteHandler::SpriteHandler(GobEngine *vm, const Common::String &target, const Common::String &ext)
|
||||
: TempSpriteHandler(vm), _file(vm, target, ext) {
|
||||
}
|
||||
|
||||
SaveLoad_Adibou1::SpriteHandler::~SpriteHandler() {
|
||||
}
|
||||
|
||||
int32 SaveLoad_Adibou1::SpriteHandler::getSize() {
|
||||
Common::String fileName = _file.build();
|
||||
|
||||
if (fileName.empty())
|
||||
return -1;;
|
||||
|
||||
SaveReader reader(1, 0, fileName);
|
||||
SaveHeader header;
|
||||
|
||||
if (!reader.load())
|
||||
return -1;
|
||||
|
||||
if (!reader.readPartHeader(0, &header))
|
||||
return -1;
|
||||
|
||||
// Return the part's size
|
||||
return header.getSize();
|
||||
}
|
||||
|
||||
bool SaveLoad_Adibou1::SpriteHandler::load(int16 dataVar, int32 size, int32 offset) {
|
||||
if (!TempSpriteHandler::createFromSprite(dataVar, size, offset))
|
||||
return false;
|
||||
|
||||
Common::String fileName = _file.build();
|
||||
if (fileName.empty())
|
||||
return false;
|
||||
|
||||
SaveReader reader(1, 0, fileName);
|
||||
if (!reader.load())
|
||||
return false;
|
||||
|
||||
if (!reader.readPart(0, _sprite))
|
||||
return false;
|
||||
|
||||
return TempSpriteHandler::load(dataVar, size, offset);
|
||||
}
|
||||
|
||||
bool SaveLoad_Adibou1::SpriteHandler::save(int16 dataVar, int32 size, int32 offset) {
|
||||
if (!TempSpriteHandler::save(dataVar, size, offset))
|
||||
return false;
|
||||
|
||||
Common::String fileName = _file.build();
|
||||
if (fileName.empty())
|
||||
return false;
|
||||
|
||||
SaveWriter writer(1, 0, fileName);
|
||||
return writer.writePart(0, _sprite);
|
||||
}
|
||||
|
||||
SaveLoad_Adibou1::GameFileHandler::File::File(GobEngine *vm, const Common::String &base, const Common::String &ext) :
|
||||
SlotFileStatic(vm, base, ext) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user