Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
mapdbentrywarpout.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 <QDebug>
23#include <QQmlEngine>
24#include <pse-common/utility.h>
25#include "mapdbentrywarpout.h"
26#include "./mapdbentry.h"
27#include "./mapdbentrywarpin.h"
28#include "../mapsdb.h"
29
35{
37 x = data["x"].toDouble();
38 y = data["y"].toDouble();
39 warp = data["toWarp"].toDouble();
40 map = data["toMap"].toString();
41 glitch = data["glitch"].toBool(false);
42}
43
45{
46 toMap = MapsDB::inst()->getInd().value(map, nullptr);
47
48#ifdef QT_DEBUG
49 // Stop here if toMap is nullptr
50 if(toMap == nullptr) {
51 qCritical() << "Map Warp Out entry: " << map << ", could not be deep linked to map";
52 return;
53 }
54#endif
55
56 // Stop here if this is a special warp to simply return to the last map
57 if(map == "Last Map")
58 return;
59
60 // Also stop here if this is the silph co elevator which warps to an invalid
61 // map. Why would the elevator do this? No idea.
62 if(map == "237")
63 return;
64
65 // Deep link to the destination warp coordinates
66 // This will immidiately crash if toMap isn't set
67 toWarp = const_cast<MapDBEntryWarpIn*>(toMap->getWarpInAt(warp));
68
69 toWarp->toConnectingWarps.append(this);
70}
71
73{
74 static bool once = false;
75 if(once)
76 return;
77
78 qmlRegisterUncreatableType<MapDBEntryWarpOut>(
79 "PSE.DB.MapDBEntryWarpOut", 1, 0, "MapDBEntryWarpOut", "Can't instantiate in QML");
80 once = true;
81}
82
87
88void MapDBEntryWarpOut::qmlProtect(const QQmlEngine* const engine) const
89{
90 Utility::qmlProtectUtil(this, engine);
91}
92
97
99{
100 return toMap;
101}
102
104{
105 return glitch;
106}
107
108const QString MapDBEntryWarpOut::getMap() const
109{
110 return map;
111}
112
114{
115 return warp;
116}
117
119{
120 return y;
121}
122
124{
125 return x;
126}
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
MapDBEntryWarpOut()
Empty entry.
MapDBEntry * toMap
Resolved destination map (deepLink).
MapDBEntryWarpIn * getToWarp() const
void deepLink()
Resolve the destination map + warp-in.
MapDBEntryWarpIn * toWarp
Resolved destination warp-in (deepLink).
friend class MapDBEntry
int getX() const
< Warp-out tile X.
friend class MapDBEntryWarpIn
void qmlRegister() const
Register with QML.
const QString getMap() const
int x
Warp-out tile X.
int y
Warp-out tile Y.
MapDBEntry * getParent() const
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
MapDBEntry * parent
Owning map.
QString map
Destination map name.
bool glitch
Glitch/unintended warp.
MapDBEntry * getToMap() const
int warp
Target warp-in index.