Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
eventpokemondbentry.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2020 Twilight
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
21
#include "
eventpokemondbentry.h
"
22
23
#include <QJsonDocument>
24
#include <QJsonArray>
25
#include <QJsonValueRef>
26
#include <QQmlEngine>
27
#include <
pse-common/utility.h
>
28
29
#ifdef QT_DEBUG
30
#include <QtDebug>
31
#endif
32
33
#include "
../util/gamedata.h
"
34
#include "
../pokemon.h
"
35
#include "
../eventpokemondb.h
"
36
37
EventPokemonDBEntry::EventPokemonDBEntry
() {
38
qmlRegister
();
39
}
40
EventPokemonDBEntry::EventPokemonDBEntry
(
const
QJsonValue& data) {
41
qmlRegister
();
42
43
// Set simple properties
44
title
= data[
"title"
].toString();
45
desc
= data[
"desc"
].toString();
46
pokemon
= data[
"pokemon"
].toString();
47
region
= data[
"region"
].toString();
48
49
// Set simple optional proeprties
50
if
(data[
"otID"
].isString())
51
otId
= data[
"otID"
].toString().toInt(
nullptr
, 16);
52
53
if
(data[
"level"
].isDouble())
54
level
= data[
"level"
].toDouble();
55
56
// Set Moves
57
auto
movesArr = data[
"moves"
].toArray();
58
for
(QJsonValue moveEntry : movesArr)
59
moves
.append(moveEntry.toString());
60
61
// Set OT Name
62
// Can be array or string
63
if
(data[
"otName"
].isArray())
64
{
65
auto
otNameArr = data[
"otName"
].toArray();
66
67
for
(
auto
otNameEntry : otNameArr)
68
otName
.append(otNameEntry.toString());
69
}
70
else
71
otName
.append(data[
"otName"
].toString());
72
73
// Set DV
74
if
(data[
"dv"
].isString())
75
{
76
// DV Can be
77
// "max" All DV Values of 15
78
// ":##:##:##:##" Specific DV Values
79
// Atk, Def, Spd, Sp
80
auto
dvVal = data[
"dv"
].toString();
81
82
if
(dvVal ==
"max"
) {
83
dvAtk
= 15;
84
dvDef
= 15;
85
dvSpd
= 15;
86
dvSp
= 15;
87
}
88
else
89
{
90
auto
dvValParts = dvVal.split(
":"
, Qt::SkipEmptyParts);
91
dvAtk
= dvValParts[0].toInt(
nullptr
, 10);
92
dvDef
= dvValParts[1].toInt(
nullptr
, 10);
93
dvSpd
= dvValParts[2].toInt(
nullptr
, 10);
94
dvSp
= dvValParts[3].toInt(
nullptr
, 10);
95
}
96
}
97
}
98
99
void
EventPokemonDBEntry::deepLink
()
100
{
101
toPokemon
=
PokemonDB::inst
()->
getIndAt
(
pokemon
);
102
103
#ifdef QT_DEBUG
104
if
(
toPokemon
==
nullptr
)
105
qCritical() <<
"Event Pokemon: "
<<
pokemon
<<
", could not be deep linked."
;
106
#endif
107
108
if
(
toPokemon
!=
nullptr
)
109
toPokemon
->toEventMons.append(
this
);
110
}
111
112
int
EventPokemonDBEntry::getDvSp
()
const
113
{
114
return
dvSp
;
115
}
116
117
void
EventPokemonDBEntry::qmlProtect
(
const
QQmlEngine*
const
engine)
const
118
{
119
Utility::qmlProtectUtil
(
this
, engine);
120
}
121
122
void
EventPokemonDBEntry::qmlRegister
()
const
123
{
124
static
bool
once =
false
;
125
if
(once)
126
return
;
127
128
qmlRegisterUncreatableType<EventPokemonDBEntry>(
"PSE.DB.EventPokemonDBEntry"
, 1, 0,
"EventPokemonDBEntry"
,
"Can't instantiate in QML"
);
129
once =
true
;
130
}
131
132
int
EventPokemonDBEntry::getDvSpd
()
const
133
{
134
return
dvSpd
;
135
}
136
137
int
EventPokemonDBEntry::getDvDef
()
const
138
{
139
return
dvDef
;
140
}
141
142
int
EventPokemonDBEntry::getDvAtk
()
const
143
{
144
return
dvAtk
;
145
}
146
147
PokemonDBEntry
*
EventPokemonDBEntry::getToPokemon
()
const
148
{
149
return
toPokemon
;
150
}
151
152
int
EventPokemonDBEntry::getLevel
()
const
153
{
154
return
level
;
155
}
156
157
QVector<QString>
EventPokemonDBEntry::getMoves
()
const
158
{
159
return
moves
;
160
}
161
162
QString
EventPokemonDBEntry::getRegion
()
const
163
{
164
return
region
;
165
}
166
167
int
EventPokemonDBEntry::getOtId
()
const
168
{
169
return
otId
;
170
}
171
172
QVector<QString>
EventPokemonDBEntry::getOtName
()
const
173
{
174
return
otName
;
175
}
176
177
QString
EventPokemonDBEntry::getPokemon
()
const
178
{
179
return
pokemon
;
180
}
181
182
QString
EventPokemonDBEntry::getDesc
()
const
183
{
184
return
desc
;
185
}
186
187
QString
EventPokemonDBEntry::getTitle
()
const
188
{
189
return
title
;
190
}
PokemonDB::inst
static PokemonDB * inst()
< Number of species.
Definition
pokemon.cpp:183
PokemonDB::getIndAt
PokemonDBEntry * getIndAt(const QString &key) const
Species by name key (for QML).
Definition
pokemon.cpp:199
Utility::qmlProtectUtil
static void qmlProtectUtil(const QObject *const obj, const QQmlEngine *const engine)
Pin obj to C++ ownership so the QML engine never garbage-collects it.
Definition
utility.cpp:63
eventpokemondb.h
eventpokemondbentry.h
gamedata.h
pokemon.h
EventPokemonDBEntry::region
QString region
Backing field (read via getRegion()).
Definition
eventpokemondbentry.h:81
EventPokemonDBEntry::otName
QVector< QString > otName
OT-name options (read via getOtName()).
Definition
eventpokemondbentry.h:80
EventPokemonDBEntry::getRegion
QString getRegion() const
Definition
eventpokemondbentry.cpp:162
EventPokemonDBEntry::getDvAtk
int getDvAtk() const
Definition
eventpokemondbentry.cpp:142
EventPokemonDBEntry::pokemon
QString pokemon
Backing field (read via getPokemon()).
Definition
eventpokemondbentry.h:79
EventPokemonDBEntry::getToPokemon
PokemonDBEntry * getToPokemon() const
Definition
eventpokemondbentry.cpp:147
EventPokemonDBEntry::deepLink
void deepLink()
Resolve the species link.
Definition
eventpokemondbentry.cpp:99
EventPokemonDBEntry::dvAtk
int dvAtk
Backing field (read via getDvAtk()).
Definition
eventpokemondbentry.h:85
EventPokemonDBEntry::moves
QVector< QString > moves
Move names (read via getMoves()).
Definition
eventpokemondbentry.h:82
EventPokemonDBEntry::dvSp
int dvSp
Backing field (read via getDvSp()).
Definition
eventpokemondbentry.h:88
EventPokemonDBEntry::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
eventpokemondbentry.cpp:117
EventPokemonDBEntry::title
QString title
Backing field (read via getTitle()).
Definition
eventpokemondbentry.h:77
EventPokemonDBEntry::getPokemon
QString getPokemon() const
Definition
eventpokemondbentry.cpp:177
EventPokemonDBEntry::toPokemon
PokemonDBEntry * toPokemon
Resolved species (deepLink).
Definition
eventpokemondbentry.h:89
EventPokemonDBEntry::dvDef
int dvDef
Backing field (read via getDvDef()).
Definition
eventpokemondbentry.h:86
EventPokemonDBEntry::getOtName
QVector< QString > getOtName() const
OT-name options.
Definition
eventpokemondbentry.cpp:172
EventPokemonDBEntry::otId
int otId
Backing field (read via getOtId()).
Definition
eventpokemondbentry.h:84
EventPokemonDBEntry::getDesc
QString getDesc() const
Definition
eventpokemondbentry.cpp:182
EventPokemonDBEntry::getMoves
QVector< QString > getMoves() const
Move names the mon comes with.
Definition
eventpokemondbentry.cpp:157
EventPokemonDBEntry::getDvSpd
int getDvSpd() const
Definition
eventpokemondbentry.cpp:132
EventPokemonDBEntry::desc
QString desc
Backing field (read via getDesc()).
Definition
eventpokemondbentry.h:78
EventPokemonDBEntry::level
int level
Backing field (read via getLevel()).
Definition
eventpokemondbentry.h:83
EventPokemonDBEntry::getLevel
int getLevel() const
Definition
eventpokemondbentry.cpp:152
EventPokemonDBEntry::EventPokemonDBEntry
EventPokemonDBEntry()
Empty entry (built by EventPokemonDB).
Definition
eventpokemondbentry.cpp:37
EventPokemonDBEntry::qmlRegister
void qmlRegister() const
Register with QML.
Definition
eventpokemondbentry.cpp:122
EventPokemonDBEntry::getTitle
QString getTitle() const
< Distribution title.
Definition
eventpokemondbentry.cpp:187
EventPokemonDBEntry::getOtId
int getOtId() const
Definition
eventpokemondbentry.cpp:167
EventPokemonDBEntry::getDvDef
int getDvDef() const
Definition
eventpokemondbentry.cpp:137
EventPokemonDBEntry::dvSpd
int dvSpd
Backing field (read via getDvSpd()).
Definition
eventpokemondbentry.h:87
EventPokemonDBEntry::getDvSp
int getDvSp() const
Definition
eventpokemondbentry.cpp:112
PokemonDBEntry
One species' complete static data – the richest entry in the db layer.
Definition
pokemon.h:98
utility.h
projects
db
src
pse-db
entries
eventpokemondbentry.cpp
Generated by
1.17.0