Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
starterPokemon.cpp
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
21
22
#include <QJsonArray>
23
#include <QQmlEngine>
24
#include <
pse-common/utility.h
>
25
#include <
pse-common/random.h
>
26
27
#ifdef QT_DEBUG
28
#include <QtDebug>
29
#endif
30
31
#include "
./starterPokemon.h
"
32
#include "
./util/gamedata.h
"
33
#include "
./pokemon.h
"
34
35
StarterPokemonDB*
StarterPokemonDB::inst
()
36
{
37
static
StarterPokemonDB* _inst =
new
StarterPokemonDB;
38
return
_inst;
39
}
40
41
int
StarterPokemonDB::getStoreSize
()
const
{
return
store.size(); }
42
43
PokemonDBEntry
*
StarterPokemonDB::random3Starter
()
const
44
{
45
var32
idx =
Random::inst
()->
rangeExclusive
(0, 3);
46
return
toPokemon.at(idx);
47
}
48
49
PokemonDBEntry
*
StarterPokemonDB::randomAnyStarter
()
const
50
{
51
var32
idx =
Random::inst
()->
rangeExclusive
(0, store.size());
52
return
toPokemon.at(idx);
53
}
54
55
void
StarterPokemonDB::load
()
56
{
57
static
bool
once =
false
;
58
if
(once)
return
;
59
auto
jsonData =
GameData::inst
()->
json
(
"starters"
);
60
for
(QJsonValue entry : jsonData.array())
61
store.append(entry.toString());
62
once =
true
;
63
}
64
65
void
StarterPokemonDB::deepLink
()
66
{
67
static
bool
once =
false
;
68
if
(once)
return
;
69
for
(
int
i = 0; i < store.size(); ++i) {
70
auto
* mon =
PokemonDB::inst
()->
getIndAt
(store.at(i));
71
toPokemon.append(mon);
72
#ifdef QT_DEBUG
73
if
(!mon) qCritical() <<
"Starter Pokemon:"
<< store.at(i) <<
"could not be deep linked."
;
74
#endif
75
}
76
once =
true
;
77
}
78
79
void
StarterPokemonDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
80
{
81
Utility::qmlProtectUtil
(
this
, engine);
82
}
83
84
void
StarterPokemonDB::qmlRegister()
const
85
{
86
static
bool
once =
false
;
87
if
(once)
return
;
88
qmlRegisterUncreatableType<StarterPokemonDB>(
"PSE.DB.StarterPokemonDB"
, 1, 0,
"StarterPokemonDB"
,
"Can't instantiate in QML"
);
89
once =
true
;
90
}
91
92
StarterPokemonDB::StarterPokemonDB()
93
{
94
qmlRegister();
95
}
GameData::json
const QJsonDocument json(const QString filename) const
Parsed document for filename.
Definition
gamedata.cpp:45
GameData::inst
static GameData * inst()
The process-wide GameData singleton.
Definition
gamedata.cpp:71
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
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
Random::rangeExclusive
int rangeExclusive(const int start, const int end) const
Random integer in the half-open interval [start, end).
Definition
random.cpp:53
StarterPokemonDB::random3Starter
PokemonDBEntry * random3Starter() const
A random one of the 3 canonical starters.
Definition
starterPokemon.cpp:43
StarterPokemonDB::inst
static StarterPokemonDB * inst()
< Number of starter choices.
Definition
starterPokemon.cpp:35
StarterPokemonDB::load
void load()
Load the starter list from JSON.
Definition
starterPokemon.cpp:55
StarterPokemonDB::deepLink
void deepLink()
Resolve the names to species entries.
Definition
starterPokemon.cpp:65
StarterPokemonDB::getStoreSize
int getStoreSize() const
Starter-choice count.
Definition
starterPokemon.cpp:41
StarterPokemonDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
starterPokemon.cpp:79
StarterPokemonDB::randomAnyStarter
PokemonDBEntry * randomAnyStarter() const
A random "startery" species.
Definition
starterPokemon.cpp:49
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
var32
var32e var32
Everyday 32-bit alias. Exact width to avoid the "fastest" widening bug.
Definition
types.h:126
gamedata.h
pokemon.h
random.h
starterPokemon.h
PokemonDBEntry
One species' complete static data – the richest entry in the db layer.
Definition
pokemon.h:98
utility.h
projects
db
src
pse-db
starterPokemon.cpp
Generated by
1.17.0