diff options
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 |