Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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
34
35MapDBEntrySprite::MapDBEntrySprite(const QJsonValue& data, MapDBEntry* const parent) :
37{
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
56{
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
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
89{
90 return parent;
91}
92
93void MapDBEntrySprite::qmlProtect(const QQmlEngine* const engine) const
94{
95 Utility::qmlProtectUtil(this, engine);
96}
97
102
107
109{
110 return missable;
111}
112
113const QString MapDBEntrySprite::getFace() const
114{
115 return face;
116}
117
119{
120 return range;
121}
122
124{
125 return text;
126}
127
128const QString MapDBEntrySprite::getMove() const
129{
130 return move;
131}
132
134{
135 return y;
136}
137
139{
140 return x;
141}
142
143const QString MapDBEntrySprite::getSprite() const
144{
145 return sprite;
146}
147
148// Called from child classes
150#ifdef QT_DEBUG
151 qCritical() << "MapDBEntrySprite: Parent asked what child type is";
152#endif
153
154 return SpriteType::ERROR;
155}
156
158{
159 return x + 4;
160}
161
163{
164 return y + 4;
165}
MissableDBEntry * getIndAt(const QString val) const
Missable by name key (for QML).
static MissablesDB * inst()
< Number of missable definitions.
static SpritesDB * inst()
< Number of sprites.
Definition sprites.cpp:36
SpriteDBEntry * getIndAt(const QString &key) const
Sprite by name key (for QML).
Definition sprites.cpp:52
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
MissableDBEntry * toMissable
Resolved missable (deepLink).
int text
Interaction text id.
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
friend class MapDBEntry
int range
Wander range (exclusive with face).
MissableDBEntry * getToMissable() const
MapDBEntrySprite()
Empty entry.
virtual void deepLink()
Resolve sprite/missable links.
virtual SpriteType type() const
The sprite kind (overridden by subclasses).
const QString getMove() const
virtual void qmlRegister() const
Register with QML.
QString sprite
Sprite name (read via getSprite()).
MapDBEntry * parent
Owning map.
QString face
Static facing (exclusive with range).
MapDBEntry * getParent() const
const QString getSprite() const
int missable
Missable index, or -1.
SpriteDBEntry * toSprite
Resolved sprite picture (deepLink).
QString move
Movement mode (see note).
const QString getFace() const
SpriteDBEntry * getToSprite() const
SpriteType
< X adjusted for Gen 1 placement.
One missable definition: a script/sprite that can be hidden or shown.
One sprite definition: its name/picture-id and the maps that use it.
Definition sprites.h:38