Ver Fonte

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

Ivan Savenko há 13 anos atrás
pai
commit
5deb499e7e

+ 1 - 1
Mods/vcmi/mod.json

@@ -18,7 +18,7 @@
 	"name" : "VCMI essential files",
 	"name" : "VCMI essential files",
 	"description" : "Essential files required for VCMI to run correctly",
 	"description" : "Essential files required for VCMI to run correctly",
 	
 	
-	"requires" :
+	"depends" :
 	[
 	[
 		"wog"
 		"wog"
 	]
 	]

+ 1 - 0
client/CKingdomInterface.cpp

@@ -945,6 +945,7 @@ CIntObject * CHeroItem::onTabSelected(size_t index)
 void CHeroItem::onTabDeselected(CIntObject *object)
 void CHeroItem::onTabDeselected(CIntObject *object)
 {
 {
 	addChild(object, false);
 	addChild(object, false);
+	object->deactivate();
 	object->recActions = DISPOSE | SHARE_POS;
 	object->recActions = DISPOSE | SHARE_POS;
 }
 }
 
 

+ 2 - 2
client/UIFramework/CCursorHandler.cpp

@@ -116,7 +116,7 @@ void CCursorHandler::shiftPos( int &x, int &y )
 		y-=16;
 		y-=16;
 
 
 		// Properly align the melee attack cursors.
 		// Properly align the melee attack cursors.
-		if (type == ECursor::COMBAT == 1)
+		if (type == ECursor::COMBAT)
 		{
 		{
 			switch (frame)
 			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
 		if (frame == 0); //to exclude
 		else if(frame == 2)
 		else if(frame == 2)

+ 1 - 1
lib/CArtHandler.cpp

@@ -387,7 +387,7 @@ void CArtHandler::load(const JsonNode & node)
 			art->id = artifacts.size();
 			art->id = artifacts.size();
 
 
 			artifacts.push_back(art);
 			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);
 			VLC->modh->identifiers.registerObject (std::string("artifact.") + art->Name(), art->id);
 		}
 		}
 	}
 	}

+ 1 - 1
lib/CCreatureHandler.cpp

@@ -548,7 +548,7 @@ void CCreatureHandler::load(const JsonNode & node)
 			creature->idNumber = creatures.size();
 			creature->idNumber = creatures.size();
 
 
 			creatures.push_back(creature);
 			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);
 			VLC->modh->identifiers.registerObject(std::string("creature.") + creature->nameRef, creature->idNumber);
 		}
 		}
 	}
 	}

+ 2 - 2
lib/CHeroHandler.cpp

@@ -141,7 +141,7 @@ void CHeroClassHandler::load(const JsonNode & classes)
 			heroClass->id = heroClasses.size();
 			heroClass->id = heroClasses.size();
 
 
 			heroClasses.push_back(heroClass);
 			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);
 			VLC->modh->identifiers.registerObject("heroClass." + heroClass->identifier, heroClass->id);
 		}
 		}
 	}
 	}
@@ -222,7 +222,7 @@ void CHeroHandler::load(const JsonNode & input)
 			hero->ID = heroes.size();
 			hero->ID = heroes.size();
 
 
 			heroes.push_back(hero);
 			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);
 			VLC->modh->identifiers.registerObject("hero." + entry.first, hero->ID);
 		}
 		}
 	}
 	}

+ 1 - 1
lib/CTownHandler.cpp

@@ -540,7 +540,7 @@ void CTownHandler::load(const JsonNode &source)
 		if (!node.second["puzzleMap"].isNull())
 		if (!node.second["puzzleMap"].isNull())
 			loadPuzzle(faction, node.second["puzzleMap"]);
 			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);
 		VLC->modh->identifiers.registerObject(std::string("faction.") + node.first, faction.factionID);
 	}
 	}
 }
 }

+ 31 - 12
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
 	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();
 	bool writeable = config["writeable"].Bool();
 	int depth = 16;
 	int depth = 16;
 	if (!config["depth"].isNull())
 	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));
 	std::string filename = initialLoader->getResourceName(ResourceID(URI, archiveType));
 	if (!filename.empty())
 	if (!filename.empty())
 		resourceLoader->addLoader(mountPoint,
 		resourceLoader->addLoader(mountPoint,
 		    shared_ptr<ISimpleResourceLoader>(new CLodArchiveLoader(filename)), false);
 		    shared_ptr<ISimpleResourceLoader>(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));
 	auto fsConfigData = initialLoader->loadData(ResourceID(fsConfigURI, EResType::TEXT));
 
 
 	const JsonNode fsConfig((char*)fsConfigData.first.get(), fsConfigData.second);
 	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())
 		BOOST_FOREACH(auto & entry, mountPoint.second.Vector())
 		{
 		{
 			CStopWatch timer;
 			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")
 			if (entry["type"].String() == "dir")
-				loadDirectory(mountPoint.first, entry);
+				loadDirectory(prefix, mountPoint.first, entry);
 			if (entry["type"].String() == "lod")
 			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")
 			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")
 			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";
 			tlog5 << "Resource loaded in " << timer.getDiff() << " ms.\n";
 		}
 		}
@@ -425,8 +430,22 @@ std::vector<std::string> CResourceHandler::getAvailableMods()
 
 
 void CResourceHandler::setActiveMods(std::vector<std::string> enabledMods)
 void CResourceHandler::setActiveMods(std::vector<std::string> 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)
 	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);
 	}
 	}
 }
 }

+ 5 - 3
lib/Filesystem/CResourceLoader.h

@@ -378,10 +378,12 @@ public:
 
 
 	/**
 	/**
 	 * Will load all filesystem data from Json data at this path (config/filesystem.json)
 	 * 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
 	 * Checks all subfolders of MODS directory for presence of mods

+ 1 - 1
lib/VCMI_Lib.cpp

@@ -60,7 +60,7 @@ void LibClasses::loadFilesystem()
 	CResourceHandler::initialize();
 	CResourceHandler::initialize();
 	tlog0<<"\t Initialization: "<<loadTime.getDiff()<<std::endl;
 	tlog0<<"\t Initialization: "<<loadTime.getDiff()<<std::endl;
 
 
-	CResourceHandler::loadFileSystem("ALL/config/filesystem.json");
+	CResourceHandler::loadFileSystem("", "ALL/config/filesystem.json");
 	tlog0<<"\t Data loading: "<<loadTime.getDiff()<<std::endl;
 	tlog0<<"\t Data loading: "<<loadTime.getDiff()<<std::endl;
 
 
 	modh = new CModHandler;
 	modh = new CModHandler;