1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Header include
#include "Trainer.h"
// Pokemod includes
#include "Pokemod.h"
// Qt includes
#include <QBuffer>
const QStringList Trainer::IntelligenceStr = QStringList() << "Ignorant" << "Remember" << "Deduce" << "Cheating";
Trainer::Trainer(const Trainer& trainer) :
Object("Trainer", trainer.parent(), trainer.id())
{
*this = trainer;
}
Trainer::Trainer(const Pokemod* parent, const int id) :
Object("Trainer", parent, id),
m_name(""),
m_moneyFactor(0),
m_skin(192, 128)
{
}
Trainer::Trainer(const Trainer& trainer, const Pokemod* parent, const int id) :
Object("Trainer", parent, id)
{
*this = trainer;
}
Trainer::Trainer(const QDomElement& xml, const Pokemod* parent, const int id) :
Object("Trainer", parent, id)
{
load(xml, id);
}
void Trainer::validate()
{
if (m_name.isEmpty())
emit(error("Name is empty"));
TEST(setMoneyFactor, moneyFactor);
TEST(setSkin, skin);
}
void Trainer::load(const QDomElement& xml, int id)
{
LOAD_ID();
LOAD(QString, name);
LOAD(int, moneyFactor);
LOAD(QPixmap, skin);
}
QDomElement Trainer::save() const
{
SAVE_CREATE();
SAVE(QString, name);
SAVE(int, moneyFactor);
SAVE(QPixmap, skin);
return xml;
}
void Trainer::setName(const QString& name)
{
CHECK(name);
}
void Trainer::setMoneyFactor(const int moneyFactor)
{
if (moneyFactor < 0)
{
emit(error(bounds("moneyFactor")));
return;
}
CHECK(moneyFactor);
}
void Trainer::setSkin(const QPixmap& skin)
{
if (skin.size() != QSize(192, 128))
{
emit(error(size("skin")));
return;
}
m_skin = skin;
emit(changed());
}
QString Trainer::name() const
{
return m_name;
}
int Trainer::moneyFactor() const
{
return m_moneyFactor;
}
QPixmap Trainer::skin() const
{
return m_skin;
}
Trainer& Trainer::operator=(const Trainer& rhs)
{
if (this == &rhs)
return *this;
COPY(name);
COPY(moneyFactor);
COPY(skin);
return *this;
}
|