Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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
39{
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
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
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
97
98void MissableDBEntry::qmlProtect(const QQmlEngine* const engine) const
99{
100 Utility::qmlProtectUtil(this, engine);
101}
102
104{
105 return toMap;
106}
107
109{
110 return defShow;
111}
112
114{
115 return sprite;
116}
117
118const QString MissableDBEntry::getMap() const
119{
120 return map;
121}
122
124{
125 return ind;
126}
127
128const QString MissableDBEntry::getName() const
129{
130 return name;
131}
static MapsDB * inst()
< Number of maps.
Definition mapsdb.cpp:35
const QHash< QString, MapDBEntry * > getInd() const
Name->map index.
Definition mapsdb.cpp:46
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
A map's sprite definition – base class for the four sprite kinds.
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56
MissableDBEntry()
Empty entry (built by MissablesDB).
MapDBEntry * toMap
Resolved map (may be null; see note above).
void deepLink()
Resolve the map + map-sprite links.
bool defShow
Backing field (read via getDefShow()).
QString name
Backing field (read via getName()).
void qmlRegister() const
Register with QML.
MapDBEntry * getToMap() const
const QString getName() const
< Missable name.
bool getDefShow() const
int sprite
Backing field (read via getSprite()).
int ind
Backing field (read via getInd()).
QString map
Backing field (read via getMap()).
const QString getMap() const
MapDBEntrySprite * getToMapSprite() const
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
MapDBEntrySprite * toMapSprite
Resolved map sprite (may be null; see note above).