Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
mapsdb.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 <
pse-common/utility.h
>
24
#include <QQmlEngine>
25
26
#include "
./mapsdb.h
"
27
#include "
./util/gamedata.h
"
28
#include "
./util/mapsearch.h
"
29
#include "
./entries/mapdbentry.h
"
30
31
#ifdef QT_DEBUG
32
#include <QtDebug>
33
#endif
34
35
MapsDB*
MapsDB::inst
()
36
{
37
static
MapsDB* _inst =
new
MapsDB;
38
return
_inst;
39
}
40
41
const
QVector<MapDBEntry*>
MapsDB::getStore
()
const
42
{
43
return
store;
44
}
45
46
const
QHash<QString, MapDBEntry*>
MapsDB::getInd
()
const
47
{
48
return
ind;
49
}
50
51
int
MapsDB::getStoreSize
()
const
52
{
53
return
store.size();
54
}
55
56
void
MapsDB::load
()
57
{
58
static
bool
once =
false
;
59
if
(once)
60
return
;
61
62
// Grab Map Data
63
auto
jsonData =
GameData::inst
()->
json
(
"maps"
);
64
65
// Go through each map
66
for
(QJsonValue jsonEntry : jsonData.array())
67
{
68
// Create a new map entry
69
auto
entry =
new
MapDBEntry
(jsonEntry);
70
71
// Add to array
72
store.append(entry);
73
}
74
75
once =
true
;
76
}
77
78
void
MapsDB::index
()
79
{
80
static
bool
once =
false
;
81
if
(once)
82
return
;
83
84
for
(
auto
entry : store)
85
{
86
// Index name and index
87
ind.insert(entry->name, entry);
88
ind.insert(QString::number(entry->ind), entry);
89
90
// Also insert the modern name if present
91
if
(entry->modernName !=
""
)
92
ind.insert(entry->modernName, entry);
93
}
94
95
once =
true
;
96
}
97
98
void
MapsDB::deepLink
()
99
{
100
static
bool
once =
false
;
101
if
(once)
102
return
;
103
104
for
(
auto
entry : store)
105
{
106
entry->deepLink();
107
}
108
109
once =
true
;
110
}
111
112
void
MapsDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
113
{
114
Utility::qmlProtectUtil
(
this
, engine);
115
for
(
auto
el : store)
116
el->qmlProtect(engine);
117
}
118
119
void
MapsDB::qmlRegister()
const
120
{
121
static
bool
once =
false
;
122
if
(once)
123
return
;
124
125
qmlRegisterUncreatableType<MapsDB>(
126
"PSE.DB.MapsDB"
, 1, 0,
"MapsDB"
,
"Can't instantiate in QML"
);
127
once =
true
;
128
}
129
130
MapsDB::MapsDB()
131
{
132
qmlRegister();
133
load
();
134
}
135
136
MapSearch
*
MapsDB::searchRaw
()
const
137
{
138
return
new
MapSearch
();
139
}
140
141
QScopedPointer<MapSearch, QScopedPointerDeleteLater>
MapsDB::search
()
const
142
{
143
return
QScopedPointer<MapSearch, QScopedPointerDeleteLater>(
144
new
MapSearch
());
145
}
146
147
MapDBEntry
*
MapsDB::getStoreAt
(
const
int
ind)
const
148
{
149
if
(ind < 0 || ind >= store.size())
150
return
nullptr
;
151
152
return
store.at(ind);
153
}
154
155
MapDBEntry
*
MapsDB::getIndAt
(
const
QString val)
const
156
{
157
return
ind.value(val,
nullptr
);
158
}
MapDBEntry
class SAVEFILE_AUTOPORT MapDBEntry
Definition
areageneral.h:52
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
MapSearch
A chainable filter ("finder") over the maps – the heart of map randomization.
Definition
mapsearch.h:42
MapsDB::deepLink
void deepLink()
Resolve every map's warps/sprites/connections/etc.
Definition
mapsdb.cpp:98
MapsDB::inst
static MapsDB * inst()
< Number of maps.
Definition
mapsdb.cpp:35
MapsDB::search
QScopedPointer< MapSearch, QScopedPointerDeleteLater > search() const
C++-owned finder (smart pointer).
Definition
mapsdb.cpp:141
MapsDB::getIndAt
MapDBEntry * getIndAt(const QString val) const
Map by name key (for QML).
Definition
mapsdb.cpp:155
MapsDB::getStoreSize
int getStoreSize() const
Map count.
Definition
mapsdb.cpp:51
MapsDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
mapsdb.cpp:112
MapsDB::index
void index()
Build the name->map index.
Definition
mapsdb.cpp:78
MapsDB::getStore
const QVector< MapDBEntry * > getStore() const
All maps.
Definition
mapsdb.cpp:41
MapsDB::getStoreAt
MapDBEntry * getStoreAt(const int ind) const
Map by store index (for QML).
Definition
mapsdb.cpp:147
MapsDB::getInd
const QHash< QString, MapDBEntry * > getInd() const
Name->map index.
Definition
mapsdb.cpp:46
MapsDB::searchRaw
MapSearch * searchRaw() const
Raw finder for QML (QML-managed ownership).
Definition
mapsdb.cpp:136
MapsDB::load
void load()
Load maps from JSON.
Definition
mapsdb.cpp:56
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
mapdbentry.h
mapsdb.h
mapsearch.h
MapDBEntry
One map's complete static definition – the root of the MapDBEntry family.
Definition
mapdbentry.h:56
utility.h
projects
db
src
pse-db
mapsdb.cpp
Generated by
1.17.0