diff options
Diffstat (limited to 'src/resources/db/statdb.cpp')
-rw-r--r-- | src/resources/db/statdb.cpp | 80 |
1 files changed, 26 insertions, 54 deletions
diff --git a/src/resources/db/statdb.cpp b/src/resources/db/statdb.cpp index d86ac5eb5..d29e012d6 100644 --- a/src/resources/db/statdb.cpp +++ b/src/resources/db/statdb.cpp @@ -1,9 +1,9 @@ /* - * The ManaPlus Client + * The ManaVerse Client * Copyright (C) 2016-2020 The ManaPlus Developers - * Copyright (C) 2020-2023 The ManaVerse Developers + * Copyright (C) 2020-2025 The ManaVerse Developers * - * This file is part of The ManaPlus Client. + * This file is part of The ManaVerse Client. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -97,72 +97,44 @@ void StatDb::load() mLoaded = true; } -static void loadBasicStats(XmlNodeConstPtr rootNode) -{ - const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE); - for_each_xml_child_node(node, rootNode) - { - if (xmlNameEqual(node, "stat")) - { - const std::string name = XML::getProperty(node, "name", ""); - const std::string attr = XML::getProperty(node, "attr", ""); - if (attr.empty() || AttributesEnum::find(attr) == false) - { - const int id = XML::getProperty(node, "id", 0); - if (id <= 0 || id >= maxAttr) - { - reportAlways("Wrong attr or id for basic " - "stat with name %s", - name.c_str()) - continue; - } - const std::string tag = XML::getProperty(node, "tag", ""); - mBasicStats.push_back(BasicStat(static_cast<AttributesT>(id), - tag, - name)); - } - else - { - const std::string tag = XML::getProperty(node, "tag", ""); - mBasicStats.push_back(BasicStat(AttributesEnum::get(attr), - tag, - name)); - } - } - } -} - static void loadStats(XmlNodeConstPtr rootNode, + const bool isBasic, const std::string &page) { const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE); - STD_VECTOR<BasicStat> &stats = mStats[page]; - mPages.push_back(page); + STD_VECTOR<BasicStat> &stats = isBasic ? mBasicStats : mStats[page]; + if (!isBasic) + mPages.push_back(page); + for_each_xml_child_node(node, rootNode) { if (xmlNameEqual(node, "stat")) { const std::string name = XML::getProperty(node, "name", ""); const std::string attr = XML::getProperty(node, "attr", ""); - if (attr.empty() || AttributesEnum::find(attr) == false) + const std::string tag = XML::getProperty(node, "tag", ""); + if (attr.empty() || AttributesEnum::contains(attr) == false) { const int id = XML::getProperty(node, "id", 0); if (id <= 0 || id >= maxAttr) { - reportAlways("Wrong attr or id for extended " - "stat with name %s", - name.c_str()) - continue; + reportAlways("Wrong attr or id for %s stat with name %s", + (isBasic ? "basic" : "extended"), + name.c_str()) + } + else + { + reportAlways("StatDb: stat name '%s' has empty attr field" + ", using legacy method (id).", + name.c_str()); + stats.push_back(BasicStat(static_cast<AttributesT>(id), + tag, name)); } - stats.push_back(BasicStat(static_cast<AttributesT>(id), - std::string(), - name)); } else { stats.push_back(BasicStat(AttributesEnum::get(attr), - std::string(), - name)); + tag, name)); } } } @@ -192,16 +164,15 @@ void StatDb::loadXmlFile(const std::string &fileName, const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadXmlFile(name, skipError); - continue; } else if (xmlNameEqual(node, "basic")) { - loadBasicStats(node); + loadStats(node, true, ""); } else if (xmlNameEqual(node, "extended")) { // TRANSLATORS: stats page name - loadStats(node, _("Extended")); + loadStats(node, false, _("Extended")); } else if (xmlNameEqual(node, "page")) { @@ -211,9 +182,10 @@ void StatDb::loadXmlFile(const std::string &fileName, reportAlways("Page without name in stats.xml") page = "Unknown"; } - loadStats(node, page); + loadStats(node, false, page); } } + if (skipError == SkipError_false) { if (mBasicStats.empty() && |