Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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
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
100{
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
113{
114 return dvSp;
115}
116
117void EventPokemonDBEntry::qmlProtect(const QQmlEngine* const engine) const
118{
119 Utility::qmlProtectUtil(this, engine);
120}
121
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
133{
134 return dvSpd;
135}
136
138{
139 return dvDef;
140}
141
143{
144 return dvAtk;
145}
146
151
153{
154 return level;
155}
156
157QVector<QString> EventPokemonDBEntry::getMoves() const
158{
159 return moves;
160}
161
163{
164 return region;
165}
166
168{
169 return otId;
170}
171
172QVector<QString> EventPokemonDBEntry::getOtName() const
173{
174 return otName;
175}
176
178{
179 return pokemon;
180}
181
183{
184 return desc;
185}
186
188{
189 return title;
190}
static PokemonDB * inst()
< Number of species.
Definition pokemon.cpp:183
PokemonDBEntry * getIndAt(const QString &key) const
Species by name key (for QML).
Definition pokemon.cpp:199
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
QString region
Backing field (read via getRegion()).
QVector< QString > otName
OT-name options (read via getOtName()).
QString pokemon
Backing field (read via getPokemon()).
PokemonDBEntry * getToPokemon() const
void deepLink()
Resolve the species link.
int dvAtk
Backing field (read via getDvAtk()).
QVector< QString > moves
Move names (read via getMoves()).
int dvSp
Backing field (read via getDvSp()).
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
QString title
Backing field (read via getTitle()).
PokemonDBEntry * toPokemon
Resolved species (deepLink).
int dvDef
Backing field (read via getDvDef()).
QVector< QString > getOtName() const
OT-name options.
int otId
Backing field (read via getOtId()).
QVector< QString > getMoves() const
Move names the mon comes with.
QString desc
Backing field (read via getDesc()).
int level
Backing field (read via getLevel()).
EventPokemonDBEntry()
Empty entry (built by EventPokemonDB).
void qmlRegister() const
Register with QML.
QString getTitle() const
< Distribution title.
int dvSpd
Backing field (read via getDvSpd()).
One species' complete static data – the richest entry in the db layer.
Definition pokemon.h:98