3
* Copyright (C) 2004-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "resources/avatardb.h"
29
#include "resources/beinginfo.h"
31
#include "utils/dtor.h"
32
#include "utils/gettext.h"
34
#include "configuration.h"
40
BeingInfos mAvatarInfos;
49
XML::Document doc("avatars.xml");
50
const XmlNodePtr rootNode = doc.rootNode();
52
if (!rootNode || !xmlNameEqual(rootNode, "avatars"))
54
logger->log1("Avatars Database: Error while loading avatars.xml!");
59
for_each_xml_child_node(avatarNode, rootNode)
61
if (!xmlNameEqual(avatarNode, "avatar"))
64
BeingInfo *const currentInfo = new BeingInfo;
66
currentInfo->setName(XML::langProperty(
67
// TRANSLATORS: unknown info name
68
avatarNode, "name", _("unnamed")));
70
currentInfo->setTargetOffsetX(XML::getProperty(avatarNode,
73
currentInfo->setTargetOffsetY(XML::getProperty(avatarNode,
76
currentInfo->setWidth(XML::getProperty(avatarNode,
78
currentInfo->setHeight(XML::getProperty(avatarNode,
81
SpriteDisplay display;
83
// iterate <sprite>s and <sound>s
84
for_each_xml_child_node(spriteNode, avatarNode)
86
if (xmlNameEqual(spriteNode, "sprite"))
88
if (!spriteNode->xmlChildrenNode)
91
SpriteReference *const currentSprite = new SpriteReference;
92
currentSprite->sprite = reinterpret_cast<const char*>(
93
spriteNode->xmlChildrenNode->content);
95
currentSprite->variant = XML::getProperty(
96
spriteNode, "variant", 0);
97
display.sprites.push_back(currentSprite);
100
currentInfo->setDisplay(display);
102
mAvatarInfos[XML::getProperty(avatarNode, "id", 0)] = currentInfo;
108
void AvatarDB::unload()
110
delete_all(mAvatarInfos);
111
mAvatarInfos.clear();
115
BeingInfo *AvatarDB::get(const int id)
117
BeingInfoIterator i = mAvatarInfos.find(id);
118
if (i == mAvatarInfos.end())
119
return BeingInfo::unknown;