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 EmoteInfoget (const int id, const bool allowNull)
 
const EmoteInfoget2 (int id, const bool allowNull)
 
const EmoteSpritegetSprite (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 68 of file emotedb.h.

Function Documentation

◆ get()

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

Definition at line 257 of file emotedb.cpp.

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

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 272 of file emotedb.cpp.

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

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 310 of file emotedb.cpp.

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

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 291 of file emotedb.cpp.

292 {
293  const EmoteInfo *const info = get(id, allowNull);
294  if (info == nullptr)
295  return nullptr;
296 
297  return info->sprites.front();
298 }

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

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

◆ load()

void EmoteDB::load ( )

Definition at line 47 of file emotedb.cpp.

48 {
49  if (mLoaded)
50  unload();
51 
52  logger->log1("Initializing emote database...");
53 
54  EmoteSprite *const unknownSprite = new EmoteSprite;
56  "sprites"), paths.getStringValue(
57  "spriteErrorFile")),
58  0);
59  unknownSprite->name = "unknown";
60  unknownSprite->id = 0;
61  mUnknown.sprites.push_back(unknownSprite);
62 
63  mLastEmote = 0;
65  loadXmlFile(paths.getStringValue("emotesPatchFile"), SkipError_true);
66  loadXmlDir("emotesPatchDir", loadXmlFile)
67  loadSpecialXmlFile("graphics/sprites/manaplus_emotes.xml",
69 
70  mLoaded = true;
71 }

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 150 of file emotedb.cpp.

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

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 73 of file emotedb.cpp.

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

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 305 of file emotedb.cpp.

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

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(), MobileOpenGLGraphics::drawLineArrays(), MobileOpenGL2Graphics::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::FsZip::rwops_read(), VirtFs::FsDir::rwops_read(), VirtFs::FsDir::rwops_write(), Inventory::setCards(), Item::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 ( )

Clear the chars data

Definition at line 226 of file emotedb.cpp.

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

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().

reportAlways
#define reportAlways(...)
Definition: checkutils.h:252
anonymous_namespace{emotedb.cpp}::mUnknown
EmoteInfo mUnknown
Definition: emotedb.cpp:42
anonymous_namespace{emotedb.cpp}::mEmotesAlt
EmoteToEmote mEmotesAlt
Definition: emotedb.cpp:41
SkipError_true
const bool SkipError_true
Definition: skiperror.h:29
Client::isTmw
static bool isTmw()
Definition: client.cpp:837
anonymous_namespace{emotedb.cpp}::mEmoteInfos
EmoteInfos mEmoteInfos
Definition: emotedb.cpp:40
Net::unload
void unload()
Definition: net.cpp:179
EmoteDB::loadSpecialXmlFile
void loadSpecialXmlFile(const std::string &fileName, const SkipError skipError)
Definition: emotedb.cpp:150
paths
Configuration paths
Definition: configuration.cpp:55
AttributesEnum::get
AttributesT get(const std::string &key)
Definition: attributesstrings.cpp:32
SkipError_false
const bool SkipError_false
Definition: skiperror.h:29
AnimatedSprite::load
static AnimatedSprite * load(const std::string &filename, const int variant)
Definition: animatedsprite.cpp:71
pathJoin
std::string pathJoin(std::string str1, const std::string &str2)
Definition: stringutils.cpp:1036
XML::Document
Definition: libxml.h:52
XML
Definition: libxml.cpp:84
XML::getProperty
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:173
logger
Logger * logger
Definition: logger.cpp:88
AttributesEnum::find
bool find(const std::string &key)
Definition: attributesstrings.cpp:32
Actions::info
bool info(InputEvent &event)
Definition: commands.cpp:56
if
if(!vert) return
fileName
std::string fileName
Definition: testmain.cpp:38
loadXmlDir
#define loadXmlDir(name, function)
Definition: beingcommon.h:38
loadXmlFile
static void loadXmlFile(const std::string &file, const std::string &name, BadgesInfos &arr, const SkipError skipError)
Definition: badgesdb.cpp:42
UseVirtFs_true
const bool UseVirtFs_true
Definition: usevirtfs.h:29
EmoteSprite::sprite
const AnimatedSprite * sprite
Definition: emotesprite.h:41
Configuration::getStringValue
std::string getStringValue(const std::string &key) const
Definition: configuration.cpp:487
anonymous_namespace{emotedb.cpp}::mLoaded
bool mLoaded
Definition: emotedb.cpp:43
XML::langProperty
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:257
Logger::log1
void log1(const char *const log_text)
Definition: logger.cpp:237
EmoteSprite::name
std::string name
Definition: emotesprite.h:43
EmoteSprite::id
int id
Definition: emotesprite.h:42
anonymous_namespace{emotedb.cpp}::mLastEmote
int mLastEmote
Definition: emotedb.cpp:44
EmoteSprite
Definition: emotesprite.h:31
new
#define new
Definition: debug_new.h:147
EmoteInfo
Definition: emoteinfo.h:33
EmoteInfo::sprites
std::list< EmoteSprite * > sprites
Definition: emoteinfo.h:44
for_each_xml_child_node
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:160
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24