summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-06 14:47:39 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-06 14:47:39 +0300
commitb7ee14cadb1e5675f7e36565aec1fe39e55ccc34 (patch)
treed92328178a64cd15891802ced4a0db5a0a751e11 /src
parent3cb15a8f777bd9907d8dc4ba57774c762ec1f67f (diff)
downloadmv-b7ee14cadb1e5675f7e36565aec1fe39e55ccc34.tar.gz
mv-b7ee14cadb1e5675f7e36565aec1fe39e55ccc34.tar.bz2
mv-b7ee14cadb1e5675f7e36565aec1fe39e55ccc34.tar.xz
mv-b7ee14cadb1e5675f7e36565aec1fe39e55ccc34.zip
add ability to inlude config parts from subdirs for items, monsters, npcs.
Diffstat (limited to 'src')
-rw-r--r--src/defaults.cpp3
-rw-r--r--src/resources/beingcommon.cpp20
-rw-r--r--src/resources/beingcommon.h4
-rw-r--r--src/resources/db/itemdb.cpp6
-rw-r--r--src/resources/db/monsterdb.cpp7
-rw-r--r--src/resources/db/npcdb.cpp7
-rw-r--r--src/utils/files.cpp11
-rw-r--r--src/utils/files.h3
8 files changed, 61 insertions, 0 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 98195d214..5e55ff98b 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -490,12 +490,15 @@ DefaultsData* getPathsDefaults()
AddDEF("soundsFile", "sounds.xml");
AddDEF("itemsFile", "items.xml");
AddDEF("itemsPatchFile", "items_patch.xml");
+ AddDEF("itemsPatchDir", "items.d");
AddDEF("avatarsFile", "avatars.xml");
AddDEF("npcsFile", "npcs.xml");
AddDEF("npcsPatchFile", "npcs_patch.xml");
+ AddDEF("npcsPatchDir", "npcs.d");
AddDEF("petsFile", "pets.xml");
AddDEF("monstersFile", "monsters.xml");
AddDEF("monstersPatchFile", "monsters_patch.xml");
+ AddDEF("monstersPatchDir", "monsters.d");
AddDEF("mapsRemapFile", "maps/remap.xml");
AddDEF("mapsFile", "maps.xml");
AddDEF("deadMessagesFile", "deadmessages.xml");
diff --git a/src/resources/beingcommon.cpp b/src/resources/beingcommon.cpp
index 174a6edfd..5647d01e3 100644
--- a/src/resources/beingcommon.cpp
+++ b/src/resources/beingcommon.cpp
@@ -20,8 +20,14 @@
#include "resources/beingcommon.h"
+#include "utils/files.h"
+#include "utils/physfstools.h"
+#include "utils/stringutils.h"
+
#include "resources/beinginfo.h"
+#include <algorithm>
+
#include "debug.h"
void BeingCommon::readBasicAttributes(BeingInfo *const info, XmlNodePtr node,
@@ -42,3 +48,17 @@ void BeingCommon::readBasicAttributes(BeingInfo *const info, XmlNodePtr node,
info->setHpBarOffsetX(XML::getProperty(node, "hpBarOffsetX", 0));
info->setHpBarOffsetY(XML::getProperty(node, "hpBarOffsetY", 0));
}
+
+void BeingCommon::getIncludeFiles(const std::string &dir, StringVect &list)
+{
+ const std::string path = dir + PhysFs::getDirSeparator();
+ StringVect tempList;
+ Files::getFilesWithDir(path, tempList);
+ FOR_EACH (StringVectCIter, it, tempList)
+ {
+ const std::string &str = *it;
+ if (findLast(str, ".xml"))
+ list.push_back(str);
+ }
+ std::sort(list.begin(), list.end());
+}
diff --git a/src/resources/beingcommon.h b/src/resources/beingcommon.h
index 54c9fc35d..6bf481db4 100644
--- a/src/resources/beingcommon.h
+++ b/src/resources/beingcommon.h
@@ -23,6 +23,8 @@
#include "utils/xml.h"
+#include "utils/stringvector.h"
+
#include "localconsts.h"
class BeingInfo;
@@ -31,6 +33,8 @@ namespace BeingCommon
{
void readBasicAttributes(BeingInfo *const info, XmlNodePtr node,
const std::string &hoverCursor);
+
+ void getIncludeFiles(const std::string &dir, StringVect &list);
}
#endif // RESOURCES_BEINGCOMMON_H
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index 81feaea47..4c47658e6 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -25,6 +25,7 @@
#include "configuration.h"
#include "logger.h"
+#include "resources/beingcommon.h"
#include "resources/iteminfo.h"
#include "utils/dtor.h"
@@ -211,6 +212,11 @@ void ItemDB::load()
mUnknown->addTag(mTags["All"]);
loadXmlFile(paths.getStringValue("itemsFile"), tagNum);
loadXmlFile(paths.getStringValue("itemsPatchFile"), tagNum);
+
+ StringVect list;
+ BeingCommon::getIncludeFiles(paths.getStringValue("itemsPatchDir"), list);
+ FOR_EACH (StringVectCIter, it, list)
+ loadXmlFile(*it, tagNum);
}
void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum)
diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp
index f04743507..d5e36f443 100644
--- a/src/resources/db/monsterdb.cpp
+++ b/src/resources/db/monsterdb.cpp
@@ -50,6 +50,13 @@ void MonsterDB::load()
logger->log1("Initializing monster database...");
loadXmlFile(paths.getStringValue("monstersFile"));
loadXmlFile(paths.getStringValue("monstersPatchFile"));
+
+ StringVect list;
+ BeingCommon::getIncludeFiles(paths.getStringValue(
+ "monstersPatchDir"), list);
+ FOR_EACH (StringVectCIter, it, list)
+ loadXmlFile(*it);
+
mLoaded = true;
}
diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp
index 7c983160c..c8b29c9da 100644
--- a/src/resources/db/npcdb.cpp
+++ b/src/resources/db/npcdb.cpp
@@ -49,6 +49,13 @@ void NPCDB::load()
loadXmlFile(paths.getStringValue("npcsFile"));
loadXmlFile(paths.getStringValue("npcsPatchFile"));
+
+ StringVect list;
+ BeingCommon::getIncludeFiles(paths.getStringValue(
+ "npcsPatchDir"), list);
+ FOR_EACH (StringVectCIter, it, list)
+ loadXmlFile(*it);
+
mLoaded = true;
}
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
index 72a4b2cb5..9abf13593 100644
--- a/src/utils/files.cpp
+++ b/src/utils/files.cpp
@@ -207,3 +207,14 @@ void Files::getFiles(const std::string &path, StringVect &list)
}
PhysFs::freeList(fonts);
}
+
+void Files::getFilesWithDir(const std::string &path, StringVect &list)
+{
+ char **fonts = PhysFs::enumerateFiles(path.c_str());
+ for (char **i = fonts; *i; i++)
+ {
+ if (!PhysFs::isDirectory((path + *i).c_str()))
+ list.push_back(path + *i);
+ }
+ PhysFs::freeList(fonts);
+}
diff --git a/src/utils/files.h b/src/utils/files.h
index b7b5bbc31..9363f96da 100644
--- a/src/utils/files.h
+++ b/src/utils/files.h
@@ -56,6 +56,9 @@ namespace Files
const std::string &restrict pTo);
void getFiles(const std::string &path, StringVect &list);
+
+ void getFilesWithDir(const std::string &restrict path,
+ StringVect &restrict list);
} // namespace Files
#endif // UTILS_FILES_H