Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
areasign.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 "areasign.h"
23#include "../../qmlownership.h"
25#include "../../savefile.h"
28#include <pse-db/mapsdb.h>
29#include <pse-common/random.h>
31
33{
34 load(saveFile);
35}
36
38{
39 for(auto sign : signs)
40 sign->deleteLater();
41}
42
44{
45 return signs.size();
46}
47
49{
50 return maxSigns;
51}
52
54{
55 return qmlCppOwned(signs.at(ind));
56}
57
58void AreaSign::signSwap(int from, int to)
59{
60 auto eFrom = signs.at(from);
61 auto eTo = signs.at(to);
62
63 signs.replace(from, eTo);
64 signs.replace(to, eFrom);
65
67}
68
70{
71 if(signs.size() <= 0)
72 return;
73
74 signs.at(ind)->deleteLater();
75 signs.removeAt(ind);
77}
78
80{
81 if(signs.size() >= maxSigns)
82 return;
83
84 signs.append(new SignData);
86}
87
88void AreaSign::load(SaveFile* saveFile)
89{
90 reset();
91
92 if(saveFile == nullptr)
93 return;
94
95 auto toolset = saveFile->toolset;
96
97 for (var8 i = 0; i < toolset->getByte(0x275C) && i < 16; i++) {
98 signs.append(new SignData(saveFile, i));
99 }
100
101 signsChanged();
102}
103
105{
106 auto toolset = saveFile->toolset;
107
108 toolset->setByte(0x275C, signs.size());
109 for (var8 i = 0; i < signs.size() && i < 16; i++) {
110 signs.at(i)->save(saveFile, i);
111 }
112}
113
115{
116 for(auto sign : signs)
117 sign->deleteLater();
118
119 signs.clear();
120
121 signsChanged();
122}
123
125{
126 // Clear all signs
127 reset();
128
129 // Grab Map Signs
130 auto signData = mapData->getSigns();
131
132 // Randomize them all if present
133 signs = SignData::randomizeAll(signData);
134 signsChanged();
135}
136
138{
139 // Clear all signs
140 reset();
141
142 // Stop here if map is null
143 if(mapData == nullptr)
144 return;
145
146 // Grab Map Signs
147 auto signData = mapData->getSigns();
148
149 // Set them all if present
150 signs = SignData::setToAll(signData);
151 signsChanged();
152}
constexpr var8 maxSigns
Maximum signs on a map.
Definition areasign.h:26
void signSwap(int from, int to)
Reorder signs.
Definition areasign.cpp:58
void save(SaveFile *saveFile)
Flatten the sign list to the save.
Definition areasign.cpp:104
AreaSign(SaveFile *saveFile=nullptr)
Definition areasign.cpp:32
void signNew()
Add a fresh sign.
Definition areasign.cpp:79
void signRemove(int ind)
Remove sign ind.
Definition areasign.cpp:69
void load(SaveFile *saveFile=nullptr)
Expand the sign list from the save.
Definition areasign.cpp:88
void randomize(MapDBEntry *mapData)
Randomize signs for mapData.
Definition areasign.cpp:124
int signMax()
Capacity (maxSigns).
Definition areasign.cpp:48
QVector< SignData * > signs
The map's signs.
Definition areasign.h:64
SignData * signAt(int ind)
Sign ind (GC-protected return).
Definition areasign.cpp:53
void setTo(MapDBEntry *mapData)
Rebuild the list from mapData's signs.
Definition areasign.cpp:137
int signCount()
Number of signs.
Definition areasign.cpp:43
protected::void signsChanged()
virtual ~AreaSign()
Definition areasign.cpp:37
void reset()
Empty the sign list.
Definition areasign.cpp:114
void setByte(var16 addr, var8 val)
Simply sets a byte.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
Definition savefile.h:117
One sign on the current map: its tile position and text id.
Definition signdata.h:37
static QVector< SignData * > randomizeAll(QVector< MapDBEntrySign * > mapSigns)
Randomize a whole map's signs.
Definition signdata.cpp:87
static QVector< SignData * > setToAll(QVector< MapDBEntrySign * > mapSigns)
Build signs from a map's sign list.
Definition signdata.cpp:135
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
qmlCppOwned() – protect Q_INVOKABLE QObject returns from QML's GC.
static T * qmlCppOwned(T *obj)
Hand QML CppOwnership of a C++-owned QObject returned from a Q_INVOKABLE.
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56
const QVector< MapDBEntrySign * > getSigns() const
Signs on the map.