Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
mapconndata.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
22
#include "
mapconndata.h
"
23
#include "
../../savefile.h
"
24
#include "
../../savefiletoolset.h
"
25
#include "
../../savefileiterator.h
"
26
#include <
pse-db/mapsdb.h
>
27
#include <
pse-db/entries/mapdbentry.h
>
28
#include <
pse-db/entries/mapdbentryconnect.h
>
29
30
#include <QRandomGenerator>
31
32
MapConnData::MapConnData
(
SaveFile
* saveFile,
var16
offset)
33
{
34
load
(saveFile, offset);
35
}
36
37
MapConnData::~MapConnData
() {}
38
39
void
MapConnData::load
(
SaveFile
* saveFile,
var16
offset)
40
{
41
reset
();
42
43
if
(saveFile ==
nullptr
) {
44
return
;
45
}
46
47
auto
it = saveFile->
iterator
()->
offsetTo
(offset);
48
49
mapPtr
= it->getByte();
50
mapPtrChanged
();
51
52
stripSrc
= it->getWord(0,
true
);
53
stripSrcChanged
();
54
55
stripDst
= it->getWord(0,
true
);
56
stripDstChanged
();
57
58
stripWidth
= it->getByte();
59
stripWidthChanged
();
60
61
width
= it->getByte();
62
widthChanged
();
63
64
yAlign
= it->getByte();
65
yAlignChanged
();
66
67
xAlign
= it->getByte();
68
xAlignChanged
();
69
70
viewPtr
= it->getWord(0,
true
);
71
viewPtrChanged
();
72
73
delete
it;
74
}
75
76
void
MapConnData::save
(
SaveFile
* saveFile,
var16
offset)
77
{
78
auto
it = saveFile->
iterator
()->
offsetTo
(offset);
79
80
it->
setByte
(
mapPtr
);
81
it->setWord(
stripSrc
, 0,
true
);
82
it->setWord(
stripDst
, 0,
true
);
83
it->setByte(
stripWidth
);
84
it->setByte(
width
);
85
it->setByte(
yAlign
);
86
it->setByte(
xAlign
);
87
it->setWord(
viewPtr
, 0,
true
);
88
89
delete
it;
90
}
91
92
void
MapConnData::reset
()
93
{
94
mapPtr
= 0;
95
mapPtrChanged
();
96
97
stripSrc
= 0;
98
stripSrcChanged
();
99
100
stripDst
= 0;
101
stripDstChanged
();
102
103
stripWidth
= 0;
104
stripWidthChanged
();
105
106
width
= 0;
107
widthChanged
();
108
109
yAlign
= 0;
110
yAlignChanged
();
111
112
xAlign
= 0;
113
xAlignChanged
();
114
115
viewPtr
= 0;
116
viewPtrChanged
();
117
}
118
119
void
MapConnData::loadFromData
(
MapDBEntryConnect
* connect) {
120
width
= connect->
getToMap
()->
getWidth
();
121
widthChanged
();
122
123
mapPtr
= connect->
getToMap
()->
getInd
();
124
mapPtrChanged
();
125
126
stripSrc
= connect->
stripLocation
();
127
stripSrcChanged
();
128
129
stripDst
= connect->
mapPos
();
130
stripDstChanged
();
131
132
stripWidth
= connect->
stripSize
();
133
stripWidthChanged
();
134
135
yAlign
= connect->
yAlign
();
136
yAlignChanged
();
137
138
xAlign
= connect->
xAlign
();
139
xAlignChanged
();
140
141
viewPtr
= connect->
window
();
142
viewPtrChanged
();
143
}
144
145
MapDBEntry
*
MapConnData::toMap
()
146
{
147
return
MapsDB::inst
()->
getIndAt
(QString::number(
mapPtr
));
148
}
MapConnData::loadFromData
void loadFromData(MapDBEntryConnect *connect)
Populate from a map-defined connection.
Definition
mapconndata.cpp:119
MapConnData::xAlignChanged
void xAlignChanged()
MapConnData::stripDstChanged
void stripDstChanged()
MapConnData::widthChanged
void widthChanged()
MapConnData::stripSrcChanged
void stripSrcChanged()
MapConnData::stripWidth
int stripWidth
Definition
mapconndata.h:76
MapConnData::stripWidthChanged
void stripWidthChanged()
MapConnData::reset
void reset()
Blank this connection.
Definition
mapconndata.cpp:92
MapConnData::toMap
MapDBEntry * toMap()
The connected map's DB entry.
Definition
mapconndata.cpp:145
MapConnData::mapPtrChanged
protected::void mapPtrChanged()
MapConnData::load
void load(SaveFile *saveFile=nullptr, var16 offset=0)
Expand a connection block from the save.
Definition
mapconndata.cpp:39
MapConnData::stripDst
int stripDst
Definition
mapconndata.h:75
MapConnData::width
int width
Definition
mapconndata.h:77
MapConnData::~MapConnData
virtual ~MapConnData()
Definition
mapconndata.cpp:37
MapConnData::mapPtr
int mapPtr
Definition
mapconndata.h:73
MapConnData::save
void save(SaveFile *saveFile, var16 offset)
Flatten a connection block to the save.
Definition
mapconndata.cpp:76
MapConnData::yAlign
int yAlign
Definition
mapconndata.h:78
MapConnData::yAlignChanged
void yAlignChanged()
MapConnData::MapConnData
MapConnData(SaveFile *saveFile=nullptr, var16 offset=0)
< Pointer to the connected map's data.
Definition
mapconndata.cpp:32
MapConnData::viewPtr
int viewPtr
Definition
mapconndata.h:80
MapConnData::xAlign
int xAlign
Definition
mapconndata.h:79
MapConnData::viewPtrChanged
void viewPtrChanged()
MapConnData::stripSrc
int stripSrc
Definition
mapconndata.h:74
MapsDB::inst
static MapsDB * inst()
< Number of maps.
Definition
mapsdb.cpp:35
MapsDB::getIndAt
MapDBEntry * getIndAt(const QString val) const
Map by name key (for QML).
Definition
mapsdb.cpp:155
SaveFileIterator::setByte
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
Definition
savefileiterator.cpp:173
SaveFileIterator::offsetTo
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
Definition
savefileiterator.cpp:31
SaveFile
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition
savefile.h:46
SaveFile::iterator
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
Definition
savefile.cpp:53
var16
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition
types.h:125
mapconndata.h
mapdbentry.h
mapdbentryconnect.h
mapsdb.h
savefile.h
savefileiterator.h
savefiletoolset.h
MapDBEntryConnect
One edge connection of a map (the seam to a neighbouring map).
Definition
mapdbentryconnect.h:60
MapDBEntryConnect::mapPos
int mapPos() const
Definition
mapdbentryconnect.cpp:151
MapDBEntryConnect::stripSize
int stripSize() const
Definition
mapdbentryconnect.cpp:178
MapDBEntryConnect::xAlign
int xAlign() const
Definition
mapdbentryconnect.cpp:257
MapDBEntryConnect::window
int window() const
Definition
mapdbentryconnect.cpp:288
MapDBEntryConnect::stripLocation
int stripLocation() const
Definition
mapdbentryconnect.cpp:118
MapDBEntryConnect::yAlign
int yAlign() const
Definition
mapdbentryconnect.cpp:232
MapDBEntryConnect::getToMap
MapDBEntry * getToMap() const
Definition
mapdbentryconnect.cpp:88
MapDBEntry
One map's complete static definition – the root of the MapDBEntry family.
Definition
mapdbentry.h:56
MapDBEntry::getWidth
int getWidth() const
Definition
mapdbentry.cpp:386
MapDBEntry::getInd
int getInd() const
Definition
mapdbentry.cpp:582
projects
savefile
src
pse-savefile
expanded
fragments
mapconndata.cpp
Generated by
1.17.0