Enable loading modules from MOD files

This commit is contained in:
Vsevolod Kremianskii 2021-04-05 16:10:17 +07:00
parent b72ab32248
commit f006d0ea1a
2 changed files with 14 additions and 10 deletions

View file

@ -144,13 +144,11 @@ void Game::loadModuleNames() {
for (auto &entry : fs::directory_iterator(modules)) {
string filename(boost::to_lower_copy(entry.path().filename().string()));
if (!boost::ends_with(filename, ".rim") || boost::ends_with(filename, "_s.rim")) continue;
string moduleName(boost::to_lower_copy(filename.substr(0, filename.size() - 4)));
_moduleNames.push_back(move(moduleName));
if (boost::ends_with(filename, ".mod") || (boost::ends_with(filename, ".rim") && !boost::ends_with(filename, "_s.rim"))) {
string moduleName(boost::to_lower_copy(filename.substr(0, filename.size() - 4)));
_moduleNames.insert(move(moduleName));
}
}
sort(_moduleNames.begin(), _moduleNames.end());
}
void Game::setCursorType(CursorType type) {
@ -308,8 +306,13 @@ void Game::loadModuleResources(const string &moduleName) {
Resources::instance().clearTransientProviders();
fs::path modulesPath(getPathIgnoreCase(_path, kModulesDirectoryName));
Resources::instance().indexRimFile(getPathIgnoreCase(modulesPath, moduleName + ".rim"), true);
Resources::instance().indexRimFile(getPathIgnoreCase(modulesPath, moduleName + "_s.rim"), true);
fs::path modPath(getPathIgnoreCase(modulesPath, moduleName + ".mod"));
if (fs::exists(modPath)) {
Resources::instance().indexErfFile(getPathIgnoreCase(modulesPath, moduleName + ".mod", false), true);
} else {
Resources::instance().indexRimFile(getPathIgnoreCase(modulesPath, moduleName + ".rim"), true);
Resources::instance().indexRimFile(getPathIgnoreCase(modulesPath, moduleName + "_s.rim"), true);
}
fs::path lipsPath(getPathIgnoreCase(_path, kLipsDirectoryName));
Resources::instance().indexErfFile(getPathIgnoreCase(lipsPath, moduleName + "_loc.mod"), true);

View file

@ -20,6 +20,7 @@
#include <cstdint>
#include <functional>
#include <map>
#include <set>
#include <boost/filesystem/path.hpp>
#include <boost/noncopyable.hpp>
@ -119,7 +120,7 @@ public:
CameraType cameraType() const { return _cameraType; }
ScriptRunner &scriptRunner() { return _scriptRunner; }
Conversation &conversation() { return *_conversation; }
const std::vector<std::string> &moduleNames() const { return _moduleNames; }
const std::set<std::string> &moduleNames() const { return _moduleNames; }
Combat &combat() { return _combat; }
void setCursorType(CursorType type);
@ -231,7 +232,7 @@ private:
bool _paused { false };
Conversation *_conversation { nullptr }; /**< pointer to either DialogGUI or ComputerGUI */
ProfileOverlay _profileOverlay;
std::vector<std::string> _moduleNames;
std::set<std::string> _moduleNames;
Combat _combat;
// Modules