Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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"
26#include <pse-db/mapsdb.h>
29
30#include <QRandomGenerator>
31
33{
34 load(saveFile, offset);
35}
36
38
39void 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();
51
52 stripSrc = it->getWord(0, true);
54
55 stripDst = it->getWord(0, true);
57
58 stripWidth = it->getByte();
60
61 width = it->getByte();
63
64 yAlign = it->getByte();
66
67 xAlign = it->getByte();
69
70 viewPtr = it->getWord(0, true);
72
73 delete it;
74}
75
76void 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
93{
94 mapPtr = 0;
96
97 stripSrc = 0;
99
100 stripDst = 0;
102
103 stripWidth = 0;
105
106 width = 0;
107 widthChanged();
108
109 yAlign = 0;
111
112 xAlign = 0;
114
115 viewPtr = 0;
117}
118
120 width = connect->getToMap()->getWidth();
121 widthChanged();
122
123 mapPtr = connect->getToMap()->getInd();
125
126 stripSrc = connect->stripLocation();
128
129 stripDst = connect->mapPos();
131
132 stripWidth = connect->stripSize();
134
135 yAlign = connect->yAlign();
137
138 xAlign = connect->xAlign();
140
141 viewPtr = connect->window();
143}
144
146{
147 return MapsDB::inst()->getIndAt(QString::number(mapPtr));
148}
void loadFromData(MapDBEntryConnect *connect)
Populate from a map-defined connection.
void xAlignChanged()
void stripDstChanged()
void widthChanged()
void stripSrcChanged()
void stripWidthChanged()
void reset()
Blank this connection.
MapDBEntry * toMap()
The connected map's DB entry.
protected::void mapPtrChanged()
void load(SaveFile *saveFile=nullptr, var16 offset=0)
Expand a connection block from the save.
virtual ~MapConnData()
void save(SaveFile *saveFile, var16 offset)
Flatten a connection block to the save.
void yAlignChanged()
MapConnData(SaveFile *saveFile=nullptr, var16 offset=0)
< Pointer to the connected map's data.
void viewPtrChanged()
static MapsDB * inst()
< Number of maps.
Definition mapsdb.cpp:35
MapDBEntry * getIndAt(const QString val) const
Map by name key (for QML).
Definition mapsdb.cpp:155
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
Definition savefile.cpp:53
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition types.h:125
One edge connection of a map (the seam to a neighbouring map).
MapDBEntry * getToMap() const
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56
int getWidth() const
int getInd() const