diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-10-04 01:41:35 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-10-04 01:41:35 +0300 |
commit | b0238edbc3f125e5d7d9d1506f7c9b78a440a200 (patch) | |
tree | 69c7b740ce8cb99b16aff72b77682dab685b7d73 /src | |
parent | fb03dee879ef921ac3c4cd834efeda439c25cd1b (diff) | |
download | manaplus-b0238edbc3f125e5d7d9d1506f7c9b78a440a200.tar.gz manaplus-b0238edbc3f125e5d7d9d1506f7c9b78a440a200.tar.bz2 manaplus-b0238edbc3f125e5d7d9d1506f7c9b78a440a200.tar.xz manaplus-b0238edbc3f125e5d7d9d1506f7c9b78a440a200.zip |
add generic way for loading item sounds.
Diffstat (limited to 'src')
-rw-r--r-- | src/resources/db/itemdb.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 19b618208..6f015b64e 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -39,9 +39,11 @@ namespace ItemDB::NamedItemInfos mNamedItemInfos; ItemInfo *mUnknown; bool mLoaded = false; + bool mConstructed = false; StringVect mTagNames; std::map<std::string, int> mTags; -} + std::map<std::string, SoundEvent> mSoundNames; +} // namespace // Forward declarations static void loadSpriteRef(ItemInfo *const itemInfo, const XmlNodePtr node); @@ -159,14 +161,26 @@ static ItemType itemTypeFromString(const std::string &name) } } +static void initStatic() +{ + mConstructed = true; + mSoundNames["hit"] = SOUND_EVENT_HIT; + mSoundNames["strike"] = SOUND_EVENT_MISS; + mSoundNames["miss"] = SOUND_EVENT_MISS; +} + void ItemDB::load() { if (mLoaded) unload(); - int tagNum = 0; logger->log1("Initializing item database..."); + if (!mConstructed) + initStatic(); + + int tagNum = 0; + mTags.clear(); mTagNames.clear(); mTagNames.push_back("All"); @@ -718,13 +732,11 @@ void loadSoundRef(ItemInfo *const itemInfo, const XmlNodePtr node) node->xmlChildrenNode->content); const int delay = XML::getProperty(node, "delay", 0); - if (event == "hit") - { - itemInfo->addSound(SOUND_EVENT_HIT, filename, delay); - } - else if (event == "strike" || event == "miss") + const std::map<std::string, SoundEvent>::const_iterator + it = mSoundNames.find(event); + if (it != mSoundNames.end()) { - itemInfo->addSound(SOUND_EVENT_MISS, filename, delay); + itemInfo->addSound((*it).second, filename, delay); } else { |