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