ManaPlus
Functions
SoundDB Namespace Reference

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
std::string & getSound (const int id)
 

Function Documentation

◆ getSound()

std::string & SoundDB::getSound ( const int  id)

Definition at line 95 of file sounddb.cpp.

96 {
97  if (id < 0 || id >= NotifyTypes::TYPE_END)
98  return mDefault;
99  return mSounds[id];
100 }
std::vector< std::string > mSounds
Definition: sounddb.cpp:37

References anonymous_namespace{sounddb.cpp}::mDefault, anonymous_namespace{sounddb.cpp}::mSounds, and NotifyTypes::TYPE_END.

Referenced by NotifyManager::notify().

◆ load()

void SoundDB::load ( )

Definition at line 40 of file sounddb.cpp.

41 {
42  unload();
43  logger->log1("Initializing sound database...");
45  loadXmlFile(paths.getStringValue("soundsPatchFile"), SkipError_true);
46  loadXmlDir("soundsPatchDir", loadXmlFile)
47 }
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, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 49 of file sounddb.cpp.

51 {
54  skipError);
55  XmlNodeConstPtrConst root = doc->rootNode();
56 
57  if ((root == nullptr) || !xmlNameEqual(root, "sounds"))
58  {
59  delete doc;
60  return;
61  }
62 
63  for_each_xml_child_node(node, root)
64  {
65  if (xmlNameEqual(node, "include"))
66  {
67  const std::string name = XML::getProperty(node, "name", "");
68  if (!name.empty())
69  loadXmlFile(name, skipError);
70  continue;
71  }
72  else if (xmlNameEqual(node, "sound"))
73  {
74  const std::string name = XML::getProperty(node, "name", "");
75  const int id = NotifyManager::getIndexBySound(name);
76  if (id != 0)
77  {
78  const std::string value = XML::getProperty(node, "value", "");
79  mSounds[id] = value;
80  }
81  }
82  }
83 
84  delete doc;
85 }
xmlNodePtr rootNode()
Definition: libxml.cpp:169
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
int getIndexBySound(const std::string &sound)
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References fileName, for_each_xml_child_node, NotifyManager::getIndexBySound(), XML::getProperty(), loadXmlFile(), anonymous_namespace{sounddb.cpp}::mSounds, XML::Document::rootNode(), and UseVirtFs_true.

◆ unload()

void SoundDB::unload ( )

Definition at line 87 of file sounddb.cpp.

88 {
89  logger->log1("Unloading sound database...");
91  for (int f = 0; f < NotifyTypes::TYPE_END; f ++)
92  mSounds[f].clear();
93 }
void clear()
Definition: playerinfo.cpp:452

References PlayerInfo::clear(), Logger::log1(), logger, anonymous_namespace{sounddb.cpp}::mSounds, and NotifyTypes::TYPE_END.

Referenced by DbManager::unloadDb().