ManaPlus
Functions
AvatarDB Namespace Reference

Functions

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

Function Documentation

◆ get()

BeingInfo * AvatarDB::get ( const BeingTypeId  id)

Definition at line 141 of file avatardb.cpp.

142 {
143  const BeingInfoIterator i = mAvatarInfos.find(id);
144  if (i == mAvatarInfos.end())
145  return BeingInfo::unknown;
146  return i->second;
147 }
BeingInfos::iterator BeingInfoIterator
Definition: beinginfo.h:410
static BeingInfo * unknown
Definition: beinginfo.h:56

References anonymous_namespace{avatardb.cpp}::mAvatarInfos, and BeingInfo::unknown.

Referenced by Being::setSubtype(), and NpcDialog::showAvatar().

◆ load()

void AvatarDB::load ( )

Definition at line 46 of file avatardb.cpp.

47 {
48  if (mLoaded)
49  unload();
50 
51  logger->log1("Initializing avatar database...");
53  loadXmlFile(paths.getStringValue("avatarsPatchFile"), SkipError_true);
54  loadXmlDir("avatarsPatchDir", loadXmlFile)
55 }
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{avatardb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by ItemDB::get(), ColorDB::getHairColorName(), Loader::getImage(), Loader::getMusic(), Loader::getRescaled(), Loader::getShader(), Loader::getShaderProgram(), Loader::getSoundEffect(), Loader::getSprite(), Loader::getSubImage(), Loader::getSubImageSet(), Loader::getXml(), DbManager::loadDb(), Theme::loadRect(), Theme::loadSkinRect(), and PopupMenu::showPlayerGMCommands().

◆ loadXmlFile()

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

Definition at line 57 of file avatardb.cpp.

59 {
62  skipError);
63  XmlNodeConstPtrConst rootNode = doc.rootNode();
64 
65  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "avatars"))
66  {
67  logger->log("Avatars Database: Error while loading %s!",
68  fileName.c_str());
69  mLoaded = true;
70  return;
71  }
72 
73  for_each_xml_child_node(avatarNode, rootNode)
74  {
75  if (xmlNameEqual(avatarNode, "include"))
76  {
77  const std::string name = XML::getProperty(avatarNode, "name", "");
78  if (!name.empty())
79  loadXmlFile(name, skipError);
80  continue;
81  }
82 
83  if (!xmlNameEqual(avatarNode, "avatar"))
84  continue;
85 
87  avatarNode, "id", 0), BeingTypeId);
88  BeingInfo *currentInfo = nullptr;
89  if (mAvatarInfos.find(id) != mAvatarInfos.end())
90  currentInfo = mAvatarInfos[id];
91  if (currentInfo == nullptr)
92  currentInfo = new BeingInfo;
93 
94  currentInfo->setName(XML::langProperty(
95  // TRANSLATORS: unknown info name
96  avatarNode, "name", _("unnamed")));
97 
98  currentInfo->setTargetOffsetX(XML::getProperty(avatarNode,
99  "targetOffsetX", 0));
100 
101  currentInfo->setTargetOffsetY(XML::getProperty(avatarNode,
102  "targetOffsetY", 0));
103 
104  currentInfo->setWidth(XML::getProperty(avatarNode,
105  "width", 0));
106  currentInfo->setHeight(XML::getProperty(avatarNode,
107  "height", 0));
108 
109  SpriteDisplay display;
110 
111  // iterate <sprite>s and <sound>s
112  for_each_xml_child_node(spriteNode, avatarNode)
113  {
114  if (xmlNameEqual(spriteNode, "sprite"))
115  {
116  if (!XmlHaveChildContent(spriteNode))
117  continue;
118 
119  SpriteReference *const currentSprite = new SpriteReference;
120  currentSprite->sprite = XmlChildContent(spriteNode);
121  currentSprite->variant = XML::getProperty(
122  spriteNode, "variant", 0);
123  display.sprites.push_back(currentSprite);
124  }
125  }
126  currentInfo->setDisplay(display);
127  mAvatarInfos[id] = currentInfo;
128  }
129 
130  mLoaded = true;
131 }
int BeingTypeId
Definition: beingtypeid.h:30
void setName(const std::string &name)
Definition: beinginfo.h:65
void setDisplay(const SpriteDisplay &display)
Definition: beinginfo.cpp:127
void setTargetOffsetY(const int n)
Definition: beinginfo.h:138
void setWidth(const int n)
Definition: beinginfo.h:210
void setHeight(const int n)
Definition: beinginfo.h:213
void setTargetOffsetX(const int n)
Definition: beinginfo.h:132
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define _(s)
Definition: gettext.h:35
#define fromInt(val, name)
Definition: intdefines.h:46
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
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
std::vector< SpriteReference * > sprites
Definition: spritedisplay.h:47
std::string sprite
std::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References _, fileName, for_each_xml_child_node, fromInt, XML::getProperty(), XML::langProperty(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{avatardb.cpp}::mAvatarInfos, anonymous_namespace{avatardb.cpp}::mLoaded, XML::Document::rootNode(), BeingInfo::setDisplay(), BeingInfo::setHeight(), BeingInfo::setName(), BeingInfo::setTargetOffsetX(), BeingInfo::setTargetOffsetY(), BeingInfo::setWidth(), SpriteReference::sprite, SpriteDisplay::sprites, UseVirtFs_true, and SpriteReference::variant.

◆ unload()

void AvatarDB::unload ( )

Definition at line 133 of file avatardb.cpp.

134 {
135  logger->log1("Unloading avatar database...");
137  mAvatarInfos.clear();
138  mLoaded = false;
139 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), Logger::log1(), logger, anonymous_namespace{avatardb.cpp}::mAvatarInfos, and anonymous_namespace{avatardb.cpp}::mLoaded.

Referenced by DbManager::unloadDb().