summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-25 17:45:11 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-25 17:45:11 +0300
commit5d82960de69aef6b9668b8454cb701e1db97af60 (patch)
tree8c7f4f227fbb3d323971bab4fc14d331c5289ce1 /src/resources
parentd863f7b334d30cf3dfd22f879a59f66ad4248c3f (diff)
downloadmanaplus-5d82960de69aef6b9668b8454cb701e1db97af60.tar.gz
manaplus-5d82960de69aef6b9668b8454cb701e1db97af60.tar.bz2
manaplus-5d82960de69aef6b9668b8454cb701e1db97af60.tar.xz
manaplus-5d82960de69aef6b9668b8454cb701e1db97af60.zip
Allow load stats for different pages from stats.xml
But for now visible only basic stats and extended page.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/db/statdb.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp
index 5c7f5a288..b68ee9576 100644
--- a/src/resources/db/statdb.cpp
+++ b/src/resources/db/statdb.cpp
@@ -34,7 +34,7 @@ namespace
{
bool mLoaded = false;
static std::vector<BasicStat> mBasicStats;
- static std::vector<BasicStat> mExtendedStats;
+ static std::map<std::string, std::vector<BasicStat> > mStats;
} // namespace
void StatDb::addDefaultStats()
@@ -72,7 +72,7 @@ const std::vector<BasicStat> &StatDb::getBasicStats()
const std::vector<BasicStat> &StatDb::getExtendedStats()
{
- return mExtendedStats;
+ return mStats["extended"];
}
void StatDb::load()
@@ -111,9 +111,11 @@ static void loadBasicStats(const XmlNodePtr rootNode)
}
}
-static void loadExtendedStats(const XmlNodePtr rootNode)
+static void loadStats(const XmlNodePtr rootNode,
+ const std::string &page)
{
const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE);
+ std::vector<BasicStat> &stats = mStats[page];
for_each_xml_child_node(node, rootNode)
{
if (xmlNameEqual(node, "stat"))
@@ -126,7 +128,7 @@ static void loadExtendedStats(const XmlNodePtr rootNode)
name.c_str());
continue;
}
- mExtendedStats.push_back(BasicStat(static_cast<AttributesT>(id),
+ stats.push_back(BasicStat(static_cast<AttributesT>(id),
std::string(),
name));
}
@@ -165,13 +167,23 @@ void StatDb::loadXmlFile(const std::string &fileName,
}
else if (xmlNameEqual(node, "extended"))
{
- loadExtendedStats(node);
+ loadStats(node, "extended");
+ }
+ else if (xmlNameEqual(node, "page"))
+ {
+ std::string page = XML::getProperty(node, "name", "");
+ if (page.empty())
+ {
+ reportAlways("Page without name in stats.xml");
+ page = "Unknown";
+ }
+ loadStats(node, page);
}
}
if (skipError == SkipError_false)
{
if (mBasicStats.empty() &&
- mExtendedStats.empty())
+ mStats.empty())
{
reportAlways("StatDb: no stats found");
addDefaultStats();
@@ -184,6 +196,6 @@ void StatDb::unload()
logger->log1("Unloading stat database...");
mBasicStats.clear();
- mExtendedStats.clear();
+ mStats.clear();
mLoaded = false;
}