Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
halloffame.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
23
#include "
./halloffame.h
"
24
#include "
../qmlownership.h
"
25
#include "
../savefile.h
"
26
#include "
../savefiletoolset.h
"
27
#include "
../savefileiterator.h
"
28
#include "
./fragments/hofrecord.h
"
29
#include <
pse-common/random.h
>
30
31
HallOfFame::HallOfFame
(
SaveFile
* saveFile)
32
{
33
load
(saveFile);
34
}
35
36
HallOfFame::~HallOfFame
()
37
{
38
for
(
auto
record :
records
)
39
record->deleteLater();
40
}
41
42
int
HallOfFame::recordCount
()
43
{
44
return
records
.size();
45
}
46
47
int
HallOfFame::recordMax
()
48
{
49
return
recordsMax
;
50
}
51
52
HoFRecord
*
HallOfFame::recordAt
(
int
ind)
53
{
54
return
qmlCppOwned
(
records
.at(ind));
55
}
56
57
void
HallOfFame::recordSwap
(
int
from,
int
to)
58
{
59
auto
fRecord =
records
.at(from);
60
auto
tRecord =
records
.at(to);
61
62
records
.replace(from, tRecord);
63
records
.replace(to, fRecord);
64
65
recordsChanged
();
66
}
67
68
void
HallOfFame::recordRemove
(
int
ind)
69
{
70
if
(
records
.size() < 1)
71
return
;
72
73
records
.at(ind)->deleteLater();
74
records
.remove(ind);
75
76
recordsChanged
();
77
}
78
79
void
HallOfFame::recordNew
()
80
{
81
if
(
records
.size() >=
recordsMax
)
82
return
;
83
84
records
.append(
new
HoFRecord
);
85
recordsChanged
();
86
}
87
88
void
HallOfFame::load
(
SaveFile
* saveFile)
89
{
90
reset
();
91
92
if
(saveFile ==
nullptr
)
93
return
;
94
95
auto
toolset = saveFile->
toolset
;
96
97
var8
hofRecordCount = toolset->getByte(0x284E);
98
for
(
var8
i = 0; i < hofRecordCount && i <
recordsMax
; i++) {
99
records
.append(
new
HoFRecord
(saveFile, i));
100
}
101
102
recordsChanged
();
103
}
104
105
void
HallOfFame::save
(
SaveFile
* saveFile)
106
{
107
auto
toolset = saveFile->
toolset
;
108
109
toolset->
setByte
(0x284E,
records
.size());
110
for
(
var8
i = 0; i <
records
.size() && i <
recordsMax
; i++) {
111
records
.at(i)->save(saveFile, i);
112
}
113
}
114
115
void
HallOfFame::reset
()
116
{
117
for
(
auto
record :
records
)
118
record->deleteLater();
119
120
records
.clear();
121
recordsChanged
();
122
}
123
124
void
HallOfFame::randomize
()
125
{
126
reset
();
127
128
// Create up to 5 random records
129
var8
rndCount =
Random::inst
()->
rangeInclusive
(0, 5);
130
131
for
(
var8
i = 0; i < rndCount && i <
recordsMax
; i++) {
132
auto
tmp =
new
HoFRecord
;
133
records
.append(tmp);
134
tmp->randomize();
135
}
136
137
recordsChanged
();
138
}
HallOfFame::records
QVector< HoFRecord * > records
Every Hall of Fame record.
Definition
halloffame.h:68
HallOfFame::recordCount
int recordCount()
Number of records.
Definition
halloffame.cpp:42
HallOfFame::save
void save(SaveFile *saveFile)
Flatten the Hall of Fame records to the save.
Definition
halloffame.cpp:105
HallOfFame::randomize
void randomize()
Fill with random records.
Definition
halloffame.cpp:124
HallOfFame::~HallOfFame
virtual ~HallOfFame()
Definition
halloffame.cpp:36
HallOfFame::HallOfFame
HallOfFame(SaveFile *saveFile=nullptr)
Definition
halloffame.cpp:31
HallOfFame::recordAt
HoFRecord * recordAt(int ind)
Record ind (GC-protected return).
Definition
halloffame.cpp:52
HallOfFame::load
void load(SaveFile *saveFile=nullptr)
Expand the Hall of Fame records from the save.
Definition
halloffame.cpp:88
HallOfFame::recordsChanged
protected::void recordsChanged()
HallOfFame::reset
void reset()
Clear all records.
Definition
halloffame.cpp:115
HallOfFame::recordNew
void recordNew()
Add a fresh record.
Definition
halloffame.cpp:79
HallOfFame::recordMax
int recordMax()
Capacity (recordsMax).
Definition
halloffame.cpp:47
HallOfFame::recordSwap
void recordSwap(int from, int to)
Reorder records.
Definition
halloffame.cpp:57
HallOfFame::recordRemove
void recordRemove(int ind)
Remove record ind.
Definition
halloffame.cpp:68
HoFRecord
One Hall of Fame record: the team that beat the Elite Four, in order.
Definition
hofrecord.h:37
Random::rangeInclusive
int rangeInclusive(const int start, const int end) const
Random integer in the closed interval [start, end].
Definition
random.cpp:42
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
SaveFileToolset::setByte
void setByte(var16 addr, var8 val)
Simply sets a byte.
Definition
savefiletoolset.cpp:237
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::toolset
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
Definition
savefile.h:117
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
halloffame.h
recordsMax
constexpr var8 recordsMax
Maximum Hall of Fame records the save keeps.
Definition
halloffame.h:26
hofrecord.h
qmlownership.h
qmlCppOwned() – protect Q_INVOKABLE QObject returns from QML's GC.
qmlCppOwned
static T * qmlCppOwned(T *obj)
Hand QML CppOwnership of a C++-owned QObject returned from a Q_INVOKABLE.
Definition
qmlownership.h:43
random.h
savefile.h
savefileiterator.h
savefiletoolset.h
projects
savefile
src
pse-savefile
expanded
halloffame.cpp
Generated by
1.17.0