ManaPlus
Functions
StatDb Namespace Reference

Functions

void load ()
 
void unload ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void addDefaultStats ()
 
const std::vector< BasicStat > & getBasicStats ()
 
const std::vector< BasicStat > & getStats (const std::string &page)
 
const std::vector< std::string > & getPages ()
 

Function Documentation

◆ addDefaultStats()

void StatDb::addDefaultStats ( )

Definition at line 44 of file statdb.cpp.

45 {
47  "str",
48  // TRANSLATORS: player stat
49  _("Strength")));
51  "agi",
52  // TRANSLATORS: player stat
53  _("Agility")));
55  "vit",
56  // TRANSLATORS: player stat
57  _("Vitality")));
59  "int",
60  // TRANSLATORS: player stat
61  _("Intelligence")));
63  "dex",
64  // TRANSLATORS: player stat
65  _("Dexterity")));
67  "luk",
68  // TRANSLATORS: player stat
69  _("Luck")));
70 }
#define _(s)
Definition: gettext.h:35
std::vector< BasicStat > mBasicStats
Definition: statdb.cpp:39

References _, anonymous_namespace{statdb.cpp}::mBasicStats, Attributes::PLAYER_AGI, Attributes::PLAYER_DEX, Attributes::PLAYER_INT, Attributes::PLAYER_LUK, Attributes::PLAYER_STR, and Attributes::PLAYER_VIT.

Referenced by loadXmlFile().

◆ getBasicStats()

const std::vector< BasicStat > & StatDb::getBasicStats ( )

Definition at line 72 of file statdb.cpp.

73 {
74  return mBasicStats;
75 }

References anonymous_namespace{statdb.cpp}::mBasicStats.

Referenced by StatsPageBasic::StatsPageBasic().

◆ getPages()

const std::vector< std::string > & StatDb::getPages ( )

Definition at line 82 of file statdb.cpp.

83 {
84  return mPages;
85 }
std::vector< std::string > mPages
Definition: statdb.cpp:41

References anonymous_namespace{statdb.cpp}::mPages.

Referenced by StatusWindow::addTabs().

◆ getStats()

const std::vector< BasicStat > & StatDb::getStats ( const std::string &  page)

Definition at line 77 of file statdb.cpp.

78 {
79  return mStats[page];
80 }
std::map< std::string, std::vector< BasicStat > > mStats
Definition: statdb.cpp:40

References anonymous_namespace{statdb.cpp}::mStats.

Referenced by StatsPage::StatsPage().

◆ load()

void StatDb::load ( )

Definition at line 87 of file statdb.cpp.

88 {
89  if (mLoaded)
90  unload();
91 
92  logger->log1("Initializing stat database...");
93 
96  loadXmlDir("statPatchDir", loadXmlFile)
97  mLoaded = true;
98 }
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:43
#define loadXmlDir(name, function)
Definition: beingcommon.h:39
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:238
Configuration paths
Logger * logger
Definition: logger.cpp:89
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30

References Configuration::getStringValue(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, anonymous_namespace{statdb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

void StatDb::loadXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 171 of file statdb.cpp.

173 {
176  skipError);
177  XmlNodeConstPtrConst rootNode = doc.rootNode();
178 
179  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "stats"))
180  {
181  logger->log("StatDb: Error while loading %s!",
182  fileName.c_str());
183  if (skipError == SkipError_false)
184  addDefaultStats();
185  return;
186  }
187 
188  for_each_xml_child_node(node, rootNode)
189  {
190  if (xmlNameEqual(node, "include"))
191  {
192  const std::string name = XML::getProperty(node, "name", "");
193  if (!name.empty())
194  loadXmlFile(name, skipError);
195  continue;
196  }
197  else if (xmlNameEqual(node, "basic"))
198  {
199  loadBasicStats(node);
200  }
201  else if (xmlNameEqual(node, "extended"))
202  {
203  // TRANSLATORS: stats page name
204  loadStats(node, _("Extended"));
205  }
206  else if (xmlNameEqual(node, "page"))
207  {
208  std::string page = XML::langProperty(node, "name", "");
209  if (page.empty())
210  {
211  reportAlways("Page without name in stats.xml")
212  page = "Unknown";
213  }
214  loadStats(node, page);
215  }
216  }
217  if (skipError == SkipError_false)
218  {
219  if (mBasicStats.empty() &&
220  mStats.empty())
221  {
222  reportAlways("StatDb: no stats found")
223  addDefaultStats();
224  }
225  }
226 }
#define reportAlways(...)
Definition: checkutils.h:253
void log(const char *const log_text,...)
Definition: logger.cpp:269
if(!vert) return
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
void addDefaultStats()
Definition: statdb.cpp:44
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
static void loadStats(const xmlNodePtr rootNode, const std::string &page)
Definition: statdb.cpp:135
static void loadBasicStats(const xmlNodePtr rootNode)
Definition: statdb.cpp:100
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References _, addDefaultStats(), fileName, for_each_xml_child_node, XML::getProperty(), XML::langProperty(), loadBasicStats(), loadStats(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{statdb.cpp}::mBasicStats, anonymous_namespace{statdb.cpp}::mStats, reportAlways, XML::Document::rootNode(), SkipError_false, and UseVirtFs_true.

◆ unload()

void StatDb::unload ( )

Definition at line 228 of file statdb.cpp.

229 {
230  logger->log1("Unloading stat database...");
231 
232  mBasicStats.clear();
233  mStats.clear();
234  mPages.clear();
235  mLoaded = false;
236 }

References Logger::log1(), logger, anonymous_namespace{statdb.cpp}::mBasicStats, anonymous_namespace{statdb.cpp}::mLoaded, anonymous_namespace{statdb.cpp}::mPages, and anonymous_namespace{statdb.cpp}::mStats.

Referenced by DbManager::unloadDb().