Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
pokemonstoragebox.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
18#include <QObject>
19#include <QVector>
20#include <pse-common/types.h>
22
23// PokemonBox is returned by the Q_INVOKABLE pokemonAt() below — full include so
24// QML receives a real (traversable) PokemonBox, not an opaque value.
25#include "./pokemonbox.h"
26
27class SaveFile;
28class PokemonBox;
29class PlayerBasics;
30
31// Maximum pokemon that can fit into a box
32constexpr var8 boxMaxPokemon = 20;
33
35
49{
50 Q_OBJECT
51
52 Q_PROPERTY(int pokemonCount READ pokemonCount NOTIFY pokemonChanged)
53 Q_PROPERTY(int isFull READ isFull NOTIFY pokemonChanged)
54 Q_PROPERTY(int pokemonMax READ pokemonMax CONSTANT)
55
56public:
58 PokemonStorageBox(int maxSize = boxMaxPokemon, SaveFile* saveFile = nullptr, var16 boxOffset = 0);
59 virtual ~PokemonStorageBox();
60
61 virtual void load(SaveFile* saveFile = nullptr, var16 boxOffset = 0);
62 virtual void save(SaveFile* saveFile, var16 boxOffset = 0);
63
64 int pokemonCount();
65 int pokemonMax();
66 bool isFull();
67
68 Q_INVOKABLE PokemonBox* pokemonAt(int ind);
69
70signals:
71 // When moving an item away from the box to another box, allow the model to
72 // perform cleanup actions
73 void beforePokemonRelocate(PokemonBox* item);
74
76 void pokemonMoveChange(int from, int to);
77 void pokemonRemoveChange(int ind);
80
81public slots:
82 void reset();
83 virtual void randomize(PlayerBasics* basics);
84
85 bool pokemonMove(int from, int to);
86 void pokemonRemove(int ind);
87 virtual void pokemonNew();
88
90 virtual bool relocateOne(PokemonStorageBox* dst, int ind);
91
92public:
93 bool isParty = false;
94 QVector<PokemonBox*> pokemon;
95 int maxSize = 0;
97};
The trainer's headline values: name, ID, money, coins, badges, starter.
A single Pokemon record – the most property-rich object in the tree.
Definition pokemonbox.h:213
bool isParty
True if this box is actually the party (affects record format).
void pokemonChanged()
Box contents changed.
virtual void randomize(PlayerBasics *basics)
Fill with constrained random mons.
int pokemonMax()
Capacity (maxSize).
virtual void pokemonNew()
Add a fresh mon.
void pokemonInsertChange()
A mon was inserted.
virtual void load(SaveFile *saveFile=nullptr, var16 boxOffset=0)
Expand the box from the save.
virtual bool relocateOne(PokemonStorageBox *dst, int ind)
Move one mon into dst.
QVector< PokemonBox * > pokemon
The stored mons.
void pokemonResetChange()
The box was reset.
virtual void save(SaveFile *saveFile, var16 boxOffset=0)
Flatten the box to the save.
void pokemonMoveChange(int from, int to)
A mon moved slot.
void reset()
Empty the box.
SaveFile * file
Owning save.
bool pokemonMove(int from, int to)
Reorder a mon within the box.
bool relocateAll(PokemonStorageBox *dst)
Move every mon into dst.
bool isFull()
At capacity.
int pokemonCount()
Number of mons present.
PokemonStorageBox(int maxSize=boxMaxPokemon, SaveFile *saveFile=nullptr, var16 boxOffset=0)
< How many mons are in the box.
PokemonBox * pokemonAt(int ind)
Mon at ind (GC-protected return).
void pokemonRemove(int ind)
Remove the mon at ind.
void pokemonRemoveChange(int ind)
A mon was removed.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
Project-wide fixed-width integer aliases (var8, var16, ...).
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition types.h:125
constexpr var8 boxMaxPokemon
Capacity of a single PC box.
Import/export macro for the savefile library, plus the central list of QObject types kept deliberatel...
#define SAVEFILE_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.