Mana
Loading...
Searching...
No Matches
iteminfo.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "resources/iteminfo.h"
23
24#include "resources/itemdb.h"
25#include "configuration.h"
26
27const std::string &ItemInfo::getSprite(Gender gender, int race) const
28{
29 if (mView)
30 {
31 // Forward the request to the item defining how to view this item
32 return itemDb->get(mView).getSprite(gender, race);
33 }
34
35 auto i = mAnimationFiles.find(static_cast<int>(gender) + race * 4);
36
37 // Fall back to ignoring race
38 if (race != 0 && i == mAnimationFiles.end())
39 i = mAnimationFiles.find(static_cast<int>(gender));
40
41 static const std::string empty;
42 return i != mAnimationFiles.end() ? i->second : empty;
43}
44
45void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename)
46{
47 mSounds[event].push_back(paths.getStringValue("sfx") + filename);
48}
49
50const std::string &ItemInfo::getSound(EquipmentSoundEvent event) const
51{
52 static const std::string empty;
53 auto i = mSounds.find(event);
54 return i == mSounds.end() ? empty : i->second[rand() % i->second.size()];
55}
56
57void ItemInfo::setSprite(const std::string &animationFile, Gender gender, int race)
58{
59 mAnimationFiles[static_cast<int>(gender) + race * 4] = animationFile;
60}
Gender
Definition being.h:58
std::string getStringValue(const std::string &key) const
const ItemInfo & get(int id) const
Definition itemdb.cpp:145
std::map< EquipmentSoundEvent, std::vector< std::string > > mSounds
Stores the names of sounds to be played at certain event.
Definition iteminfo.h:153
const std::string & getSprite(Gender gender, int race) const
Definition iteminfo.cpp:27
int mView
Item ID of how this item looks.
Definition iteminfo.h:147
void setSprite(const std::string &animationFile, Gender gender, int race)
Definition iteminfo.cpp:57
const std::string & getSound(EquipmentSoundEvent event) const
Definition iteminfo.cpp:50
std::map< int, std::string > mAnimationFiles
Maps gender to sprite filenames.
Definition iteminfo.h:150
void addSound(EquipmentSoundEvent event, const std::string &filename)
Definition iteminfo.cpp:45
Configuration paths
XML default paths information reader.
Definition client.cpp:99
ItemDB * itemDb
Items info database.
Definition client.cpp:106
EquipmentSoundEvent
Definition iteminfo.h:33