Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
pokemon.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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#pragma once
17
18#include <QObject>
19#include <QJsonValue>
20#include <QString>
21#include <QVector>
22#include <QHash>
23#include <optional>
24
25#include <pse-common/types.h>
26#include "./db_autoport.h"
27
28constexpr var8 pokemonDexCount = 151;
29constexpr var8 pokemonLevelMax = 100;
30
31// Forward declarations
33struct MoveDBEntry;
34struct PokemonDBEntry;
35struct ItemDBEntry;
36struct TypeDBEntry;
40struct TradeDBEntry;
42class QQmlEngine;
43
52{
55 void deepLink(PokemonDBEntry* deEvolution);
56
57 QString toName;
58 bool trade = false;
59 QString item;
60 std::optional<var8> level;
61
64 ItemDBEntry* toItem = nullptr;
66};
67
74{
76 PokemonDBEntryMove(QJsonValue& data, PokemonDBEntry* parent);
77 void deepLink();
78
79 var8 level = 0;
80 QString move;
81
82 MoveDBEntry* toMove = nullptr;
84};
85
100 PokemonDBEntry(QJsonValue& data);
101 void deepLink();
102
103 QString name;
104 var8 ind = 0;
105 QString readable;
106 bool glitch = false;
107 QString type1;
108 QString type2;
109
110 QVector<PokemonDBEntryMove*> moves;
111 QVector<QString> initial;
112 QVector<var8> tmHm;
113 QVector<PokemonDBEntryEvolution*> evolution;
114
115 std::optional<var8> pokedex;
116 std::optional<var8> growthRate;
117 std::optional<var8> baseHp;
118 std::optional<var8> baseAttack;
119 std::optional<var8> baseDefense;
120 std::optional<var8> baseSpeed;
121 std::optional<var8> baseSpecial;
122 std::optional<var8> baseExpYield;
123 std::optional<var8> catchRate;
124
125 TypeDBEntry* toType1 = nullptr;
126 TypeDBEntry* toType2 = nullptr;
128 QVector<MoveDBEntry*> toInitial;
129 QVector<MoveDBEntry*> toTmHmMove;
130 QVector<ItemDBEntry*> toTmHmItem;
131 QVector<EventPokemonDBEntry*> toEventMons;
133 QVector<MapDBEntryWildMon*> toWildMonMaps;
134 QVector<TradeDBEntry*> toTrades;
135 QVector<GameCornerDBEntry*> toGameCorner;
136};
137
146class DB_AUTOPORT PokemonDB : public QObject
147{
148 Q_OBJECT
149 Q_PROPERTY(int getStoreSize READ getStoreSize CONSTANT)
150
151public:
152 static PokemonDB* inst();
153
154 [[nodiscard]] const QVector<PokemonDBEntry*> getStore() const;
155 [[nodiscard]] const QHash<QString, PokemonDBEntry*> getInd() const;
156 [[nodiscard]] int getStoreSize() const;
157
158 Q_INVOKABLE PokemonDBEntry* getStoreAt(int idx) const;
159 Q_INVOKABLE PokemonDBEntry* getIndAt(const QString& key) const;
160
161public slots:
162 void load();
163 void index();
164 void deepLink();
165 void qmlProtect(const QQmlEngine* const engine) const;
166
167private slots:
168 void qmlRegister() const;
169
170private:
171 PokemonDB();
172
173 QVector<PokemonDBEntry*> store;
174 QHash<QString, PokemonDBEntry*> ind;
175};
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition pokemon.cpp:237
static PokemonDB * inst()
< Number of species.
Definition pokemon.cpp:183
void deepLink()
Resolve every species' cross-reference web.
Definition pokemon.cpp:228
PokemonDBEntry * getStoreAt(int idx) const
Species by store index (for QML).
Definition pokemon.cpp:193
int getStoreSize() const
Species count.
Definition pokemon.cpp:191
const QHash< QString, PokemonDBEntry * > getInd() const
Name->species index.
Definition pokemon.cpp:190
void index()
Build the name->species index.
Definition pokemon.cpp:214
const QVector< PokemonDBEntry * > getStore() const
All species.
Definition pokemon.cpp:189
void load()
Load species from JSON.
Definition pokemon.cpp:204
PokemonDBEntry * getIndAt(const QString &key) const
Species by name key (for QML).
Definition pokemon.cpp:199
Project-wide fixed-width integer aliases (var8, var16, ...).
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
Import/export macro for the db library, plus the central list of DB entry pointer types declared opaq...
#define DB_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.
Definition db_autoport.h:37
constexpr var8 pokemonDexCount
Number of species.
Definition pokemon.h:28
constexpr var8 pokemonLevelMax
Maximum level.
Definition pokemon.h:29
One real-world event-distribution Pokemon preset.
One Game Corner prize: a Pokemon or item, its coin price, and level.
One item's static data: name/flags, pricing, and where it's used.
Definition itemdbentry.h:46
A map sprite that is a static, battleable Pokemon (type POKEMON).
One wild-encounter slot in a map's encounter table: species + level.
One move's static data (type, power, accuracy, PP, TM/HM), with links.
Definition moves.h:46
One evolution edge of a species: how it evolves (and de-evolves).
Definition pokemon.h:52
QString item
Evolution item, if any.
Definition pokemon.h:59
void deepLink(PokemonDBEntry *deEvolution)
Resolve target/item; set deEvolution back-link.
Definition pokemon.cpp:52
std::optional< var8 > level
Evolution level, if level-based.
Definition pokemon.h:60
PokemonDBEntry * toDeEvolution
Resolved pre-evolution.
Definition pokemon.h:62
PokemonDBEntry * toEvolution
Resolved evolved species.
Definition pokemon.h:63
ItemDBEntry * toItem
Resolved evolution item.
Definition pokemon.h:64
QString toName
Name of the species this evolves into.
Definition pokemon.h:57
PokemonDBEntry * parent
Owning species.
Definition pokemon.h:65
PokemonDBEntryEvolution()
Empty edge.
Definition pokemon.cpp:41
bool trade
Evolves on trade.
Definition pokemon.h:58
void deepLink()
Resolve the move link.
Definition pokemon.cpp:82
PokemonDBEntryMove()
Empty learn entry.
Definition pokemon.cpp:74
QString move
Move name (resolved to toMove).
Definition pokemon.h:80
MoveDBEntry * toMove
Resolved move.
Definition pokemon.h:82
var8 level
Level the move is learned at.
Definition pokemon.h:79
PokemonDBEntry * parent
Owning species.
Definition pokemon.h:83
One species' complete static data – the richest entry in the db layer.
Definition pokemon.h:98
QVector< GameCornerDBEntry * > toGameCorner
Game Corner prizes of this species.
Definition pokemon.h:135
QString type1
Primary type name (resolved to toType1).
Definition pokemon.h:107
PokemonDBEntry()
Empty species.
Definition pokemon.cpp:94
bool glitch
Whether this is a glitch species.
Definition pokemon.h:106
std::optional< var8 > baseHp
Base HP.
Definition pokemon.h:117
QVector< ItemDBEntry * > toTmHmItem
Resolved TM/HM items.
Definition pokemon.h:130
QString type2
Secondary type name (resolved to toType2).
Definition pokemon.h:108
std::optional< var8 > baseDefense
Base Defense.
Definition pokemon.h:119
MapDBEntrySpritePokemon * toMapSpritePokemon
On-map static-Pokemon sprite, if any.
Definition pokemon.h:132
std::optional< var8 > catchRate
Catch rate.
Definition pokemon.h:123
QVector< MoveDBEntry * > toTmHmMove
Resolved TM/HM moves.
Definition pokemon.h:129
std::optional< var8 > growthRate
EXP growth-rate group.
Definition pokemon.h:116
PokemonDBEntry * toDeEvolution
Resolved pre-evolution.
Definition pokemon.h:127
QString name
Internal species name (key).
Definition pokemon.h:103
QVector< PokemonDBEntryMove * > moves
Level-up learnset.
Definition pokemon.h:110
void deepLink()
Resolve the full cross-reference web (the to* members).
Definition pokemon.cpp:135
std::optional< var8 > baseSpeed
Base Speed.
Definition pokemon.h:120
QVector< MoveDBEntry * > toInitial
Resolved capture moves.
Definition pokemon.h:128
var8 ind
Internal species index.
Definition pokemon.h:104
QVector< var8 > tmHm
TM/HM numbers it can learn.
Definition pokemon.h:112
std::optional< var8 > baseSpecial
Base Special.
Definition pokemon.h:121
QVector< QString > initial
Moves known at capture (resolved to toInitial).
Definition pokemon.h:111
QVector< TradeDBEntry * > toTrades
In-game trades giving/getting it.
Definition pokemon.h:134
QString readable
Human-readable species name.
Definition pokemon.h:105
std::optional< var8 > baseExpYield
Base EXP yield.
Definition pokemon.h:122
QVector< PokemonDBEntryEvolution * > evolution
Evolution edges.
Definition pokemon.h:113
QVector< EventPokemonDBEntry * > toEventMons
Event distributions of this species.
Definition pokemon.h:131
TypeDBEntry * toType1
Resolved primary type.
Definition pokemon.h:125
TypeDBEntry * toType2
Resolved secondary type.
Definition pokemon.h:126
QVector< MapDBEntryWildMon * > toWildMonMaps
Maps where it appears wild.
Definition pokemon.h:133
std::optional< var8 > baseAttack
Base Attack.
Definition pokemon.h:118
std::optional< var8 > pokedex
Pokedex number, if assigned.
Definition pokemon.h:115
One in-game (NPC) trade definition: what you give and get.
Definition trades.h:37
One elemental type: its name plus the moves and Pokemon of that type.
Definition types.h:39