Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
mapdbentryconnect.h
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#pragma once
17#include <QObject>
18#include <QString>
19#include <QJsonValue>
20#include "../db_autoport.h"
21
22class MapDBEntry;
23class QQmlEngine;
24class MapDBEntry;
25
26/*
27 * A forewarning!!
28 *
29 * Map Connections are one of the most complicated aspects of the entire game
30 * by far and large. Out of any gen 1 data structure, forumlas, algorithms, math
31 * etc... Virtually out of anythign within the game code, this is the most
32 * complicated part. Anyone I've talked to and most docs I've read have all
33 * been in agreement. It's also one of the most difficult to get right and the
34 * most difficult to understand.
35 *
36 * If anything is slightly wrong, the game will liekly crash quickly or at the
37 * least not work right. So... yea... that's why it's inclusion is so late in
38 * this app and the reason why I've been so hesitant to bring in this
39 * functionality.
40 *
41 * Sources to help me:
42 *
43 * PokeRed Team
44 * https://github.com/pret/pokered/blob/master/macros/data_macros.asm
45 *
46 * Bulbapedia User Tiddlywinks
47 * https://bulbapedia.bulbagarden.net/wiki/User:Tiddlywinks/Map_header_data_structure_in_Generation_I
48*/
60struct DB_AUTOPORT MapDBEntryConnect : public QObject {
61 Q_OBJECT
62 Q_PROPERTY(int stripLocation READ stripLocation CONSTANT)
63 Q_PROPERTY(int mapPos READ mapPos CONSTANT)
64 Q_PROPERTY(int stripSize READ stripSize CONSTANT)
65 Q_PROPERTY(int yAlign READ yAlign CONSTANT)
66 Q_PROPERTY(int xAlign READ xAlign CONSTANT)
67 Q_PROPERTY(int window READ window CONSTANT)
68 Q_PROPERTY(ConnectDir getDir READ getDir CONSTANT)
69 Q_PROPERTY(QString getMap READ getMap CONSTANT)
70 Q_PROPERTY(int getStripMove READ getStripMove CONSTANT)
71 Q_PROPERTY(int getStripOffset READ getStripOffset CONSTANT)
72 Q_PROPERTY(bool getFlag READ getFlag CONSTANT)
73 Q_PROPERTY(MapDBEntry* getToMap READ getToMap CONSTANT)
74 Q_PROPERTY(MapDBEntry* getFromMap READ getFromMap CONSTANT)
75 Q_PROPERTY(MapDBEntry* getParent READ getParent CONSTANT)
76
77public:
78 // Hard-Coded value, this is the value that the gen 1 games use, it refers
79 // to a ram address that never changes related to the overworld map
80 static const constexpr int worldMapPtr = 0xC6E8;
81
90 Q_ENUM(ConnectDir)
91
92 // Location of strip
93 // Pointer to start in connected map
94 // AKA Strip Source
95 int stripLocation() const;
96
97 // Map Position
98 // Pointer to start of connection
99 // AKA Strip Dst
100 int mapPos() const;
101
102 // Strip Size
103 // Connection size (blocks)
104 // AKA stripWidth
105 int stripSize() const;
106
107 // Player Pos
108 // Player Y & X Offset (steps)
109 // AKA X-Align/Y-Align
110 int yAlign() const;
111 int xAlign() const;
112
113 // Map VRAM Offset
114 // Pointer to window
115 // AKA => viewPtr & UL Corner
116 int window() const;
117
118 ConnectDir getDir() const;
119 const QString getMap() const;
120 int getStripMove() const;
121 int getStripOffset() const;
122 bool getFlag() const;
123 MapDBEntry* getToMap() const;
124 MapDBEntry* getFromMap() const;
125 MapDBEntry* getParent() const;
126
127public slots:
128 void qmlProtect(const QQmlEngine* const engine) const;
129
130protected:
132 MapDBEntryConnect(const ConnectDir dir,
133 MapDBEntry* const fromMap,
134 const QJsonValue& data);
135 void deepLink();
136 void qmlRegister() const;
137
138 // Direction used in calculating
140
141 // Connecting Map
142 QString map = "";
143
144 // Connecting Strip Centering
145 int stripMove = 0;
146
147 // Connecting Strip Position
148 int stripOffset = 0;
149
150 // Offset strip by an additional 3 for unknown
151 // reasons
152 bool flag = false;
153
154 // To connecting map
155 MapDBEntry* toMap = nullptr;
156
157 // Map with connection
158 MapDBEntry* fromMap = nullptr;
159 MapDBEntry* parent = nullptr; // Basically the same thing, just an alias
160
161 friend class MapDBEntry;
162};
Import/export macro for the db library, plus the central list of DB entry pointer types declared opaq...
#define DB_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.
Definition db_autoport.h:37
One edge connection of a map (the seam to a neighbouring map).
const QString getMap() const
MapDBEntry * toMap
Resolved connected map (deepLink).
bool flag
+3 offset flag (purpose unknown; see note).
static const constexpr int worldMapPtr
< Strip source pointer.
int stripOffset
Strip position.
ConnectDir dir
Edge direction.
int stripMove
Strip centering.
MapDBEntry * fromMap
Owning map.
QString map
Connected map name.
MapDBEntry * getToMap() const
MapDBEntry * getParent() const
ConnectDir getDir() const
MapDBEntry * getFromMap() const
ConnectDir
The four connectable edges.
MapDBEntryConnect()
Empty entry.
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56