111 lines
2.9 KiB
C++
Raw Normal View History

/* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "pink/pink.h"
2018-05-21 12:30:27 +03:00
#include "pink/objects/module.h"
#include "pink/objects/pages/game_page.h"
#include "pink/objects/actors/lead_actor.h"
namespace Pink {
ModuleProxy::ModuleProxy(const Common::String &name)
2018-05-22 11:58:02 +03:00
: NamedObject(name) {}
ModuleProxy::ModuleProxy() {}
Module::Module(PinkEngine *game, const Common::String &name)
2018-05-22 11:58:02 +03:00
: NamedObject(name), _game(game), _page(nullptr) {}
2018-04-06 10:03:56 +03:00
Module::~Module() {
2018-05-22 08:03:37 +03:00
for (uint i = 0; i < _pages.size(); ++i) {
delete _pages[i];
}
2018-04-06 10:03:56 +03:00
}
2018-06-20 13:42:37 +02:00
void Module::load(Archive &archive) {
2018-05-22 08:03:37 +03:00
archive.mapObject(this);
NamedObject::deserialize(archive);
archive.skipString(); // skip directory
2018-05-22 08:03:37 +03:00
_invMgr.deserialize(archive);
_pages.deserialize(archive);
}
void Module::init(bool isLoadingSave, const Common::String &pageName) {
2018-05-22 08:03:37 +03:00
// 0 0 - new game
// 0 1 - module changed
// 1 0 - from save
if (!pageName.empty())
_page = findPage(pageName);
else if (!_page)
_page = _pages[0];
_page->init(isLoadingSave);
}
void Module::changePage(const Common::String &pageName) {
2018-05-22 08:03:37 +03:00
_page->unload();
2018-06-13 15:04:46 +03:00
_page = findPage(pageName);
2018-05-22 08:03:37 +03:00
_page->init(kLoadingNewGame);
}
GamePage *Module::findPage(const Common::String &pageName) const {
for (uint i = 0; i < _pages.size(); ++i) {
if (_pages[i]->getName() == pageName)
return _pages[i];
}
return nullptr;
}
2020-02-13 21:28:22 +01:00
bool Module::checkValueOfVariable(const Common::String &variable, const Common::String &value) const {
2018-05-22 08:03:37 +03:00
if (!_variables.contains(variable))
2018-06-29 14:26:22 +03:00
return value == kUndefinedValue;
2018-05-22 08:03:37 +03:00
return _variables[variable] == value;
}
void Module::loadState(Archive &archive) {
_invMgr.loadState(archive);
_variables.deserialize(archive);
for (uint i = 0; i < _pages.size(); ++i) {
_pages[i]->loadState(archive);
}
_page = findPage(archive.readString());
_page->loadManagers();
_page->getLeadActor()->loadState(archive);
}
void Module::saveState(Archive &archive) {
_invMgr.saveState(archive);
_variables.serialize(archive);
for (uint i = 0; i < _pages.size(); ++i) {
_pages[i]->saveState(archive);
}
archive.writeString(_page->getName());
_page->getLeadActor()->saveState(archive);
}
} // End of namespace Pink