Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
eventpokemondb.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 <QJsonDocument>
23
#include <QJsonArray>
24
#include <QJsonValueRef>
25
#include <QQmlEngine>
26
#include <
pse-common/utility.h
>
27
28
#ifdef QT_DEBUG
29
#include <QtDebug>
30
#endif
31
32
#include "
./eventpokemondb.h
"
33
#include "
./entries/eventpokemondbentry.h
"
34
#include "
./util/gamedata.h
"
35
#include "
./pokemon.h
"
36
37
EventPokemonDB*
EventPokemonDB::inst
()
38
{
39
static
EventPokemonDB* _inst =
new
EventPokemonDB;
40
return
_inst;
41
}
42
43
const
QVector<EventPokemonDBEntry*>
EventPokemonDB::getStore
()
const
44
{
45
return
store;
46
}
47
48
int
EventPokemonDB::getStoreSize
()
const
49
{
50
return
store.size();
51
}
52
53
EventPokemonDBEntry
*
EventPokemonDB::getStoreAt
(
const
int
ind)
const
54
{
55
if
(ind < 0 || ind >= store.size())
56
return
nullptr
;
57
58
return
store.at(ind);
59
}
60
61
void
EventPokemonDB::load
()
62
{
63
static
bool
once =
false
;
64
if
(once)
65
return
;
66
67
// Grab Event Pokemon Data
68
auto
jsonData =
GameData::inst
()->
json
(
"eventPokemon"
);
69
70
// Go through each event Pokemon
71
for
(QJsonValue jsonEntry : jsonData.array())
72
{
73
// Create a new event Pokemon entry
74
auto
entry =
new
EventPokemonDBEntry
(jsonEntry);
75
76
// Add to array
77
store.append(entry);
78
}
79
80
once =
true
;
81
}
82
83
void
EventPokemonDB::deepLink
()
84
{
85
static
bool
once =
false
;
86
if
(once)
87
return
;
88
89
for
(
auto
entry : store)
90
{
91
entry->deepLink();
92
}
93
94
once =
true
;
95
}
96
97
void
EventPokemonDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
98
{
99
Utility::qmlProtectUtil
(
this
, engine);
100
for
(
auto
el : store)
101
el->qmlProtect(engine);
102
}
103
104
void
EventPokemonDB::qmlRegister()
const
105
{
106
static
bool
once =
false
;
107
if
(once)
108
return
;
109
110
qmlRegisterUncreatableType<EventPokemonDB>(
"PSE.DB.EventPokemonDB"
, 1, 0,
"EventPokemonDB"
,
"Can't instantiate in QML"
);
111
once =
true
;
112
}
113
114
EventPokemonDB::EventPokemonDB()
115
{
116
qmlRegister();
117
load
();
118
}
EventPokemonDB::deepLink
void deepLink()
Resolve each entry's species/move links.
Definition
eventpokemondb.cpp:83
EventPokemonDB::getStoreSize
int getStoreSize() const
Event-Pokemon count.
Definition
eventpokemondb.cpp:48
EventPokemonDB::load
void load()
Load event Pokemon from JSON.
Definition
eventpokemondb.cpp:61
EventPokemonDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
eventpokemondb.cpp:97
EventPokemonDB::inst
static EventPokemonDB * inst()
< Number of event Pokemon.
Definition
eventpokemondb.cpp:37
EventPokemonDB::getStore
const QVector< EventPokemonDBEntry * > getStore() const
All event Pokemon.
Definition
eventpokemondb.cpp:43
EventPokemonDB::getStoreAt
EventPokemonDBEntry * getStoreAt(const int ind) const
Event Pokemon by store index (for QML).
Definition
eventpokemondb.cpp:53
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
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
One real-world event-distribution Pokemon preset.
Definition
eventpokemondbentry.h:37
utility.h
projects
db
src
pse-db
eventpokemondb.cpp
Generated by
1.17.0