1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

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
This commit is contained in:
Ivan Savenko 2013-01-16 14:28:49 +00:00
parent d7c9377843
commit 5deb499e7e
10 changed files with 46 additions and 24 deletions

View File

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

View File

@ -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;
}

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<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));
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<std::string> CResourceHandler::getAvailableMods()
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)
{
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);
}
}

View File

@ -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

View File

@ -60,7 +60,7 @@ void LibClasses::loadFilesystem()
CResourceHandler::initialize();
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;
modh = new CModHandler;