MACVENTURE: Add save game loading
This commit is contained in:
parent
9564866ec3
commit
5719ea3076
7 changed files with 275 additions and 7 deletions
98
engines/macventure/world.cpp
Normal file
98
engines/macventure/world.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
#include "macventure/world.h"
|
||||
|
||||
#include "common/file.h"
|
||||
|
||||
namespace MacVenture {
|
||||
|
||||
World::World(MacVentureEngine *engine, Common::MacResManager *resMan) {
|
||||
_resourceManager = resMan;
|
||||
_engine = engine;
|
||||
|
||||
if (!loadStartGameFileName())
|
||||
error("Could not load initial game configuration");
|
||||
|
||||
Common::File saveGameFile;
|
||||
if (!saveGameFile.open(_startGameFileName))
|
||||
error("Could not load initial game configuration");
|
||||
|
||||
Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size());
|
||||
|
||||
_saveGame = new SaveGame(_engine, saveGameRes);
|
||||
|
||||
delete saveGameRes;
|
||||
saveGameFile.close();
|
||||
}
|
||||
|
||||
|
||||
World::~World() {
|
||||
|
||||
if (_saveGame)
|
||||
delete _saveGame;
|
||||
}
|
||||
|
||||
bool World::loadStartGameFileName() {
|
||||
Common::SeekableReadStream *res;
|
||||
|
||||
res = _resourceManager->getResource(MKTAG('S', 'T', 'R', ' '), kStartGameFilenameID);
|
||||
if (!res)
|
||||
return false;
|
||||
|
||||
byte length = res->readByte();
|
||||
char *fileName = new char[length + 1];
|
||||
res->read(fileName, length);
|
||||
fileName[length] = '\0';
|
||||
_startGameFileName = Common::String(fileName, length);
|
||||
_startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".TXT");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// SaveGame
|
||||
SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) {
|
||||
_groups = Common::Array<AttributeGroup>();
|
||||
loadGroups(engine, res);
|
||||
_globals = Common::Array<uint16>();
|
||||
loadGlobals(engine, res);
|
||||
_text = Common::String();
|
||||
loadText(engine, res);
|
||||
}
|
||||
|
||||
SaveGame::~SaveGame() {
|
||||
}
|
||||
|
||||
const Common::Array<AttributeGroup>& MacVenture::SaveGame::getGroups() {
|
||||
return _groups;
|
||||
}
|
||||
|
||||
const Common::Array<uint16>& MacVenture::SaveGame::getGlobals() {
|
||||
return _globals;
|
||||
}
|
||||
|
||||
const Common::String & MacVenture::SaveGame::getText() {
|
||||
return _text;
|
||||
}
|
||||
|
||||
void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) {
|
||||
GlobalSettings settings = engine->getGlobalSettings();
|
||||
for (int i = 0; i < settings.numGroups; ++i) {
|
||||
AttributeGroup g;
|
||||
for (int j = 0; j < settings.numObjects; ++j)
|
||||
g.push_back(res->readUint16BE());
|
||||
|
||||
_groups.push_back(g);
|
||||
}
|
||||
}
|
||||
|
||||
void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream * res) {
|
||||
GlobalSettings settings = engine->getGlobalSettings();
|
||||
for (int i = 0; i < settings.numGlobals; ++i) {
|
||||
_globals.push_back(res->readUint16BE());
|
||||
}
|
||||
}
|
||||
|
||||
void SaveGame::loadText(MacVentureEngine *engine, Common::SeekableReadStream * res) {
|
||||
_text = "Placeholder Console Text";
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace MacVenture
|
Loading…
Add table
Add a link
Reference in a new issue