Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
flydb.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 <QVector>
23
#include <QJsonArray>
24
#include <QQmlEngine>
25
#include <
pse-common/utility.h
>
26
27
#ifdef QT_DEBUG
28
#include <QtDebug>
29
#endif
30
31
#include "
./flydb.h
"
32
#include "
./util/gamedata.h
"
33
#include "
./mapsdb.h
"
34
#include "
./entries/flydbentry.h
"
35
36
FlyDB
*
FlyDB::inst
()
37
{
38
static
FlyDB
* _inst =
new
FlyDB
;
39
return
_inst;
40
}
41
42
const
QVector<FlyDBEntry*>
FlyDB::getStore
()
const
43
{
44
return
store
;
45
}
46
47
const
QHash<QString, FlyDBEntry*>
FlyDB::getInd
()
const
48
{
49
return
ind
;
50
}
51
52
int
FlyDB::getStoreSize
()
const
53
{
54
return
store
.size();
55
}
56
57
FlyDBEntry
*
FlyDB::getStoreAt
(
const
int
ind
)
const
58
{
59
if
(
ind < 0 || ind >
=
store
.size())
60
return
nullptr
;
61
62
return
store
.at(
ind
);
63
}
64
65
FlyDBEntry
*
FlyDB::getIndAt
(
const
QString val)
const
66
{
67
return
ind
.value(val,
nullptr
);
68
}
69
70
void
FlyDB::load
()
71
{
72
static
bool
once =
false
;
73
if
(once)
74
return
;
75
76
// Grab Event Pokemon Data
77
auto
jsonData =
GameData::inst
()->
json
(
"fly"
);
78
79
// Go through each event Pokemon
80
for
(QJsonValue jsonEntry : jsonData.array())
81
{
82
// Create a new event Pokemon entry
83
auto
entry =
new
FlyDBEntry
(jsonEntry);
84
85
// Add to array
86
store
.append(entry);
87
}
88
89
once =
true
;
90
}
91
92
void
FlyDB::index
()
93
{
94
static
bool
once =
false
;
95
if
(once)
96
return
;
97
98
for
(
auto
entry :
store
)
99
{
100
// Index name and index
101
ind
.insert(entry->name, entry);
102
ind
.insert(QString::number(entry->ind), entry);
103
}
104
105
once =
true
;
106
}
107
108
void
FlyDB::deepLink
()
109
{
110
static
bool
once =
false
;
111
if
(once)
112
return
;
113
114
for
(
auto
entry :
store
)
115
{
116
entry->deepLink();
117
}
118
119
once =
true
;
120
}
121
122
void
FlyDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
123
{
124
Utility::qmlProtectUtil
(
this
, engine);
125
for
(
auto
el :
store
)
126
el->qmlProtect(engine);
127
}
128
129
void
FlyDB::qmlRegister()
const
130
{
131
static
bool
once =
false
;
132
if
(once)
133
return
;
134
135
qmlRegisterUncreatableType<FlyDB>(
"PSE.DB.FlyDB"
, 1, 0,
"FlyDB"
,
"Can't instantiate in QML"
);
136
once =
true
;
137
}
138
139
FlyDB::FlyDB
()
140
{
141
qmlRegister();
142
load
();
143
}
FlyDB::getIndAt
FlyDBEntry * getIndAt(const QString val) const
Destination by name key (for QML).
Definition
flydb.cpp:65
FlyDB::deepLink
void deepLink()
Resolve each destination's map link.
Definition
flydb.cpp:108
FlyDB::index
void index()
Build the name->entry index.
Definition
flydb.cpp:92
FlyDB::inst
static FlyDB * inst()
< Number of fly destinations.
Definition
flydb.cpp:36
FlyDB::FlyDB
FlyDB()
(Public here, but obtain the singleton via inst().)
Definition
flydb.cpp:139
FlyDB::getStoreSize
int getStoreSize() const
Destination count.
Definition
flydb.cpp:52
FlyDB::store
QVector< FlyDBEntry * > store
The loaded destinations.
Definition
flydb.h:67
FlyDB::getStoreAt
FlyDBEntry * getStoreAt(const int ind) const
Destination by store index (for QML).
Definition
flydb.cpp:57
FlyDB::load
void load()
Load destinations from JSON.
Definition
flydb.cpp:70
FlyDB::ind
QHash< QString, FlyDBEntry * > ind
Name->entry lookup.
Definition
flydb.h:68
FlyDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
flydb.cpp:122
FlyDB::getInd
const QHash< QString, FlyDBEntry * > getInd() const
Name->entry index.
Definition
flydb.cpp:47
FlyDB::getStore
const QVector< FlyDBEntry * > getStore() const
All fly destinations.
Definition
flydb.cpp:42
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
flydb.h
flydbentry.h
gamedata.h
mapsdb.h
FlyDBEntry
One fly destination: its name/index and the map it flies to.
Definition
flydbentry.h:37
utility.h
projects
db
src
pse-db
flydb.cpp
Generated by
1.17.0