MOHAWK: Move running the card leave script to the RivenCard destructor

This commit is contained in:
Bastien Bouclet 2016-08-07 07:47:18 +02:00 committed by Eugene Sandulenko
parent 9b2c90c0b3
commit aa0c89da03
5 changed files with 54 additions and 20 deletions

View file

@ -387,9 +387,6 @@ void MohawkEngine_Riven::changeToCard(uint16 dest) {
} }
} }
if (_card)
_card->runScript(kCardLeaveScript);
delete _card; delete _card;
_card = new RivenCard(this, dest); _card = new RivenCard(this, dest);
@ -400,9 +397,6 @@ void MohawkEngine_Riven::refreshCard() {
// Clear any timer still floating around // Clear any timer still floating around
removeTimer(); removeTimer();
_gfx->clearWaterEffects();
_video->stopVideos();
_card->open(); _card->open();
if (_showHotspots) if (_showHotspots)
@ -838,7 +832,7 @@ void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) {
ZipMode zip; ZipMode zip;
zip.name = cardName; zip.name = cardName;
zip.id = cardId; zip.id = cardId;
if (!(Common::find(_zipModeData.begin(), _zipModeData.end(), zip) != _zipModeData.end())) if (Common::find(_zipModeData.begin(), _zipModeData.end(), zip) == _zipModeData.end())
_zipModeData.push_back(zip); _zipModeData.push_back(zip);
} }

View file

@ -44,9 +44,14 @@ RivenCard::RivenCard(MohawkEngine_Riven *vm, uint16 id) :
} }
RivenCard::~RivenCard() { RivenCard::~RivenCard() {
runLeaveScripts();
for (uint i = 0; i < _hotspots.size(); i++) { for (uint i = 0; i < _hotspots.size(); i++) {
delete _hotspots[i]; delete _hotspots[i];
} }
_vm->_gfx->clearWaterEffects();
_vm->_video->stopVideos();
} }
void RivenCard::loadCardResource(uint16 id) { void RivenCard::loadCardResource(uint16 id) {
@ -93,13 +98,18 @@ void RivenCard::initializeZipMode() {
} }
} }
void RivenCard::runScript(uint16 scriptType) { RivenScriptPtr RivenCard::getScript(uint16 scriptType) const {
for (uint16 i = 0; i < _scripts.size(); i++) for (uint16 i = 0; i < _scripts.size(); i++)
if (_scripts[i].type == scriptType) { if (_scripts[i].type == scriptType) {
RivenScriptPtr script = _scripts[i].script; return _scripts[i].script;
_vm->_scriptMan->runScript(script, false);
break;
} }
return RivenScriptPtr(new RivenScript());
}
void RivenCard::runScript(uint16 scriptType) {
RivenScriptPtr script = getScript(scriptType);
_vm->_scriptMan->runScript(script, false);
} }
uint16 RivenCard::getId() const { uint16 RivenCard::getId() const {
@ -381,12 +391,12 @@ void RivenCard::onMouseDragUpdate() {
} }
void RivenCard::onMouseUpdate() { void RivenCard::onMouseUpdate() {
RivenScriptPtr script; RivenScriptPtr script(new RivenScript());
if (_hoveredHotspot) { if (_hoveredHotspot) {
script = _hoveredHotspot->getScript(kMouseInsideScript); script = _hoveredHotspot->getScript(kMouseInsideScript);
} }
if (script && !script->empty()) { if (!script->empty()) {
_vm->_scriptMan->runScript(script, false); _vm->_scriptMan->runScript(script, false);
} else { } else {
updateMouseCursor(); updateMouseCursor();
@ -405,6 +415,22 @@ void RivenCard::updateMouseCursor() {
_vm->_system->updateScreen(); _vm->_system->updateScreen();
} }
void RivenCard::runLeaveScripts() {
RivenScriptPtr script(new RivenScript());
if (_pressedHotspot) {
script += _pressedHotspot->getScript(kMouseUpScript);
}
if (_hoveredHotspot) {
script += _hoveredHotspot->getScript(kMouseLeaveScript);
}
script += getScript(kCardLeaveScript);
_vm->_scriptMan->runScript(script, false);
}
RivenHotspot::RivenHotspot(MohawkEngine_Riven *vm, Common::ReadStream *stream) : RivenHotspot::RivenHotspot(MohawkEngine_Riven *vm, Common::ReadStream *stream) :
_vm(vm) { _vm(vm) {
loadFromStream(stream); loadFromStream(stream);
@ -448,7 +474,7 @@ RivenScriptPtr RivenHotspot::getScript(uint16 scriptType) const {
return _scripts[i].script; return _scripts[i].script;
} }
return RivenScriptPtr(); return RivenScriptPtr(new RivenScript());
} }
bool RivenHotspot::isEnabled() const { bool RivenHotspot::isEnabled() const {

View file

@ -125,7 +125,11 @@ private:
void loadCardHotspotEnableList(uint16 id); void loadCardHotspotEnableList(uint16 id);
void loadCardWaterEffectList(uint16 id); void loadCardWaterEffectList(uint16 id);
RivenScriptPtr getScript(uint16 scriptType) const;
void defaultLoadScript(); void defaultLoadScript();
void runLeaveScripts();
void updateMouseCursor();
struct HotspotEnableRecord { struct HotspotEnableRecord {
uint16 index; uint16 index;
@ -156,8 +160,6 @@ private:
Common::Array<SLSTRecord> _soundList; Common::Array<SLSTRecord> _soundList;
Common::Array<HotspotEnableRecord> _hotspotEnableList; Common::Array<HotspotEnableRecord> _hotspotEnableList;
Common::Array<WaterEffectRecord> _waterEffectList; Common::Array<WaterEffectRecord> _waterEffectList;
void updateMouseCursor();
}; };
/** /**

View file

@ -114,10 +114,6 @@ void RivenScriptManager::clearStoredMovieOpcode() {
} }
void RivenScriptManager::runScript(const RivenScriptPtr &script, bool queue) { void RivenScriptManager::runScript(const RivenScriptPtr &script, bool queue) {
if (!script || script->empty()) {
return;
}
if (!queue) { if (!queue) {
script->run(); script->run();
} else { } else {
@ -187,6 +183,16 @@ bool RivenScript::empty() const {
return _commands.empty(); return _commands.empty();
} }
RivenScript &RivenScript::operator+=(const RivenScript &other) {
_commands.push_back(other._commands);
return *this;
}
RivenScriptPtr &operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs) {
*lhs += *rhs;
return lhs;
}
RivenCommand::RivenCommand(MohawkEngine_Riven *vm) : RivenCommand::RivenCommand(MohawkEngine_Riven *vm) :
_vm(vm) { _vm(vm) {

View file

@ -87,11 +87,17 @@ public:
/** Stop the script after the current command */ /** Stop the script after the current command */
void stopRunning() { _continueRunning = false; } void stopRunning() { _continueRunning = false; }
/** Append the commands of the other script to this script */
RivenScript &operator+=(const RivenScript &other);
private: private:
Common::Array<RivenCommand *> _commands; Common::Array<RivenCommand *> _commands;
bool _continueRunning; bool _continueRunning;
}; };
/** Append the commands of the rhs Script to those of the lhs Script */
RivenScriptPtr &operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs);
/** /**
* A script and its type * A script and its type
* *