summaryrefslogtreecommitdiffstats
path: root/pokemod/Badge.cpp
blob: 6e57eb579584f89cba0ce4108243da674fe06310 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * Copyright 2007-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 "Badge.h"

// Pokemod includes
#include "Macros.h"
#include "Pokemod.h"
#include "Rules.h"

Pokemod::Badge::Badge(const Badge& badge) :
        Object("Badge", badge.parent(), badge.id())
{
    *this = badge;
}

Pokemod::Badge::Badge(const Pokemod* parent, const int id) :
        Object("Badge", parent, id),
        m_name(""),
        m_face(64, 64),
        m_badge(64, 64),
        m_obey(0)
{
    for (int i = 0; i < ST_End_GSC; ++i)
        m_stat[i].set(1, 1);
}

Pokemod::Badge::Badge(const Badge& badge, const Pokemod* parent, const int id) :
        Object("Badge", parent, id)
{
    *this = badge;
}

Pokemod::Badge::Badge(const QDomElement& xml, const Pokemod* parent, const int id) :
        Object("Badge", parent, id)
{
    LOAD_ID();
    load(xml);
}

void Pokemod::Badge::validate()
{
    TEST_BEGIN();
    if (m_name.isEmpty())
        emit(error("Name is empty"));
    TEST(setFace, face);
    TEST(setBadge, badge);
    TEST(setObey, obey);
    TEST_ARRAY(setStat, stat, (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? ST_End_GSC : ST_End_RBY));
    TEST_END();
}

void Pokemod::Badge::load(const QDomElement& xml)
{
    LOAD_BEGIN();
    LOAD(QString, name);
    LOAD(QPixmap, face);
    LOAD(QPixmap, badge);
    LOAD(int, obey);
    LOAD_ARRAY(Fraction, stat, (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? ST_End_GSC : ST_End_RBY));
}

QDomElement Pokemod::Badge::save() const
{
    SAVE_CREATE();
    SAVE(QString, name);
    SAVE(QPixmap, face);
    SAVE(QPixmap, badge);
    SAVE(int, obey);
    SAVE_ARRAY(Fraction, stat, (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? ST_End_GSC : ST_End_RBY));
    return xml;
}

void Pokemod::Badge::setName(const QString& name)
{
    CHECK(name);
}

void Pokemod::Badge::setFace(const QPixmap& face)
{
    if (face.size() != QSize(64, 64))
    {
        emit(error(size("face")));
        return;
    }
    m_face = face;
    emit(changed());
}

void Pokemod::Badge::setBadge(const QPixmap& badge)
{
    if (badge.size() != QSize(64, 64))
    {
        emit(error(size("badge")));
        return;
    }
    m_badge = badge;
    emit(changed());
}

void Pokemod::Badge::setObey(const int obey)
{
    if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < obey)
    {
        emit(error(bounds("obey")));
        return;
    }
    CHECK(obey);
}

void Pokemod::Badge::setStat(const int stat, const Fraction& multiplier)
{
    if (multiplier < 1)
    {
        emit(error(bounds("stat multiplier")));
        return;
    }
    if ((qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? ST_End_GSC : ST_End_RBY) <= stat)
    {
        emit(error(bounds("stat")));
        return;
    }
    CHECK_ARRAY(stat[stat], multiplier);
}

QString Pokemod::Badge::name() const
{
    return m_name;
}

QPixmap Pokemod::Badge::face() const
{
    return m_face;
}

QPixmap Pokemod::Badge::badge() const
{
    return m_badge;
}

int Pokemod::Badge::obey() const
{
    return m_obey;
}

Pokemod::Fraction Pokemod::Badge::stat(const int stat) const
{
    if ((qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit() ? ST_End_GSC : ST_End_RBY) <= stat)
    {
        emit(warning(bounds("stat")));
        return Fraction();
    }
    return m_stat[stat];
}

Pokemod::Badge& Pokemod::Badge::operator=(const Badge& rhs)
{
    if (this == &rhs)
        return *this;
    COPY(name);
    COPY(face);
    COPY(badge);
    COPY(obey);
    COPY_ARRAY(stat, ST_End_GSC);
    return *this;
}