Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
playerbasics.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#include <QVector>
18#include <QObject>
19#include <QString>
20#include <pse-common/types.h>
22
23class SaveFile;
24class PokemonBox;
25struct PokemonDBEntry;
26
33struct SAVEFILE_AUTOPORT Badges : public QObject
34{
35 Q_OBJECT
36 Q_ENUMS(Badges_)
37
38public:
49};
50
51constexpr var8 maxBadges = 8;
52
66class SAVEFILE_AUTOPORT PlayerBasics : public QObject
67{
68 Q_OBJECT
69
70 // We use the full-set versions of playername and ID so that all QML changes
71 // will properly update non-trade mons and keep the non-trade status. Otherwise
72 // the user will have to manually go through and change all of the non-trade mons
73 // OT Name and OT ID after changing it here which is undesirable.
74 Q_PROPERTY(QString playerName READ getPlayerName WRITE fullSetPlayerName NOTIFY playerNameChanged)
75 Q_PROPERTY(int playerID READ getPlayerId WRITE fullSetPlayerId NOTIFY playerIDChanged)
76 Q_PROPERTY(unsigned int money MEMBER money NOTIFY moneyChanged)
77 Q_PROPERTY(int coins MEMBER coins NOTIFY coinsChanged)
78 Q_PROPERTY(int playerStarter MEMBER playerStarter NOTIFY playerStarterChanged)
79
80public:
81 PlayerBasics(SaveFile* saveFile = nullptr);
82 virtual ~PlayerBasics();
83
84 void load(SaveFile* saveFile = nullptr);
85 void save(SaveFile* saveFile);
86 void setBadges(SaveFile* saveFile, var16 offset);
87
89
90 Q_INVOKABLE int badgeCount();
91 Q_INVOKABLE bool badgeAt(int ind);
92 Q_INVOKABLE void badgeSet(int ind, bool val);
93
94 QString getPlayerName();
95 int getPlayerId();
96
97 QVector<PokemonBox*> getNonTradeMons();
98 void fixNonTradeMons(QVector<PokemonBox*> mons);
99
100signals:
107
108public slots:
109 void reset();
110 void randomize();
111
112 // Full Set also goes through the Pokemon and ensures non-traded pokemon are
113 // properly updated
114 void fullSetPlayerName(QString val);
115 void fullSetPlayerId(int id);
116
117 void randomizeStarter();
118 void randomizeCoins();
119 void randomizeMoney();
120 void randomizeID();
121
122public:
123 QString playerName;
125 unsigned int money;
126 int coins;
128 false, // Boulder
129 false, // Cascade
130 false, // Thunder
131 false, // Rainbow
132 false, // Soul
133 false, // Marsh
134 false, // Volcano
135 false // Earth
136 };
138
139 SaveFile* file = nullptr;
140};
void save(SaveFile *saveFile)
Flatten the trainer basics back to the save.
void moneyChanged()
void randomizeMoney()
Randomize just the money.
QString getPlayerName()
Current trainer name (backs the property READ).
void playerIDChanged()
void fullSetPlayerName(QString val)
Set name AND fix non-trade mons' OT name.
int coins
Casino coins.
void randomize()
Randomize the trainer basics (constrained).
QVector< PokemonBox * > getNonTradeMons()
All party/box mons whose OT is this trainer (not traded in).
unsigned int money
Money value.
int playerID
Trainer ID (backs the property).
SaveFile * file
Owning save (used by the full-set helpers to reach the mons).
int getPlayerId()
Current trainer ID (backs the property READ).
QString playerName
Trainer name (backs the property).
void randomizeStarter()
Randomize just the starter.
void randomizeCoins()
Randomize just the coin count.
bool badgeAt(int ind)
Is badge ind set?
void playerStarterChanged()
int badgeCount()
How many badges are set.
void coinsChanged()
void fullSetPlayerId(int id)
Set ID AND fix non-trade mons' OT ID.
void badgesChanged()
PlayerBasics(SaveFile *saveFile=nullptr)
< Trainer name; writing it full-sets non-trade mons (see note above).
void reset()
Blank the trainer basics.
protected::void playerNameChanged()
void fixNonTradeMons(QVector< PokemonBox * > mons)
Rewrite those mons' OT name/ID to match this trainer.
void badgeSet(int ind, bool val)
Set/clear badge ind.
void randomizeID()
Randomize just the trainer ID.
int playerStarter
Chosen starter species.
void load(SaveFile *saveFile=nullptr)
Expand the trainer basics from the save.
void setBadges(SaveFile *saveFile, var16 offset)
Write the badge bits at offset.
bool badges[maxBadges]
Per-badge owned flags, indexed by Badges::Badges_.
PokemonDBEntry * toStarter()
Resolve playerStarter to its DB entry.
A single Pokemon record – the most property-rich object in the tree.
Definition pokemonbox.h:213
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 maxBadges
Number of Gym badges.
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.
The eight Gym badges, in bit order, as a QML-visible enum.
@ Rainbow
Rainbow Badge (Erika).
@ Cascade
Cascade Badge (Misty).
@ Thunder
Thunder Badge (Lt. Surge).
@ Boulder
Boulder Badge (Brock).
@ Volcano
Volcano Badge (Blaine).
@ Marsh
Marsh Badge (Sabrina).
@ Soul
Soul Badge (Koga).
@ Earth
Earth Badge (Giovanni).
One species' complete static data – the richest entry in the db layer.
Definition pokemon.h:98