ManaPlus
Typedefs | Functions
EmoteDB Namespace Reference

Typedefs

typedef EmoteInfos::iterator EmoteInfosIterator
 

Functions

void load ()
 
void loadXmlFile (const std::string &fileName, const SkipError skipError)
 
void loadSpecialXmlFile (const std::string &fileName, const SkipError skipError)
 
void unload ()
 
const EmoteInfo * get (const int id, const bool allowNull)
 
const EmoteInfo * get2 (int id, const bool allowNull)
 
const EmoteSprite * getSprite (const int id, const bool allowNull)
 
const int & getLast () A_CONST
 
int getIdByIndex (const int index)
 
int size ()
 

Detailed Description

Emote information database.

Typedef Documentation

◆ EmoteInfosIterator

typedef EmoteInfos::iterator EmoteDB::EmoteInfosIterator

Definition at line 69 of file emotedb.h.

Function Documentation

◆ get()

const EmoteInfo * EmoteDB::get ( const int  id,
const bool  allowNull 
)

Definition at line 258 of file emotedb.cpp.

259 {
260  const EmoteInfos::const_iterator i = mEmoteInfos.find(id);
261 
262  if (i == mEmoteInfos.end())
263  {
264  if (allowNull)
265  return nullptr;
266  reportAlways("EmoteDB: Warning, unknown emote ID %d requested",
267  id)
268  return &mUnknown;
269  }
270  return i->second;
271 }
#define reportAlways(...)
Definition: checkutils.h:253

References anonymous_namespace{emotedb.cpp}::mEmoteInfos, anonymous_namespace{emotedb.cpp}::mUnknown, and reportAlways.

◆ get2()

const EmoteInfo * EmoteDB::get2 ( int  id,
const bool  allowNull 
)

Definition at line 273 of file emotedb.cpp.

274 {
275  const EmoteToEmote::const_iterator it = mEmotesAlt.find(id);
276  if (it != mEmotesAlt.end())
277  id = (*it).second;
278 
279  const EmoteInfos::const_iterator i = mEmoteInfos.find(id);
280 
281  if (i == mEmoteInfos.end())
282  {
283  if (allowNull)
284  return nullptr;
285  reportAlways("EmoteDB: Warning, unknown emote ID %d requested",
286  id)
287  return &mUnknown;
288  }
289  return i->second;
290 }

References anonymous_namespace{emotedb.cpp}::mEmoteInfos, anonymous_namespace{emotedb.cpp}::mEmotesAlt, anonymous_namespace{emotedb.cpp}::mUnknown, and reportAlways.

Referenced by Being::setEmote().

◆ getIdByIndex()

int EmoteDB::getIdByIndex ( const int  index)

Definition at line 311 of file emotedb.cpp.

312 {
313  if (index < 0 || index >= static_cast<signed int>(mEmoteInfos.size()))
314  return 0;
315  EmoteInfos::const_iterator it = mEmoteInfos.begin();
316  for (int f = 0; f < index; f ++)
317  ++ it;
318  return (*it).first;
319 }

References anonymous_namespace{emotedb.cpp}::mEmoteInfos.

◆ getLast()

const int & EmoteDB::getLast ( )

◆ getSprite()

const EmoteSprite * EmoteDB::getSprite ( const int  id,
const bool  allowNull 
)

Definition at line 292 of file emotedb.cpp.

293 {
294  const EmoteInfo *const info = get(id, allowNull);
295  if (info == nullptr)
296  return nullptr;
297 
298  return info->sprites.front();
299 }
bool info(InputEvent &event)
Definition: commands.cpp:57
AttributesT get(const std::string &key)

References AttributesEnum::get(), and Actions::info().

Referenced by EmoteShortcutContainer::EmoteShortcutContainer(), EmoteShortcut::load(), and ItemDB::load().

◆ load()

void EmoteDB::load ( )

Definition at line 48 of file emotedb.cpp.

49 {
50  if (mLoaded)
51  unload();
52 
53  logger->log1("Initializing emote database...");
54 
55  EmoteSprite *const unknownSprite = new EmoteSprite;
57  "sprites"), paths.getStringValue(
58  "spriteErrorFile")),
59  0);
60  unknownSprite->name = "unknown";
61  unknownSprite->id = 0;
62  mUnknown.sprites.push_back(unknownSprite);
63 
64  mLastEmote = 0;
66  loadXmlFile(paths.getStringValue("emotesPatchFile"), SkipError_true);
67  loadXmlDir("emotesPatchDir", loadXmlFile)
68  loadSpecialXmlFile("graphics/sprites/manaplus_emotes.xml",
70 
71  mLoaded = true;
72 }
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
static AnimatedSprite * load(const std::string &filename, const int variant)
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 loadSpecialXmlFile(const std::string &fileName, const SkipError skipError)
Definition: emotedb.cpp:151
void unload()
Definition: net.cpp:180
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30
std::string pathJoin(std::string str1, const std::string &str2)
std::list< EmoteSprite * > sprites
Definition: emoteinfo.h:45
const AnimatedSprite * sprite
Definition: emotesprite.h:42
std::string name
Definition: emotesprite.h:44

References Configuration::getStringValue(), EmoteSprite::id, AnimatedSprite::load(), loadSpecialXmlFile(), loadXmlDir, loadXmlFile(), Logger::log1(), logger, anonymous_namespace{emotedb.cpp}::mLastEmote, anonymous_namespace{emotedb.cpp}::mLoaded, anonymous_namespace{emotedb.cpp}::mUnknown, EmoteSprite::name, pathJoin(), paths, SkipError_false, SkipError_true, EmoteSprite::sprite, EmoteInfo::sprites, and Net::unload().

Referenced by DbManager::loadDb().

◆ loadSpecialXmlFile()

void EmoteDB::loadSpecialXmlFile ( const std::string &  fileName,
const SkipError  skipError 
)

Definition at line 151 of file emotedb.cpp.

153 {
154  XML::Document doc(fileName, UseVirtFs_true, skipError);
155  XmlNodePtrConst rootNode = doc.rootNode();
156 
157  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "emotes"))
158  {
159  logger->log1("Emote Database: Error while loading"
160  " manaplus_emotes.xml!");
161  return;
162  }
163 
164  // iterate <emote>s
165  for_each_xml_child_node(emoteNode, rootNode)
166  {
167  if (xmlNameEqual(emoteNode, "include"))
168  {
169  const std::string name = XML::getProperty(emoteNode, "name", "");
170  if (!name.empty())
171  loadSpecialXmlFile(name, skipError);
172  continue;
173  }
174  else if (!xmlNameEqual(emoteNode, "emote"))
175  {
176  continue;
177  }
178 
179  const int id = XML::getProperty(emoteNode, "id", -1);
180  if (id == -1)
181  {
182  reportAlways("Emote Database: Emote with missing ID in "
183  "manaplus_emotes.xml!")
184  continue;
185  }
186  const int altId = XML::getProperty(emoteNode, "altid", -1);
187 
188  EmoteInfo *currentInfo = nullptr;
189  if (mEmoteInfos.find(id) != mEmoteInfos.end())
190  currentInfo = mEmoteInfos[id];
191  if (currentInfo == nullptr)
192  currentInfo = new EmoteInfo;
193  currentInfo->time = XML::getProperty(emoteNode, "time", 500);
194  currentInfo->effectId = XML::getProperty(emoteNode, "effect", -1);
195 
196  for_each_xml_child_node(spriteNode, emoteNode)
197  {
198  if (!XmlHaveChildContent(spriteNode))
199  continue;
200 
201  if (xmlNameEqual(spriteNode, "sprite"))
202  {
203  EmoteSprite *const currentSprite = new EmoteSprite;
204  currentSprite->sprite = AnimatedSprite::load(pathJoin(
205  paths.getStringValue("sprites"),
206  XmlChildContent(spriteNode)),
207  XML::getProperty(spriteNode, "variant", 0));
208  currentSprite->name = XML::langProperty(
209  spriteNode, "name", "");
210  currentSprite->id = id;
211  currentInfo->sprites.push_back(currentSprite);
212  }
213  else if (xmlNameEqual(spriteNode, "particlefx"))
214  {
215  currentInfo->particles.push_back(XmlChildContent(spriteNode));
216  }
217  }
218  mEmoteInfos[id] = currentInfo;
219  if (altId != -1)
220  mEmotesAlt[altId] = id;
221 
222  if (id > mLastEmote)
223  mLastEmote = id;
224  }
225 }
#define new
Definition: debug_new.h:147
if(!vert) return
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
bool find(const std::string &key)
Definition: libxml.cpp:86
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::string fileName
Definition: testmain.cpp:39
const bool UseVirtFs_true
Definition: usevirtfs.h:30

References EmoteInfo::effectId, fileName, for_each_xml_child_node, XML::getProperty(), Configuration::getStringValue(), EmoteSprite::id, XML::langProperty(), AnimatedSprite::load(), Logger::log1(), logger, anonymous_namespace{emotedb.cpp}::mEmoteInfos, anonymous_namespace{emotedb.cpp}::mEmotesAlt, anonymous_namespace{emotedb.cpp}::mLastEmote, EmoteSprite::name, EmoteInfo::particles, pathJoin(), paths, reportAlways, XML::Document::rootNode(), EmoteSprite::sprite, EmoteInfo::sprites, EmoteInfo::time, and UseVirtFs_true.

Referenced by load().

◆ loadXmlFile()

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

Definition at line 74 of file emotedb.cpp.

76 {
77  XML::Document doc(fileName, UseVirtFs_true, skipError);
78  XmlNodePtrConst rootNode = doc.rootNode();
79 
80  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "emotes"))
81  {
82  logger->log("Emote Database: Error while loading %s!",
83  fileName.c_str());
84  return;
85  }
86 
87  // iterate <emote>s
88  for_each_xml_child_node(emoteNode, rootNode)
89  {
90  if (xmlNameEqual(emoteNode, "include"))
91  {
92  const std::string name = XML::getProperty(emoteNode, "name", "");
93  if (!name.empty())
94  loadXmlFile(name, skipError);
95  continue;
96  }
97  else if (!xmlNameEqual(emoteNode, "emote"))
98  {
99  continue;
100  }
101 
102  const int id = XML::getProperty(emoteNode, "id", -1);
103  // skip hight images
104  if (id > 19 || (Client::isTmw() && id > 13))
105  continue;
106 
107  if (id == -1)
108  {
109  reportAlways("Emote Database: Emote with missing ID in %s!",
110  paths.getStringValue("emotesFile").c_str())
111  continue;
112  }
113  EmoteInfo *currentInfo = nullptr;
114  if (mEmoteInfos.find(id) != mEmoteInfos.end())
115  currentInfo = mEmoteInfos[id];
116  else
117  currentInfo = new EmoteInfo;
118  if (currentInfo == nullptr)
119  continue;
120  currentInfo->time = XML::getProperty(emoteNode, "time", 500);
121  currentInfo->effectId = XML::getProperty(emoteNode, "effect", -1);
122 
123  for_each_xml_child_node(spriteNode, emoteNode)
124  {
125  if (!XmlHaveChildContent(spriteNode))
126  continue;
127 
128  if (xmlNameEqual(spriteNode, "sprite"))
129  {
130  EmoteSprite *const currentSprite = new EmoteSprite;
131  currentSprite->sprite = AnimatedSprite::load(pathJoin(
132  paths.getStringValue("sprites"),
133  XmlChildContent(spriteNode)),
134  XML::getProperty(spriteNode, "variant", 0));
135  currentSprite->name = XML::langProperty(
136  spriteNode, "name", "");
137  currentSprite->id = id;
138  currentInfo->sprites.push_back(currentSprite);
139  }
140  else if (xmlNameEqual(spriteNode, "particlefx"))
141  {
142  currentInfo->particles.push_back(XmlChildContent(spriteNode));
143  }
144  }
145  mEmoteInfos[id] = currentInfo;
146  if (id > mLastEmote)
147  mLastEmote = id;
148  }
149 }
static bool isTmw()
Definition: client.cpp:838
void log(const char *const log_text,...)
Definition: logger.cpp:269

References EmoteInfo::effectId, fileName, for_each_xml_child_node, XML::getProperty(), Configuration::getStringValue(), EmoteSprite::id, Client::isTmw(), XML::langProperty(), AnimatedSprite::load(), loadXmlFile(), Logger::log(), logger, anonymous_namespace{emotedb.cpp}::mEmoteInfos, anonymous_namespace{emotedb.cpp}::mLastEmote, EmoteSprite::name, EmoteInfo::particles, pathJoin(), paths, reportAlways, XML::Document::rootNode(), EmoteSprite::sprite, EmoteInfo::sprites, EmoteInfo::time, and UseVirtFs_true.

◆ size()

int EmoteDB::size ( )

Definition at line 306 of file emotedb.cpp.

307 {
308  return static_cast<signed int>(mEmoteInfos.size());
309 }

References anonymous_namespace{emotedb.cpp}::mEmoteInfos.

Referenced by Net::Download::adlerBuffer(), LayoutArray::align(), alloc_mem(), Setup_Theme::apply(), Logger::assertLog(), BrowserBox::calcHeight(), CharCreateDialog::CharCreateDialog(), PlayerRelationsManager::checkName(), Ea::LoginHandler::chooseServer(), ActorSprite::cleanupTargetCursors(), CrazyMoves::crazyMoveAe(), cursorSize(), Font::doClean(), XML::Document::Document(), NormalOpenGLGraphics::drawLineArrayf(), NormalOpenGLGraphics::drawLineArrayi(), MobileOpenGL2Graphics::drawLineArrays(), MobileOpenGLGraphics::drawLineArrays(), ModernOpenGLGraphics::drawLineArrays(), NormalOpenGLGraphics::drawQuadArrayfi(), NormalOpenGLGraphics::drawQuadArrayfiCached(), NormalOpenGLGraphics::drawQuadArrayii(), NormalOpenGLGraphics::drawQuadArrayiiCached(), MobileOpenGL2Graphics::drawTriangleArray(), ModernOpenGLGraphics::drawTriangleArray(), MobileOpenGLGraphics::drawTriangleArrayfs(), MobileOpenGLGraphics::drawTriangleArrayfsCached(), DyePalette::DyePalette(), encodeStr(), EquipmentWindow::EquipmentWindow(), extractNameFromSprite(), Map::findPath(), Font::Font(), TextBox::getCaretPosition(), UpdaterWindow::getFileHash(), IgnoreChoicesListModel::getNumberOfElements(), getSafeUtf8String(), LayoutArray::getSize(), LayoutArray::getSizes(), Map::indexTilesets(), ActorSprite::initTargetCursor(), InventoryWindow::InventoryWindow(), PlayerRelationsManager::isGoodName(), NpcDialog::itemCraftRequest(), NpcDialog::itemIndexRequest(), NpcDialog::itemRequest(), TextBox::keyPressed(), Font::loadFont(), SkinHelper::loadList(), Logger::log(), Logger::log_r(), WhoIsOnline::memoryWrite(), UpdaterWindow::memoryWrite(), PoParser::openFile(), Font::openFont(), operator new(), operator new[](), Catch::CompositeGenerator< T >::operator T(), mse::msevector< _Ty, _A >::mm_const_iterator_type::points_to_an_item(), mse::msevector< _Ty, _A >::mm_iterator_type::points_to_an_item(), EAthena::InventoryRecv::processCartInfo(), Ea::PlayerRecv::processMapMusic(), EAthena::PlayerRecv::processOnlineList(), Ea::InventoryRecv::processPlayerStorageStatus(), readColor(), LayoutArray::reflow(), removeSpriteIndex(), LayoutArray::resizeGrid(), VirtFs::FsDir::rwops_read(), VirtFs::FsZip::rwops_read(), VirtFs::FsDir::rwops_write(), Item::setCards(), Inventory::setCards(), TextBox::setCaretColumn(), TextBox::setCaretPosition(), setConfigDefaults2(), Minimap::setMap(), KeyListModel::setSize(), BeingInfo::setTargetCursorSize(), Setup_Theme::Setup_Theme(), ShopWindow::ShopWindow(), PopupMenu::showAttackMonsterPopup(), AtlasManager::simpleSort(), Particle::update(), StaticBrowserBox::updateHeight(), Net::Download::writeFunction(), xmlErrorLogger(), and ObjectsLayer::~ObjectsLayer().

◆ unload()

void EmoteDB::unload ( )

Definition at line 227 of file emotedb.cpp.

228 {
229  logger->log1("Unloading emote database...");
230  FOR_EACH (EmoteInfos::const_iterator, i, mEmoteInfos)
231  {
232  if (i->second != nullptr)
233  {
234  std::list<EmoteSprite*> &sprites = i->second->sprites;
235  while (!sprites.empty())
236  {
237  delete sprites.front()->sprite;
238  delete sprites.front();
239  sprites.pop_front();
240  }
241  delete i->second;
242  }
243  }
244 
245  mEmoteInfos.clear();
246 
247  std::list<EmoteSprite*> &sprites = mUnknown.sprites;
248  while (!sprites.empty())
249  {
250  delete sprites.front()->sprite;
251  delete sprites.front();
252  sprites.pop_front();
253  }
254 
255  mLoaded = false;
256 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References FOR_EACH, Logger::log1(), logger, anonymous_namespace{emotedb.cpp}::mEmoteInfos, anonymous_namespace{emotedb.cpp}::mLoaded, anonymous_namespace{emotedb.cpp}::mUnknown, and EmoteInfo::sprites.

Referenced by DbManager::unloadDb().