Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
mapdbentrysprite.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
22
#include <QJsonValue>
23
#include <QDebug>
24
#include <QQmlEngine>
25
#include <
pse-common/utility.h
>
26
27
#include "
./mapdbentrysprite.h
"
28
#include "
../sprites.h
"
29
#include "
../missablesdb.h
"
30
31
MapDBEntrySprite::MapDBEntrySprite
() {
32
qmlRegister
();
33
}
34
35
MapDBEntrySprite::MapDBEntrySprite
(
const
QJsonValue& data,
MapDBEntry
*
const
parent
) :
36
parent
(
parent
)
37
{
38
qmlRegister
();
39
40
sprite
= data[
"sprite"
].toString();
41
x
= data[
"x"
].toDouble();
42
y
= data[
"y"
].toDouble();
43
move
= data[
"move"
].toString();
44
text
= data[
"text"
].toDouble();
45
46
if
(data[
"missable"
].isDouble())
47
missable
= data[
"missable"
].toDouble();
48
49
if
(data[
"range"
].isDouble())
50
range
= data[
"range"
].toDouble();
51
else
52
face
= data[
"face"
].toString();
53
}
54
55
void
MapDBEntrySprite::deepLink
()
56
{
57
toSprite
=
SpritesDB::inst
()->
getIndAt
(
sprite
);
58
59
if
(
missable
>= 0)
60
toMissable
=
MissablesDB::inst
()->
getIndAt
(QString::number(
missable
));
61
62
#ifdef QT_DEBUG
63
if
(
toSprite
==
nullptr
)
64
qCritical() <<
"MapDBEntrySprite: Unable to deep link "
+
sprite
+
" to sprite"
;
65
66
if
(
move
==
""
||
text
== 0 || (!
range
&&
face
==
""
))
67
qCritical() <<
"Values are not correct on sprite "
+
sprite
;
68
69
if
(
missable
>= 0 &&
toMissable
==
nullptr
)
70
qCritical() <<
"Missable cannot be deep linked to "
+ QString::number(
missable
);
71
#endif
72
73
if
(
toSprite
!=
nullptr
)
74
toSprite
->toMaps.append(
this
);
75
}
76
77
void
MapDBEntrySprite::qmlRegister
()
const
78
{
79
static
bool
once =
false
;
80
if
(once)
81
return
;
82
83
qmlRegisterUncreatableType<MapDBEntrySprite>(
84
"PSE.DB.MapDBEntrySprite"
, 1, 0,
"MapDBEntrySprite"
,
"Can't instantiate in QML"
);
85
once =
true
;
86
}
87
88
MapDBEntry
*
MapDBEntrySprite::getParent
()
const
89
{
90
return
parent
;
91
}
92
93
void
MapDBEntrySprite::qmlProtect
(
const
QQmlEngine*
const
engine)
const
94
{
95
Utility::qmlProtectUtil
(
this
, engine);
96
}
97
98
SpriteDBEntry
*
MapDBEntrySprite::getToSprite
()
const
99
{
100
return
toSprite
;
101
}
102
103
MissableDBEntry
*
MapDBEntrySprite::getToMissable
()
const
104
{
105
return
toMissable
;
106
}
107
108
int
MapDBEntrySprite::getMissable
()
const
109
{
110
return
missable
;
111
}
112
113
const
QString
MapDBEntrySprite::getFace
()
const
114
{
115
return
face
;
116
}
117
118
int
MapDBEntrySprite::getRange
()
const
119
{
120
return
range
;
121
}
122
123
int
MapDBEntrySprite::getText
()
const
124
{
125
return
text
;
126
}
127
128
const
QString
MapDBEntrySprite::getMove
()
const
129
{
130
return
move
;
131
}
132
133
int
MapDBEntrySprite::getY
()
const
134
{
135
return
y
;
136
}
137
138
int
MapDBEntrySprite::getX
()
const
139
{
140
return
x
;
141
}
142
143
const
QString
MapDBEntrySprite::getSprite
()
const
144
{
145
return
sprite
;
146
}
147
148
// Called from child classes
149
MapDBEntrySprite::SpriteType
MapDBEntrySprite::type
()
const
{
150
#ifdef QT_DEBUG
151
qCritical() <<
"MapDBEntrySprite: Parent asked what child type is"
;
152
#endif
153
154
return
SpriteType::ERROR
;
155
}
156
157
int
MapDBEntrySprite::adjustedX
()
const
158
{
159
return
x
+ 4;
160
}
161
162
int
MapDBEntrySprite::adjustedY
()
const
163
{
164
return
y
+ 4;
165
}
MissablesDB::getIndAt
MissableDBEntry * getIndAt(const QString val) const
Missable by name key (for QML).
Definition
missablesdb.cpp:59
MissablesDB::inst
static MissablesDB * inst()
< Number of missable definitions.
Definition
missablesdb.cpp:30
SpritesDB::inst
static SpritesDB * inst()
< Number of sprites.
Definition
sprites.cpp:36
SpritesDB::getIndAt
SpriteDBEntry * getIndAt(const QString &key) const
Sprite by name key (for QML).
Definition
sprites.cpp:52
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
mapdbentrysprite.h
missablesdb.h
sprites.h
MapDBEntrySprite::toMissable
MissableDBEntry * toMissable
Resolved missable (deepLink).
Definition
mapdbentrysprite.h:134
MapDBEntrySprite::getRange
int getRange() const
Definition
mapdbentrysprite.cpp:118
MapDBEntrySprite::text
int text
Interaction text id.
Definition
mapdbentrysprite.h:124
MapDBEntrySprite::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
mapdbentrysprite.cpp:93
MapDBEntrySprite::MapDBEntry
friend class MapDBEntry
Definition
mapdbentrysprite.h:143
MapDBEntrySprite::range
int range
Wander range (exclusive with face).
Definition
mapdbentrysprite.h:129
MapDBEntrySprite::getToMissable
MissableDBEntry * getToMissable() const
Definition
mapdbentrysprite.cpp:103
MapDBEntrySprite::MapDBEntrySprite
MapDBEntrySprite()
Empty entry.
Definition
mapdbentrysprite.cpp:31
MapDBEntrySprite::deepLink
virtual void deepLink()
Resolve sprite/missable links.
Definition
mapdbentrysprite.cpp:55
MapDBEntrySprite::type
virtual SpriteType type() const
The sprite kind (overridden by subclasses).
Definition
mapdbentrysprite.cpp:149
MapDBEntrySprite::getMove
const QString getMove() const
Definition
mapdbentrysprite.cpp:128
MapDBEntrySprite::adjustedX
int adjustedX() const
Definition
mapdbentrysprite.cpp:157
MapDBEntrySprite::x
int x
Raw X.
Definition
mapdbentrysprite.h:114
MapDBEntrySprite::qmlRegister
virtual void qmlRegister() const
Register with QML.
Definition
mapdbentrysprite.cpp:77
MapDBEntrySprite::sprite
QString sprite
Sprite name (read via getSprite()).
Definition
mapdbentrysprite.h:111
MapDBEntrySprite::parent
MapDBEntry * parent
Owning map.
Definition
mapdbentrysprite.h:140
MapDBEntrySprite::getY
int getY() const
Definition
mapdbentrysprite.cpp:133
MapDBEntrySprite::face
QString face
Static facing (exclusive with range).
Definition
mapdbentrysprite.h:130
MapDBEntrySprite::getMissable
int getMissable() const
Definition
mapdbentrysprite.cpp:108
MapDBEntrySprite::getParent
MapDBEntry * getParent() const
Definition
mapdbentrysprite.cpp:88
MapDBEntrySprite::getSprite
const QString getSprite() const
Definition
mapdbentrysprite.cpp:143
MapDBEntrySprite::y
int y
Raw Y.
Definition
mapdbentrysprite.h:115
MapDBEntrySprite::missable
int missable
Missable index, or -1.
Definition
mapdbentrysprite.h:133
MapDBEntrySprite::getX
int getX() const
Definition
mapdbentrysprite.cpp:138
MapDBEntrySprite::toSprite
SpriteDBEntry * toSprite
Resolved sprite picture (deepLink).
Definition
mapdbentrysprite.h:137
MapDBEntrySprite::move
QString move
Movement mode (see note).
Definition
mapdbentrysprite.h:121
MapDBEntrySprite::getFace
const QString getFace() const
Definition
mapdbentrysprite.cpp:113
MapDBEntrySprite::adjustedY
int adjustedY() const
Definition
mapdbentrysprite.cpp:162
MapDBEntrySprite::getToSprite
SpriteDBEntry * getToSprite() const
Definition
mapdbentrysprite.cpp:98
MapDBEntrySprite::getText
int getText() const
Definition
mapdbentrysprite.cpp:123
MapDBEntrySprite::SpriteType
SpriteType
< X adjusted for Gen 1 placement.
Definition
mapdbentrysprite.h:66
MapDBEntrySprite::ERROR
@ ERROR
Definition
mapdbentrysprite.h:81
MissableDBEntry
One missable definition: a script/sprite that can be hidden or shown.
Definition
missabledbentry.h:51
SpriteDBEntry
One sprite definition: its name/picture-id and the maps that use it.
Definition
sprites.h:38
utility.h
projects
db
src
pse-db
entries
mapdbentrysprite.cpp
Generated by
1.17.0