From 98db053ae7fa09a8b209dca95e4e65d00320cc0b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 30 Jun 2016 15:08:36 +0300 Subject: Move extended stats from status window into stats.xml too. Also add reports about failed stats loading. --- src/resources/db/statdb.cpp | 53 +++++++++++++++++++++++++++++++++++++++++---- src/resources/db/statdb.h | 6 +++-- 2 files changed, 53 insertions(+), 6 deletions(-) (limited to 'src/resources') diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp index e079d323a..ae48485bd 100644 --- a/src/resources/db/statdb.cpp +++ b/src/resources/db/statdb.cpp @@ -37,9 +37,10 @@ namespace { bool mLoaded = false; static std::vector mBasicStats; + static std::vector mExtendedStats; } // namespace -void StatDb::addBasicStats() +void StatDb::addDefaultStats() { mBasicStats.push_back(BasicStat(Attributes::STR, "str", @@ -67,11 +68,16 @@ void StatDb::addBasicStats() _("Luck"))); } -const std::vector &StatDb::getExtraStats() +const std::vector &StatDb::getBasicStats() { return mBasicStats; } +const std::vector &StatDb::getExtendedStats() +{ + return mExtendedStats; +} + void StatDb::load() { if (mLoaded) @@ -92,11 +98,15 @@ static void loadBasicStats(const XmlNodePtr rootNode) { if (xmlNameEqual(node, "stat")) { + const std::string name = XML::getProperty(node, "name", ""); const int id = XML::getProperty(node, "id", 0); if (id <= 0 || id >= maxAttr) + { + reportAlways("Wrong id for basic stat with name %s", + name.c_str()); continue; + } const std::string tag = XML::getProperty(node, "tag", ""); - const std::string name = XML::getProperty(node, "name", ""); mBasicStats.push_back(BasicStat(static_cast(id), tag, name)); @@ -104,6 +114,28 @@ static void loadBasicStats(const XmlNodePtr rootNode) } } +static void loadExtendedStats(const XmlNodePtr rootNode) +{ + const int maxAttr = static_cast(Attributes::MAX_ATTRIBUTE); + for_each_xml_child_node(node, rootNode) + { + if (xmlNameEqual(node, "stat")) + { + const std::string name = XML::getProperty(node, "name", ""); + const int id = XML::getProperty(node, "id", 0); + if (id <= 0 || id >= maxAttr) + { + reportAlways("Wrong id for extended stat with name %s", + name.c_str()); + continue; + } + mExtendedStats.push_back(BasicStat(static_cast(id), + std::string(), + name)); + } + } +} + void StatDb::loadXmlFile(const std::string &fileName, const SkipError skipError) { @@ -117,7 +149,7 @@ void StatDb::loadXmlFile(const std::string &fileName, logger->log("StatDb: Error while loading %s!", fileName.c_str()); if (skipError == SkipError_false) - addBasicStats(); + addDefaultStats(); return; } @@ -134,6 +166,19 @@ void StatDb::loadXmlFile(const std::string &fileName, { loadBasicStats(node); } + else if (xmlNameEqual(node, "extended")) + { + loadExtendedStats(node); + } + } + if (skipError == SkipError_false) + { + if (mBasicStats.empty() && + mExtendedStats.empty()) + { + reportAlways("StatDb: no stats found"); + addDefaultStats(); + } } } diff --git a/src/resources/db/statdb.h b/src/resources/db/statdb.h index 5a5d3920a..d9aaf1568 100644 --- a/src/resources/db/statdb.h +++ b/src/resources/db/statdb.h @@ -39,9 +39,11 @@ namespace StatDb void loadXmlFile(const std::string &fileName, const SkipError skipError); - void addBasicStats(); + void addDefaultStats(); - const std::vector &getExtraStats(); + const std::vector &getBasicStats(); + + const std::vector &getExtendedStats(); } // namespace StatDb #endif // RESOURCES_DB_STATDB_H -- cgit v1.2.3-70-g09d2