2018-03-17 17:36:18 +02:00
|
|
|
/* 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.
|
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* 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.
|
2018-03-17 17:36:18 +02:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-17 17:36:18 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-03-25 22:32:07 +03:00
|
|
|
#include "pink/pink.h"
|
2018-05-21 12:30:27 +03:00
|
|
|
#include "pink/objects/module.h"
|
|
|
|
#include "pink/objects/pages/game_page.h"
|
2018-05-25 17:48:22 +03:00
|
|
|
#include "pink/objects/actors/lead_actor.h"
|
2018-03-17 17:36:18 +02:00
|
|
|
|
|
|
|
namespace Pink {
|
|
|
|
|
2018-03-17 20:27:03 +02:00
|
|
|
ModuleProxy::ModuleProxy(const Common::String &name)
|
2018-05-22 11:58:02 +03:00
|
|
|
: NamedObject(name) {}
|
2018-03-17 17:36:18 +02:00
|
|
|
|
2018-03-17 20:27:03 +02:00
|
|
|
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-03-17 20:27:03 +02:00
|
|
|
|
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);
|
2018-03-17 17:36:18 +02:00
|
|
|
|
2018-08-17 17:08:40 +03:00
|
|
|
archive.skipString(); // skip directory
|
2018-03-17 17:36:18 +02:00
|
|
|
|
2018-05-22 08:03:37 +03:00
|
|
|
_invMgr.deserialize(archive);
|
|
|
|
_pages.deserialize(archive);
|
2018-03-17 17:36:18 +02:00
|
|
|
}
|
|
|
|
|
2018-03-25 22:32:07 +03:00
|
|
|
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);
|
2018-03-25 22:32:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-03-17 17:36:18 +02:00
|
|
|
}
|
|
|
|
|
2018-03-25 22:32:07 +03:00
|
|
|
GamePage *Module::findPage(const Common::String &pageName) const {
|
2018-05-22 07:01:54 +03:00
|
|
|
for (uint i = 0; i < _pages.size(); ++i) {
|
|
|
|
if (_pages[i]->getName() == pageName)
|
|
|
|
return _pages[i];
|
|
|
|
}
|
|
|
|
return nullptr;
|
2018-03-25 22:32:07 +03:00
|
|
|
}
|
|
|
|
|
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;
|
2018-03-22 07:47:45 +02:00
|
|
|
}
|
|
|
|
|
2018-05-25 17:48:22 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-03-17 17:36:18 +02:00
|
|
|
} // End of namespace Pink
|