GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/textcommand.cpp Lines: 11 28 39.3 %
Date: 2017-11-29 Branches: 4 34 11.8 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  Andrei Karas
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
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
12
 *  any later version.
13
 *
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.
18
 *
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/>.
21
 */
22
23
#include "textcommand.h"
24
25
#include "configuration.h"
26
27
#include "gui/theme.h"
28
29
#include "resources/iteminfo.h"
30
31
#include "resources/db/itemdb.h"
32
33
#include "resources/image/image.h"
34
35
#include "resources/loaders/imageloader.h"
36
37
#include "debug.h"
38
39
#ifdef TMWA_SUPPORT
40
TextCommand::TextCommand(const int id,
41
                         const std::string &symbol,
42
                         const std::string &command,
43
                         const std::string &comment,
44
                         const CommandTargetT type,
45
                         const std::string &icon,
46
                         const unsigned int basicLvl,
47
                         const MagicSchoolT school,
48
                         const unsigned int schoolLvl,
49
                         const unsigned int mana) :
50
    mCommand(command),
51
    mComment(comment),
52
    mSymbol(symbol),
53
    mTargetType(type),
54
    mIcon(icon),
55
    mId(id),
56
    mMana(mana),
57
    mSchool(school),
58
    mBaseLvl(basicLvl),
59
    mSchoolLvl(schoolLvl),
60
    mCommandType(TextCommandType::Magic),
61
    mImage(nullptr)
62
{
63
    loadImage();
64
}
65
#endif  // TMWA_SUPPORT
66
67
2
TextCommand::TextCommand(const int id,
68
                         const std::string &symbol,
69
                         const std::string &command,
70
                         const std::string &comment,
71
                         const CommandTargetT type,
72
2
                         const std::string &icon) :
73
    mCommand(command),
74
    mComment(comment),
75
    mSymbol(symbol),
76
    mTargetType(type),
77
    mIcon(icon),
78
    mId(id),
79
#ifdef TMWA_SUPPORT
80
    mMana(0U),
81
    mSchool(MagicSchool::SkillMagic),
82
    mBaseLvl(0),
83
    mSchoolLvl(0),
84
    mCommandType(TextCommandType::Text),
85
#endif  // TMWA_SUPPORT
86
10
    mImage(nullptr)
87
{
88
2
    loadImage();
89
2
}
90
91
TextCommand::TextCommand(const int id) :
92
    mCommand(""),
93
    mComment(""),
94
    mSymbol(""),
95
    mTargetType(CommandTarget::NoTarget),
96
    mIcon(""),
97
    mId(id),
98
#ifdef TMWA_SUPPORT
99
    mMana(0U),
100
    mSchool(MagicSchool::SkillMagic),
101
    mBaseLvl(0),
102
    mSchoolLvl(0),
103
    mCommandType(TextCommandType::Text),
104
#endif  // TMWA_SUPPORT
105
    mImage(nullptr)
106
{
107
    loadImage();
108
}
109
110
111
12
TextCommand::~TextCommand()
112
{
113
2
    if (mImage != nullptr)
114
    {
115
        mImage->decRef();
116
        mImage = nullptr;
117
    }
118
2
}
119
120
2
void TextCommand::loadImage()
121
{
122
2
    if (mImage != nullptr)
123
    {
124
        mImage->decRef();
125
        mImage = nullptr;
126
    }
127
128

4
    if (mIcon.empty() ||
129
        !ItemDB::exists(mIcon))
130
    {
131
        return;
132
    }
133
134
    const ItemInfo &info = ItemDB::get(mIcon);
135
    const SpriteDisplay &display = info.getDisplay();
136
    mImage = Loader::getImage(pathJoin(paths.getStringValue("itemIcons"),
137
        display.image));
138
139
    if (mImage == nullptr)
140
        mImage = Theme::getImageFromTheme("unknown-item.png");
141
}