From 5deb499e7ef08d64ade93ec23b6b7e9ebb726c3e Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 16 Jan 2013 14:28:49 +0000 Subject: [PATCH] Last breaking change into mod system (will explain on forum) - paths in "filesystem" node are now relative to mod directory - "filesystem" entry in mod.json is now optional - made "register object" log messages visible only in log - minor fixes, including #1173 --- Mods/vcmi/mod.json | 2 +- client/CKingdomInterface.cpp | 1 + client/UIFramework/CCursorHandler.cpp | 4 +-- lib/CArtHandler.cpp | 2 +- lib/CCreatureHandler.cpp | 2 +- lib/CHeroHandler.cpp | 4 +-- lib/CTownHandler.cpp | 2 +- lib/Filesystem/CResourceLoader.cpp | 43 +++++++++++++++++++-------- lib/Filesystem/CResourceLoader.h | 8 +++-- lib/VCMI_Lib.cpp | 2 +- 10 files changed, 46 insertions(+), 24 deletions(-) diff --git a/Mods/vcmi/mod.json b/Mods/vcmi/mod.json index 9acf02745..7419fb523 100644 --- a/Mods/vcmi/mod.json +++ b/Mods/vcmi/mod.json @@ -18,7 +18,7 @@ "name" : "VCMI essential files", "description" : "Essential files required for VCMI to run correctly", - "requires" : + "depends" : [ "wog" ] diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index c963d4102..2d87f49cb 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -945,6 +945,7 @@ CIntObject * CHeroItem::onTabSelected(size_t index) void CHeroItem::onTabDeselected(CIntObject *object) { addChild(object, false); + object->deactivate(); object->recActions = DISPOSE | SHARE_POS; } diff --git a/client/UIFramework/CCursorHandler.cpp b/client/UIFramework/CCursorHandler.cpp index b785174ba..391a158c3 100644 --- a/client/UIFramework/CCursorHandler.cpp +++ b/client/UIFramework/CCursorHandler.cpp @@ -116,7 +116,7 @@ void CCursorHandler::shiftPos( int &x, int &y ) y-=16; // Properly align the melee attack cursors. - if (type == ECursor::COMBAT == 1) + if (type == ECursor::COMBAT) { switch (frame) { @@ -155,7 +155,7 @@ void CCursorHandler::shiftPos( int &x, int &y ) } } } - else if(ECursor::ADVENTURE == 0) + else if(type == ECursor::ADVENTURE) { if (frame == 0); //to exclude else if(frame == 2) diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index ec9df4eff..31b415c66 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -387,7 +387,7 @@ void CArtHandler::load(const JsonNode & node) art->id = artifacts.size(); artifacts.push_back(art); - tlog3 << "Added artifact: " << entry.first << "\n"; + tlog5 << "Added artifact: " << entry.first << "\n"; VLC->modh->identifiers.registerObject (std::string("artifact.") + art->Name(), art->id); } } diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 0fbf51ea6..5c86e9164 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -548,7 +548,7 @@ void CCreatureHandler::load(const JsonNode & node) creature->idNumber = creatures.size(); creatures.push_back(creature); - tlog3 << "Added creature: " << entry.first << "\n"; + tlog5 << "Added creature: " << entry.first << "\n"; VLC->modh->identifiers.registerObject(std::string("creature.") + creature->nameRef, creature->idNumber); } } diff --git a/lib/CHeroHandler.cpp b/lib/CHeroHandler.cpp index eddbf8569..d7ffbe3f2 100644 --- a/lib/CHeroHandler.cpp +++ b/lib/CHeroHandler.cpp @@ -141,7 +141,7 @@ void CHeroClassHandler::load(const JsonNode & classes) heroClass->id = heroClasses.size(); heroClasses.push_back(heroClass); - tlog3 << "Added hero class: " << entry.first << "\n"; + tlog5 << "Added hero class: " << entry.first << "\n"; VLC->modh->identifiers.registerObject("heroClass." + heroClass->identifier, heroClass->id); } } @@ -222,7 +222,7 @@ void CHeroHandler::load(const JsonNode & input) hero->ID = heroes.size(); heroes.push_back(hero); - tlog3 << "Added hero: " << entry.first << "\n"; + tlog5 << "Added hero: " << entry.first << "\n"; VLC->modh->identifiers.registerObject("hero." + entry.first, hero->ID); } } diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 68854c682..4344a6502 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -540,7 +540,7 @@ void CTownHandler::load(const JsonNode &source) if (!node.second["puzzleMap"].isNull()) loadPuzzle(faction, node.second["puzzleMap"]); - tlog3 << "Added faction: " << node.first << "\n"; + tlog5 << "Added faction: " << node.first << "\n"; VLC->modh->identifiers.registerObject(std::string("faction.") + node.first, faction.factionID); } } diff --git a/lib/Filesystem/CResourceLoader.cpp b/lib/Filesystem/CResourceLoader.cpp index 0473345f3..557e336b7 100644 --- a/lib/Filesystem/CResourceLoader.cpp +++ b/lib/Filesystem/CResourceLoader.cpp @@ -344,9 +344,9 @@ void CResourceHandler::initialize() recurseInDir("ALL/MODS", 2); // look for mods. Depth 2 is required for now but won't cause issues if no mods present } -void CResourceHandler::loadDirectory(const std::string &mountPoint, const JsonNode & config) +void CResourceHandler::loadDirectory(const std::string &prefix, const std::string &mountPoint, const JsonNode & config) { - std::string URI = config["path"].String(); + std::string URI = prefix + config["path"].String(); bool writeable = config["writeable"].Bool(); int depth = 16; if (!config["depth"].isNull()) @@ -362,36 +362,41 @@ void CResourceHandler::loadDirectory(const std::string &mountPoint, const JsonNo } } -void CResourceHandler::loadArchive(const std::string &mountPoint, const JsonNode & config, EResType::Type archiveType) +void CResourceHandler::loadArchive(const std::string &prefix, const std::string &mountPoint, const JsonNode & config, EResType::Type archiveType) { - std::string URI = config["path"].String(); + std::string URI = prefix + config["path"].String(); std::string filename = initialLoader->getResourceName(ResourceID(URI, archiveType)); if (!filename.empty()) resourceLoader->addLoader(mountPoint, shared_ptr(new CLodArchiveLoader(filename)), false); } -void CResourceHandler::loadFileSystem(const std::string &fsConfigURI) +void CResourceHandler::loadFileSystem(const std::string & prefix, const std::string &fsConfigURI) { auto fsConfigData = initialLoader->loadData(ResourceID(fsConfigURI, EResType::TEXT)); const JsonNode fsConfig((char*)fsConfigData.first.get(), fsConfigData.second); - BOOST_FOREACH(auto & mountPoint, fsConfig["filesystem"].Struct()) + loadFileSystem(prefix, fsConfig["filesystem"]); +} + +void CResourceHandler::loadFileSystem(const std::string & prefix, const JsonNode &fsConfig) +{ + BOOST_FOREACH(auto & mountPoint, fsConfig.Struct()) { BOOST_FOREACH(auto & entry, mountPoint.second.Vector()) { CStopWatch timer; - tlog5 << "\t\tLoading resource at " << entry["path"].String() << "\n"; + tlog5 << "\t\tLoading resource at " << prefix + entry["path"].String() << "\n"; if (entry["type"].String() == "dir") - loadDirectory(mountPoint.first, entry); + loadDirectory(prefix, mountPoint.first, entry); if (entry["type"].String() == "lod") - loadArchive(mountPoint.first, entry, EResType::ARCHIVE_LOD); + loadArchive(prefix, mountPoint.first, entry, EResType::ARCHIVE_LOD); if (entry["type"].String() == "snd") - loadArchive(mountPoint.first, entry, EResType::ARCHIVE_SND); + loadArchive(prefix, mountPoint.first, entry, EResType::ARCHIVE_SND); if (entry["type"].String() == "vid") - loadArchive(mountPoint.first, entry, EResType::ARCHIVE_VID); + loadArchive(prefix, mountPoint.first, entry, EResType::ARCHIVE_VID); tlog5 << "Resource loaded in " << timer.getDiff() << " ms.\n"; } @@ -425,8 +430,22 @@ std::vector CResourceHandler::getAvailableMods() void CResourceHandler::setActiveMods(std::vector enabledMods) { + // default FS config for mods: directory "Content" that acts as H3 root directory + JsonNode defaultFS; + + defaultFS[""].Vector().resize(1); + defaultFS[""].Vector()[0]["type"].String() = "dir"; + defaultFS[""].Vector()[0]["path"].String() = "/Content"; + BOOST_FOREACH(std::string & modName, enabledMods) { - loadFileSystem("all/mods/" + modName + "/mod.json"); + ResourceID modConfFile("all/mods/" + modName + "/mod", EResType::TEXT); + auto fsConfigData = initialLoader->loadData(modConfFile); + const JsonNode fsConfig((char*)fsConfigData.first.get(), fsConfigData.second); + + if (!fsConfig["filesystem"].isNull()) + loadFileSystem("all/mods/" + modName, fsConfig["filesystem"]); + else + loadFileSystem("all/mods/" + modName, defaultFS); } } diff --git a/lib/Filesystem/CResourceLoader.h b/lib/Filesystem/CResourceLoader.h index a255a22e6..121a959a4 100644 --- a/lib/Filesystem/CResourceLoader.h +++ b/lib/Filesystem/CResourceLoader.h @@ -378,10 +378,12 @@ public: /** * Will load all filesystem data from Json data at this path (config/filesystem.json) + * @param prefix - prefix for all paths in filesystem config */ - static void loadFileSystem(const std::string & fsConfigURI); - static void loadDirectory(const std::string & mountPoint, const JsonNode & config); - static void loadArchive(const std::string & mountPoint, const JsonNode & config, EResType::Type archiveType); + static void loadFileSystem(const std::string &prefix, const std::string & fsConfigURI); + static void loadFileSystem(const std::string &prefix, const JsonNode & fsConfig); + static void loadDirectory(const std::string &prefix, const std::string & mountPoint, const JsonNode & config); + static void loadArchive(const std::string &prefix, const std::string & mountPoint, const JsonNode & config, EResType::Type archiveType); /** * Checks all subfolders of MODS directory for presence of mods diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 45af71117..1759b0ea9 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -60,7 +60,7 @@ void LibClasses::loadFilesystem() CResourceHandler::initialize(); tlog0<<"\t Initialization: "<