From 1bb5424dddca2cf150fa1a09f4845e193b581e3e Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Thu, 4 Aug 2016 06:28:04 +0200 Subject: MOHAWK: Move PLST handling to the RivenCard class --- engines/mohawk/riven_card.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'engines/mohawk/riven_card.cpp') diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp index 90a6888f22..54b588c2a0 100644 --- a/engines/mohawk/riven_card.cpp +++ b/engines/mohawk/riven_card.cpp @@ -22,6 +22,9 @@ #include "mohawk/riven_card.h" +#include "mohawk/riven_graphics.h" +#include "mohawk/sound.h" + #include "mohawk/resource.h" #include "mohawk/riven.h" @@ -31,6 +34,7 @@ RivenCard::RivenCard(MohawkEngine_Riven *vm, uint16 id) : _vm(vm), _id(id) { loadCardResource(id); + loadCardPictureList(id); } RivenCard::~RivenCard() { @@ -48,7 +52,16 @@ void RivenCard::loadCardResource(uint16 id) { } void RivenCard::open() { + _vm->_activatedPLST = false; + _vm->_activatedSLST = false; + + runScript(kCardLoadScript); + defaultLoadScript(); + initializeZipMode(); + _vm->_gfx->updateScreen(); + + runScript(kCardOpenScript); } void RivenCard::initializeZipMode() { @@ -70,4 +83,49 @@ uint16 RivenCard::getId() const { return _id; } +void RivenCard::defaultLoadScript() { + // Activate the first picture list if none have been activated + if (!_vm->_activatedPLST) + drawPicture(1); + + // Activate the first sound list if none have been activated + if (!_vm->_activatedSLST) + _vm->_sound->playSLST(1, _id); +} + +void RivenCard::loadCardPictureList(uint16 id) { + Common::SeekableReadStream* plst = _vm->getResource(ID_PLST, id); + uint16 recordCount = plst->readUint16BE(); + _pictureList.resize(recordCount); + + for (uint16 i = 0; i < recordCount; i++) { + Picture &picture = _pictureList[i]; + picture.index = plst->readUint16BE(); + picture.id = plst->readUint16BE(); + picture.rect.left = plst->readUint16BE(); + picture.rect.top = plst->readUint16BE(); + picture.rect.right = plst->readUint16BE(); + picture.rect.bottom = plst->readUint16BE(); + } + + delete plst; +} + +void RivenCard::drawPicture(uint16 index, bool queue) { + if (index > 0 && index <= _pictureList.size()) { + RivenScriptPtr script = _vm->_scriptMan->createScriptFromData(1, 39, 1, index); + _vm->_scriptMan->runScript(script, queue); + } +} + +RivenCard::Picture RivenCard::getPicture(uint16 index) const { + for (uint16 i = 0; i < _pictureList.size(); i++) { + if (_pictureList[i].index == index) { + return _pictureList[i]; + } + } + + error("Could not find picture %d in card %d", index, _id); +} + } // End of namespace Mohawk -- cgit v1.2.3