Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
missabledbentry.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2020 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
#include "
missabledbentry.h
"
22
23
#include <QVector>
24
#include <QJsonArray>
25
#include <QQmlEngine>
26
#include <
pse-common/utility.h
>
27
28
#ifdef QT_DEBUG
29
#include <QtDebug>
30
#endif
31
32
#include "
../mapsdb.h
"
33
#include "
./mapdbentry.h
"
34
35
MissableDBEntry::MissableDBEntry
() {
36
qmlRegister
();
37
}
38
MissableDBEntry::MissableDBEntry
(QJsonValue& data)
39
{
40
qmlRegister
();
41
42
// Set simple properties
43
name
= data[
"name"
].toString();
44
ind
= data[
"ind"
].toDouble();
45
map
= data[
"map"
].toString();
46
sprite
= data[
"sprite"
].toDouble();
47
defShow
= data[
"defVal"
].toString() ==
"Show"
;
48
}
49
50
void
MissableDBEntry::deepLink
()
51
{
52
toMap
=
MapsDB::inst
()->
getInd
().value(
map
,
nullptr
);
53
54
// Deep link map sprite only if toMap is valid and sprite is a valid range
55
if
(
toMap
!=
nullptr
&&
sprite < toMap->
getSprites().size())
56
{
57
toMapSprite
=
toMap
->getSprites().at(
sprite
);
58
}
59
60
#ifdef QT_DEBUG
61
if
(
toMap
==
nullptr
)
62
qCritical() <<
"Missables: "
<<
name
<<
", could not be deep linked to map"
<<
map
;
63
64
if
(
toMapSprite
==
nullptr
&&
65
66
// Don't warn about these errors as they're not my errors, they're
67
// gen 1 errors
68
69
// This is a valid map that refers to an extra sprite not on the map
70
((
map
==
"Silph Co 7F"
&&
71
sprite
!= 11) ||
72
73
// This is an invalid map with no sprites
74
(
map
==
"Unused Map F4"
&&
75
sprite
!= 1))
76
77
)
78
qCritical() <<
"Missables: "
<<
name
<<
", could not be deep linked to map "
<<
map
<<
" sprite #"
<<
sprite
;
79
#endif
80
}
81
82
void
MissableDBEntry::qmlRegister
()
const
83
{
84
static
bool
once =
false
;
85
if
(once)
86
return
;
87
88
qmlRegisterUncreatableType<MissableDBEntry>(
89
"PSE.DB.MissableDBEntry"
, 1, 0,
"MissableDBEntry"
,
"Can't instantiate in QML"
);
90
once =
true
;
91
}
92
93
MapDBEntrySprite
*
MissableDBEntry::getToMapSprite
()
const
94
{
95
return
toMapSprite
;
96
}
97
98
void
MissableDBEntry::qmlProtect
(
const
QQmlEngine*
const
engine)
const
99
{
100
Utility::qmlProtectUtil
(
this
, engine);
101
}
102
103
MapDBEntry
*
MissableDBEntry::getToMap
()
const
104
{
105
return
toMap
;
106
}
107
108
bool
MissableDBEntry::getDefShow
()
const
109
{
110
return
defShow
;
111
}
112
113
int
MissableDBEntry::getSprite
()
const
114
{
115
return
sprite
;
116
}
117
118
const
QString
MissableDBEntry::getMap
()
const
119
{
120
return
map
;
121
}
122
123
int
MissableDBEntry::getInd
()
const
124
{
125
return
ind
;
126
}
127
128
const
QString
MissableDBEntry::getName
()
const
129
{
130
return
name
;
131
}
MapsDB::inst
static MapsDB * inst()
< Number of maps.
Definition
mapsdb.cpp:35
MapsDB::getInd
const QHash< QString, MapDBEntry * > getInd() const
Name->map index.
Definition
mapsdb.cpp:46
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
mapdbentry.h
mapsdb.h
missabledbentry.h
MapDBEntrySprite
A map's sprite definition – base class for the four sprite kinds.
Definition
mapdbentrysprite.h:44
MapDBEntry
One map's complete static definition – the root of the MapDBEntry family.
Definition
mapdbentry.h:56
MissableDBEntry::MissableDBEntry
MissableDBEntry()
Empty entry (built by MissablesDB).
Definition
missabledbentry.cpp:35
MissableDBEntry::toMap
MapDBEntry * toMap
Resolved map (may be null; see note above).
Definition
missabledbentry.h:97
MissableDBEntry::deepLink
void deepLink()
Resolve the map + map-sprite links.
Definition
missabledbentry.cpp:50
MissableDBEntry::getSprite
int getSprite() const
Definition
missabledbentry.cpp:113
MissableDBEntry::defShow
bool defShow
Backing field (read via getDefShow()).
Definition
missabledbentry.h:88
MissableDBEntry::name
QString name
Backing field (read via getName()).
Definition
missabledbentry.h:80
MissableDBEntry::qmlRegister
void qmlRegister() const
Register with QML.
Definition
missabledbentry.cpp:82
MissableDBEntry::getToMap
MapDBEntry * getToMap() const
Definition
missabledbentry.cpp:103
MissableDBEntry::getName
const QString getName() const
< Missable name.
Definition
missabledbentry.cpp:128
MissableDBEntry::getDefShow
bool getDefShow() const
Definition
missabledbentry.cpp:108
MissableDBEntry::sprite
int sprite
Backing field (read via getSprite()).
Definition
missabledbentry.h:85
MissableDBEntry::ind
int ind
Backing field (read via getInd()).
Definition
missabledbentry.h:81
MissableDBEntry::getInd
int getInd() const
Definition
missabledbentry.cpp:123
MissableDBEntry::map
QString map
Backing field (read via getMap()).
Definition
missabledbentry.h:84
MissableDBEntry::getMap
const QString getMap() const
Definition
missabledbentry.cpp:118
MissableDBEntry::getToMapSprite
MapDBEntrySprite * getToMapSprite() const
Definition
missabledbentry.cpp:93
MissableDBEntry::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
missabledbentry.cpp:98
MissableDBEntry::toMapSprite
MapDBEntrySprite * toMapSprite
Resolved map sprite (may be null; see note above).
Definition
missabledbentry.h:98
utility.h
projects
db
src
pse-db
entries
missabledbentry.cpp
Generated by
1.17.0