summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-12 06:44:16 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-12 06:44:16 -0600
commite2d60401eaf55abe9e2251854f3174ffe0f4ad9e (patch)
tree99be0ae61a6b4c97cafeb6458491f38cb7904d8a /src/resources
parent2eb027b0f7a67706df68fe29e605c5be7fc1d5c9 (diff)
downloadmana-client-e2d60401eaf55abe9e2251854f3174ffe0f4ad9e.tar.gz
mana-client-e2d60401eaf55abe9e2251854f3174ffe0f4ad9e.tar.bz2
mana-client-e2d60401eaf55abe9e2251854f3174ffe0f4ad9e.tar.xz
mana-client-e2d60401eaf55abe9e2251854f3174ffe0f4ad9e.zip
Move emote sprite loading into EmoteDB
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/emotedb.cpp24
-rw-r--r--src/resources/emotedb.h9
2 files changed, 23 insertions, 10 deletions
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index 5e9a146c..5bc8407a 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -21,6 +21,7 @@
#include "emotedb.h"
+#include "../animatedsprite.h"
#include "../log.h"
#include "../utils/xml.h"
@@ -41,9 +42,8 @@ void EmoteDB::load()
mLastEmote = 0;
EmoteSprite *unknownSprite = new EmoteSprite;
- unknownSprite->sprite = "error.xml";
+ unknownSprite->sprite = AnimatedSprite::load("error.xml");
unknownSprite->name = "unknown";
- unknownSprite->variant = 0;
mUnknown.sprites.push_back(unknownSprite);
logger->log("Initializing emote database...");
@@ -77,8 +77,10 @@ void EmoteDB::load()
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
EmoteSprite *currentSprite = new EmoteSprite;
- currentSprite->sprite = (const char*) spriteNode->xmlChildrenNode->content;
- currentSprite->variant = XML::getProperty(spriteNode, "variant", 0);
+ std::string file = "graphics/sprites/" + (std::string)
+ (const char*) spriteNode->xmlChildrenNode->content;
+ currentSprite->sprite = AnimatedSprite::load(file,
+ XML::getProperty(spriteNode, "variant", 0));
currentInfo->sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
@@ -102,6 +104,7 @@ void EmoteDB::unload()
{
while (!i->second->sprites.empty())
{
+ delete i->second->sprites.front()->sprite;
delete i->second->sprites.front();
i->second->sprites.pop_front();
}
@@ -112,6 +115,7 @@ void EmoteDB::unload()
while (!mUnknown.sprites.empty())
{
+ delete mUnknown.sprites.front()->sprite;
delete mUnknown.sprites.front();
mUnknown.sprites.pop_front();
}
@@ -119,21 +123,27 @@ void EmoteDB::unload()
mLoaded = false;
}
-const EmoteInfo& EmoteDB::get(int id)
+const EmoteInfo *EmoteDB::get(int id)
{
EmoteInfosIterator i = mEmoteInfos.find(id);
if (i == mEmoteInfos.end())
{
logger->log("EmoteDB: Warning, unknown emote ID %d requested", id);
- return mUnknown;
+ return &mUnknown;
}
else
{
- return *(i->second);
+ return i->second;
}
}
+const AnimatedSprite* EmoteDB::getAnimation(int id)
+{
+ const EmoteInfo *info = get(id);
+ return info->sprites.front()->sprite;
+}
+
const int& EmoteDB::getLast()
{
return mLastEmote;
diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h
index ad21722a..691881c8 100644
--- a/src/resources/emotedb.h
+++ b/src/resources/emotedb.h
@@ -26,11 +26,12 @@
#include <map>
#include <string>
+class AnimatedSprite;
+
struct EmoteSprite
{
- std::string sprite;
+ const AnimatedSprite *sprite;
std::string name;
- int variant;
};
struct EmoteInfo
@@ -50,7 +51,9 @@ namespace EmoteDB
void unload();
- const EmoteInfo& get(int id);
+ const EmoteInfo *get(int id);
+
+ const AnimatedSprite *getAnimation(int id);
const int& getLast();