ManaPlus
Functions
PETDB Namespace Reference

Functions

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

Function Documentation

◆ get()

BeingInfo * PETDB::get ( const BeingTypeId  id)

Definition at line 157 of file petdb.cpp.

158 {
159  const BeingInfoIterator i = mPETInfos.find(id);
160 
161  if (i == mPETInfos.end())
162  {
163  reportAlways("PETDB: Warning, unknown PET ID %d requested",
164  toInt(id, int))
165  return BeingInfo::unknown;
166  }
167  return i->second;
168 }
BeingInfos::iterator BeingInfoIterator
Definition: beinginfo.h:410
#define reportAlways(...)
Definition: checkutils.h:253
static BeingInfo * unknown
Definition: beinginfo.h:56
#define toInt(val, name)
Definition: intdefines.h:47

References anonymous_namespace{petdb.cpp}::mPETInfos, reportAlways, toInt, and BeingInfo::unknown.

Referenced by BrowserBoxTools::replaceLinkCommands(), and Being::setSubtype().

◆ load()

void PETDB::load ( )

Definition at line 45 of file petdb.cpp.

46 {
47  if (mLoaded)
48  unload();
49 
50  logger->log1("Initializing PET database...");
53  loadXmlDir("petsPatchDir", loadXmlFile)
54  mLoaded = true;
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{petdb.cpp}::mLoaded, paths, SkipError_false, SkipError_true, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadXmlFile()

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

Definition at line 57 of file petdb.cpp.

59 {
62  skipError);
63  XmlNodeConstPtrConst rootNode = doc.rootNode();
64 
65  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "pets"))
66  {
67  logger->log("PET Database: Error while loading %s!",
68  fileName.c_str());
69  return;
70  }
71 
72  // iterate <pet>s
73  for_each_xml_child_node(petNode, rootNode)
74  {
75  if (xmlNameEqual(petNode, "include"))
76  {
77  const std::string name = XML::getProperty(petNode, "name", "");
78  if (!name.empty())
79  loadXmlFile(name, skipError);
80  continue;
81  }
82  else if (!xmlNameEqual(petNode, "pet"))
83  {
84  continue;
85  }
86 
88  petNode, "id", -1), BeingTypeId);
89  if (id == BeingTypeId_negOne)
90  {
91  reportAlways("PET Database: PET with missing ID in %s!",
92  paths.getStringValue("petsFile").c_str())
93  continue;
94  }
95 
96  BeingInfo *currentInfo = nullptr;
97  if (mPETInfos.find(id) != mPETInfos.end())
98  currentInfo = mPETInfos[id];
99  if (currentInfo == nullptr)
100  currentInfo = new BeingInfo;
101 
102  currentInfo->setName(XML::langProperty(petNode,
103  // TRANSLATORS: unknown info name
104  "name", _("pet")));
105 
106  currentInfo->setTargetSelection(XML::getBoolProperty(petNode,
107  "targetSelection", true));
108 
109  BeingCommon::readBasicAttributes(currentInfo, petNode, "talk");
110  BeingCommon::readWalkingAttributes(currentInfo, petNode, 0);
111 
112  currentInfo->setDeadSortOffsetY(XML::getProperty(petNode,
113  "deadSortOffsetY", 31));
114 
115  const std::string returnMessage = XML::langProperty(petNode,
116  // TRANSLATORS: popup menu item
117  // TRANSLATORS: pet return to egg
118  "removeMessage", _("Return to egg"));
119  currentInfo->setString(0, returnMessage);
120 
121  SpriteDisplay display;
122  for_each_xml_child_node(spriteNode, petNode)
123  {
124  if (!XmlHaveChildContent(spriteNode))
125  continue;
126 
127  if (xmlNameEqual(spriteNode, "sprite"))
128  {
129  SpriteReference *const currentSprite = new SpriteReference;
130  currentSprite->sprite = XmlChildContent(spriteNode);
131  currentSprite->variant =
132  XML::getProperty(spriteNode, "variant", 0);
133  display.sprites.push_back(currentSprite);
134  }
135  else if (xmlNameEqual(spriteNode, "particlefx"))
136  {
137  std::string particlefx = XmlChildContent(spriteNode);
138  display.particles.push_back(particlefx);
139  }
140  }
141 
142  currentInfo->setDisplay(display);
143 
144  mPETInfos[id] = currentInfo;
145  }
146 }
int BeingTypeId
Definition: beingtypeid.h:30
const BeingTypeId BeingTypeId_negOne
Definition: beingtypeid.h:31
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define new
Definition: debug_new.h:147
#define _(s)
Definition: gettext.h:35
if(!vert) return
#define fromInt(val, name)
Definition: intdefines.h:46
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
bool talk(InputEvent &event)
Definition: actions.cpp:55
bool find(const std::string &key)
void readBasicAttributes(BeingInfo *const info, xmlNode *const node, const std::string &hoverCursor)
Definition: beingcommon.cpp:37
void readWalkingAttributes(BeingInfo *const info, xmlNode *const node, const int moreBlockFlags)
Definition: beingcommon.cpp:60
Definition: libxml.cpp:86
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
bool getBoolProperty(const xmlNodePtr node, const char *const name, const bool def)
Definition: libxml.cpp:269
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
StringVect particles
Definition: spritedisplay.h:48
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 _, BeingTypeId_negOne, fileName, for_each_xml_child_node, fromInt, XML::getBoolProperty(), XML::getProperty(), Configuration::getStringValue(), XML::langProperty(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{petdb.cpp}::mPETInfos, SpriteDisplay::particles, paths, BeingCommon::readBasicAttributes(), BeingCommon::readWalkingAttributes(), reportAlways, XML::Document::rootNode(), BeingInfo::setDeadSortOffsetY(), BeingInfo::setDisplay(), BeingInfo::setName(), BeingInfo::setString(), BeingInfo::setTargetSelection(), SpriteReference::sprite, SpriteDisplay::sprites, UseVirtFs_true, and SpriteReference::variant.

◆ unload()

void PETDB::unload ( )

Definition at line 148 of file petdb.cpp.

149 {
150  logger->log1("Unloading PET database...");
152  mPETInfos.clear();
153 
154  mLoaded = false;
155 }
void delete_all(Container &c)
Definition: dtor.h:56

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

Referenced by DbManager::unloadDb().