From b0238edbc3f125e5d7d9d1506f7c9b78a440a200 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 4 Oct 2013 01:41:35 +0300 Subject: add generic way for loading item sounds. --- src/resources/db/itemdb.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/resources') 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 mTags; -} + std::map 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::const_iterator + it = mSoundNames.find(event); + if (it != mSoundNames.end()) { - itemInfo->addSound(SOUND_EVENT_MISS, filename, delay); + itemInfo->addSound((*it).second, filename, delay); } else { -- cgit v1.2.3-70-g09d2