/* 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 . * */ #include "engines/stark/services/staticprovider.h" #include "engines/stark/resources/anim.h" #include "engines/stark/resources/animscript.h" #include "engines/stark/resources/container.h" #include "engines/stark/resources/image.h" #include "engines/stark/resources/item.h" #include "engines/stark/resources/level.h" #include "engines/stark/resources/location.h" #include "engines/stark/resources/sound.h" #include "engines/stark/services/archiveloader.h" #include "engines/stark/services/global.h" #include "engines/stark/visual/image.h" namespace Stark { StaticProvider::StaticProvider(ArchiveLoader *archiveLoader) : _archiveLoader(archiveLoader), _level(nullptr), _location(nullptr) { } void StaticProvider::init() { // Load the static archive _archiveLoader->load("static/static.xarc"); // Set the root tree _level = _archiveLoader->useRoot("static/static.xarc"); // Resources lifecycle update _level->onAllLoaded(); Resources::Item *staticItem = _level->findChild(); _stockAnims = staticItem->listChildren(); for (uint i = 0; i< _stockAnims.size(); i++) { _stockAnims[i]->applyToItem(nullptr); } Resources::Anim *imagesAnim = _stockAnims[kImages]; _stockImages = imagesAnim->listChildrenRecursive(); } void StaticProvider::onGameLoop() { _level->onGameLoop(); } void StaticProvider::shutdown() { if (_location) { unloadLocation(_location); } _level = nullptr; _archiveLoader->returnRoot("static/static.xarc"); _archiveLoader->unloadUnused(); } VisualImageXMG *StaticProvider::getCursorImage(uint32 cursor) const { Resources::Anim *anim = _stockAnims[cursor]; return anim->getVisual()->get(); } VisualImageXMG *StaticProvider::getUIElement(UIElement element) const { return getCursorImage(element); } VisualImageXMG *StaticProvider::getUIElement(UIElement element, uint32 index) const { Resources::Anim *anim = _stockAnims[element]; uint32 prevIndex = anim->getCurrentFrame(); anim->selectFrame(index); VisualImageXMG *visualImage = anim->getVisual()->get(); anim->selectFrame(prevIndex); return visualImage; } VisualImageXMG *StaticProvider::getUIImage(UIImage image) const { Resources::Image *anim = _stockImages[image]; return anim->getVisual()->get(); } void StaticProvider::goToAnimScriptStatement(StaticProvider::UIElement stockUIElement, int animScriptItemIndex) { Resources::Anim *anim = _stockAnims[stockUIElement]; Resources::AnimScript *animScript = anim->findChild(); Resources::AnimScriptItem *animScriptItem = animScript->findChildWithIndex(animScriptItemIndex); animScript->goToScriptItem(animScriptItem); } Resources::Sound *StaticProvider::getUISound(UISound sound) const { Resources::Item *staticLevelItem = _level->findChild(); Resources::Anim *anim = staticLevelItem->findChildWithOrder(4); Resources::Container *sounds = anim->findChildWithSubtype(Resources::Container::kSounds); return sounds->findChildWithOrder(sound); } Common::Path StaticProvider::buildLocationArchiveName(const char *locationName) const { return Common::Path(Common::String::format("static/%s/%s.xarc", locationName, locationName)); } Resources::Location *StaticProvider::loadLocation(const char *locationName) { assert(!_location); Common::Path archiveName = buildLocationArchiveName(locationName); _archiveLoader->load(archiveName); _location = _archiveLoader->useRoot(archiveName); _location->onAllLoaded(); _location->onEnterLocation(); // Start background music Common::Array sounds = _location->listChildren(Resources::Sound::kSoundBackground); for (uint i = 0; i < sounds.size(); i++) { sounds[i]->play(); } return _location; } void StaticProvider::unloadLocation(Resources::Location *location) { assert(_location == location); location->onExitLocation(); Common::Path archiveName = buildLocationArchiveName(location->getName().c_str()); _archiveLoader->returnRoot(archiveName); _archiveLoader->unloadUnused(); _location = nullptr; } bool StaticProvider::isStaticLocation() const { return _location != nullptr; } Resources::Location *StaticProvider::getLocation() const { return _location; } Resources::Sound *StaticProvider::getLocationSound(uint16 index) const { assert(_location); Resources::Container *sounds = _location->findChildWithSubtype(Resources::Container::kSounds); return sounds->findChildWithIndex(index); } } // End of namespace Stark