diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-08-26 16:55:05 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-08-26 16:55:05 +0200 |
commit | 6d9dbf93e6c0247cb9b19d3f52a1837a5833b22d (patch) | |
tree | 4e6e178095ac8cf89dc0dba4f532913891305436 /src/resources/itemdb.h | |
parent | ee8f131b49bb9b1d66cac3840b3c566eb49bcf3f (diff) | |
download | mana-6d9dbf93e6c0247cb9b19d3f52a1837a5833b22d.tar.gz mana-6d9dbf93e6c0247cb9b19d3f52a1837a5833b22d.tar.bz2 mana-6d9dbf93e6c0247cb9b19d3f52a1837a5833b22d.tar.xz mana-6d9dbf93e6c0247cb9b19d3f52a1837a5833b22d.zip |
Merged testing branch into master.
Diffstat (limited to 'src/resources/itemdb.h')
-rw-r--r-- | src/resources/itemdb.h | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index be023073..e4146131 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -26,45 +26,67 @@ #include <map> #include <string> +#include "utils/xml.h" + class ItemInfo; +class SpriteDisplay; /** * Item information database. */ -namespace ItemDB +class ItemDB { - /** - * Loads the item data from <code>items.xml</code>. - */ - void load(); - - /** - * Frees item data. - */ - void unload(); - - bool exists(int id); - - const ItemInfo &get(int id); - const ItemInfo &get(const std::string &name); - - struct Stat - { - Stat(const std::string &tag, - const std::string &format): - tag(tag), - format(format) - {} - - std::string tag; - std::string format; - }; - - void setStatsList(const std::list<Stat> &stats); - - // Items database - typedef std::map<int, ItemInfo*> ItemInfos; - typedef std::map<std::string, ItemInfo*> NamedItemInfos; -} + public: + ItemDB() : mLoaded(false) { load(); } + + ~ItemDB() { unload(); } + /** + * Loads the item data from <code>items.xml</code>. + */ + void load(); + + /** + * Frees item data. + */ + void unload(); + + bool exists(int id); + + const ItemInfo &get(int id); + const ItemInfo &get(const std::string &name); + + class Stat + { + public: + Stat(const std::string &tag, + const std::string &format): + tag(tag), format(format) {} + + bool operator ==(std::string &name) const { return tag == name; } + + private: + std::string tag; + std::string format; + friend class ItemDB; + }; + + void setStatsList(const std::list<Stat> &stats); + + private: + void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node); + void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node); + void loadFloorSprite(SpriteDisplay *display, xmlNodePtr node); + + // Items database + typedef std::map<int, ItemInfo*> ItemInfos; + typedef std::map<std::string, ItemInfo*> NamedItemInfos; + + ItemInfos mItemInfos; + NamedItemInfos mNamedItemInfos; + ItemInfo *mUnknown; + bool mLoaded; +}; + +extern ItemDB *itemDb; #endif |