Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
spritedata.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 <QObject>
18#include <QVector>
19#include "optional"
20#include <pse-common/types.h>
22
23class SaveFile;
24struct SpriteDBEntry;
25struct MapDBEntrySprite;
26struct MapDBEntry;
27struct TmpSpritePos;
28
31{
32 Q_OBJECT
34
35public:
43};
44
46struct SAVEFILE_AUTOPORT SpriteFacing : public QObject
47{
48 Q_OBJECT
49 Q_ENUMS(SpriteFacing_)
50
51public:
52 Q_INVOKABLE static var8 random();
53
54 // Place these in same scope
56 {
57 Down = 4 * 0,
58 Up = 4 * 1,
59 Left = 4 * 2,
60 Right = 4 * 3,
61 None = 0xFF
62 };
63};
64
66struct SAVEFILE_AUTOPORT SpriteMobility : public QObject
67{
68 Q_OBJECT
69 Q_ENUMS(SpriteMobility_)
70
71public:
72 Q_INVOKABLE static var8 random();
73
75 {
76 Moving = 0xFF,
77 NotMoving = 0xFE,
79 };
80};
81
83struct SAVEFILE_AUTOPORT SpriteMovement : public QObject
84{
85 Q_OBJECT
86 Q_ENUMS(SpriteMovement_)
87
88public:
89 Q_INVOKABLE static var8 random();
90
92 UpDown = 0x01,
93 LeftRight = 0x02,
94 Down = 0xD0,
95 Up = 0xD1,
96 Left = 0xD2,
97 Right = 0xD3,
98
99 // Allow to be moved with strength
100 // Does this apply only to boulders or any sprite or does it enable it
101 // For special scripted sprites???
103 };
104};
105
107struct SAVEFILE_AUTOPORT SpriteGrass : public QObject
108{
109 Q_OBJECT
110 Q_ENUMS(SpriteGrass_)
111
112public:
113 Q_INVOKABLE static var8 random();
114
116 {
117 InGrass = 0x00,
119 };
120};
121
138class SAVEFILE_AUTOPORT SpriteData : public QObject
139{
140 Q_OBJECT
141
142 Q_PROPERTY(int pictureID MEMBER pictureID NOTIFY pictureIDChanged)
143 Q_PROPERTY(int movementStatus MEMBER movementStatus NOTIFY movementStatusChanged)
144 Q_PROPERTY(int imageIndex MEMBER imageIndex NOTIFY imageIndexChanged)
145 Q_PROPERTY(int faceDir MEMBER faceDir NOTIFY faceDirChanged)
146 Q_PROPERTY(int yDisp MEMBER yDisp NOTIFY yDispChanged)
147 Q_PROPERTY(int xDisp MEMBER xDisp NOTIFY xDispChanged)
148 Q_PROPERTY(int mapY MEMBER mapY NOTIFY mapYChanged)
149 Q_PROPERTY(int mapX MEMBER mapX NOTIFY mapXChanged)
150 Q_PROPERTY(int movementByte MEMBER movementByte NOTIFY movementByteChanged)
151 Q_PROPERTY(int grassPriority MEMBER grassPriority NOTIFY grassPriorityChanged)
152 Q_PROPERTY(int yPixels MEMBER yPixels NOTIFY yPixelsChanged)
153 Q_PROPERTY(int xPixels MEMBER xPixels NOTIFY xPixelsChanged)
155 Q_PROPERTY(int animFrameCounter MEMBER animFrameCounter NOTIFY animFrameCounterChanged)
157 Q_PROPERTY(int movementDelay MEMBER movementDelay NOTIFY movementDelayChanged)
158 Q_PROPERTY(int imageBaseOffset MEMBER imageBaseOffset NOTIFY imageBaseOffsetChanged)
160 Q_PROPERTY(int textID READ getTextID WRITE setTextID RESET resetTextID NOTIFY textIDChanged)
164 Q_PROPERTY(int yStepVector READ getYStepVector WRITE setYStepVector NOTIFY yStepVectorChanged)
165 Q_PROPERTY(int xStepVector READ getXStepVector WRITE setXStepVector NOTIFY xStepVectorChanged)
166
167public:
169 SpriteData(bool blankNPC = false,
170 SaveFile* saveFile = nullptr,
171 var8 index = 0);
172
175
176 virtual ~SpriteData();
177
178 void load(bool blankNPC = false,
179 SaveFile* saveFile = nullptr,
180 var8 index = 0);
181
184 void load(MapDBEntrySprite* spriteData);
185
186 void loadSpriteData1(SaveFile* saveFile,
187 var8 index);
188 void loadSpriteData2(SaveFile* saveFile,
189 var8 index);
190 void loadSpriteDataNPC(SaveFile* saveFile,
191 var8 index);
192 void checkMissable(SaveFile* saveFile,
193 var8 index);
194
195 void save(SaveFile* saveFile,
196 var8 index);
197 void saveSpriteData1(SaveFile* saveFile,
198 var8 index);
199 void saveSpriteData2(SaveFile* saveFile,
200 var8 index);
201 void saveSpriteDataNPC(SaveFile* saveFile,
202 var8 index);
203
205
206 // Can't be Q_INVOKABLE for some reason, can't be placed into the
207 // Qt Meta System
208 static void saveMissables(SaveFile* saveFile,
209 QVector<SpriteData*> spriteData);
210
211 // These allow QML to work with std::optional values including resetting them
212 // They are interfaced with a Q_PROPERTY
213 int getRangeDirByte();
214 void setRangeDirByte(int val);
215 void resetRangeDirByte();
216 int getTextID();
217 void setTextID(int val);
218 void resetTextID();
220 void setTrainerClassOrItemID(int val);
222 int getTrainerSetID();
223 void setTrainerSetID(int val);
224 void resetTrainerSetID();
225 int getMissableIndex();
226 void setMissableIndex(int val);
227 void resetMissableIndex();
228
229 // These allow QML to work with values that require a var8 as QML can only
230 // read and write int's
231 // They are interfaced with a Q_PROPERTY
232 int getYStepVector();
233 void setYStepVector(int val);
234 int getXStepVector();
235 void setXStepVector(int val);
236
237signals:
262
263public slots:
264 void reset(bool blankNPC = false);
265 static QVector<SpriteData*> randomizeAll(QVector<MapDBEntrySprite*> mapSprites);
266 void randomize(QVector<TmpSpritePos*>* tmpPos);
267
268 void setTo(MapDBEntrySprite* spriteData);
269 static QVector<SpriteData*> setToAll(QVector<MapDBEntrySprite*> spriteSigns);
270
271public:
275
278
282
286
289
293 int yDisp;
294 int xDisp;
295
302 int mapY;
303 int mapX;
304
307
310
316
323
328
332
335
337
339
343
346
347 /*
348 * Sprite data that applies to all non-player sprites
349 * (All sprites that aren't sprite #0)
350 * In reality though the game doesn't use any sprite data at all for the
351 * player so none of this matters to begin with
352 */
353
358 std::optional<int> rangeDirByte;
359
361 std::optional<int> textID;
362
364 std::optional<int> trainerClassOrItemID;
365
367 std::optional<int> trainerSetID;
368
374
377 std::optional<int> missableIndex;
378};
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
void movementStatusChanged()
void loadSpriteData1(SaveFile *saveFile, var8 index)
Expand the first sprite-data table for index.
int grassPriority
(0x80 in grass, 0x00 otherwise) - Prioritizing grass drawn around sprite
Definition spritedata.h:309
void movementDelayChanged()
void setMissableIndex(int val)
int movementByte
(0xFF not moving, 0xFE random movements, others move without collision)
Definition spritedata.h:306
void load(bool blankNPC=false, SaveFile *saveFile=nullptr, var8 index=0)
std::optional< int > missableIndex
Sprite data that applies to all non-player missable sprites (All sprites that aren't sprite #0 and ha...
Definition spritedata.h:377
void yStepVectorChanged()
int getTrainerClassOrItemID()
std::optional< int > textID
Text id when this sprite is interacted with.
Definition spritedata.h:361
void xPixelsChanged()
void setTrainerSetID(int val)
void setXStepVector(int val)
void saveSpriteData2(SaveFile *saveFile, var8 index)
Flatten the second sprite-data table.
void saveSpriteData1(SaveFile *saveFile, var8 index)
Flatten the first sprite-data table.
void randomize(QVector< TmpSpritePos * > *tmpPos)
Randomize this sprite (avoiding tmpPos clashes).
void resetMissableIndex()
Clear the optional missableIndex.
SpriteData(bool blankNPC=false, SaveFile *saveFile=nullptr, var8 index=0)
Create a blank sprite or load one from a map.
int getTextID()
void setTrainerClassOrItemID(int val)
int movementDelay
Delay until next movement, counts downward and flags movementStatus ready once reached.
Definition spritedata.h:342
void setRangeDirByte(int val)
void movementByteChanged()
void mapYChanged()
void faceDirChanged()
std::optional< int > trainerSetID
Trainer data id.
Definition spritedata.h:367
void textIDChanged()
int getMissableIndex()
void mapXChanged()
void imageBaseOffsetChanged()
void trainerClassOrItemIDChanged()
void xStepVectorChanged()
void animFrameCounterChanged()
void setTextID(int val)
void save(SaveFile *saveFile, var8 index)
void loadSpriteData2(SaveFile *saveFile, var8 index)
Expand the second sprite-data table for index.
int imageBaseOffset
Used to help compute imageIndex based on vram.
Definition spritedata.h:345
int yDisp
Important to set to 0x8 Keep sprites from wandering too far however it's noted that it's bugged to be...
Definition spritedata.h:293
int yPixels
Screen position in pixels aligned to 4 pixels offset from the grid (To appear centered).
Definition spritedata.h:326
void loadSpriteDataNPC(SaveFile *saveFile, var8 index)
Expand the NPC-only sprite data for index.
int getRangeDirByte()
void reset(bool blankNPC=false)
Blank this sprite (optionally as a blank NPC).
void setYStepVector(int val)
void resetTextID()
Clear the optional textID.
std::optional< int > rangeDirByte
How far a walking sprite can wander, or if still the facing direction A walking sprite having a value...
Definition spritedata.h:358
void xDispChanged()
int mapY
These are very important to set, just usual coordinates for map placement +4 Coordinate 0,...
Definition spritedata.h:302
int getYStepVector()
void walkAnimationCounterChanged()
static QVector< SpriteData * > setToAll(QVector< MapDBEntrySprite * > spriteSigns)
Build sprites from a map's sprite list.
var8 xStepVector
Definition spritedata.h:322
var8 yStepVector
These actually don't really matter and can be zero I'm not sure if the game even uses these values in...
Definition spritedata.h:321
static void saveMissables(SaveFile *saveFile, QVector< SpriteData * > spriteData)
void setTo(MapDBEntrySprite *spriteData)
Copy values from a map-defined sprite.
static QVector< SpriteData * > randomizeAll(QVector< MapDBEntrySprite * > mapSprites)
Randomize a whole map's sprites.
int getTrainerSetID()
void saveSpriteDataNPC(SaveFile *saveFile, var8 index)
Flatten the NPC-only sprite data.
void resetTrainerClassOrItemID()
Clear the optional trainerClassOrItemID.
protected::void pictureIDChanged()
int movementStatus
(0: uninitialized, 1: ready, 2: delayed, 3: moving) Advised to use ready
Definition spritedata.h:281
void yDispChanged()
int getXStepVector()
void missableIndexChanged()
std::optional< int > trainerClassOrItemID
If this is an item sprite, the item id, otherwise the trainer class.
Definition spritedata.h:364
void resetTrainerSetID()
Clear the optional trainerSetID.
int animFrameCounter
Animation frame counter.
Definition spritedata.h:334
int walkAnimationCounter
Tracks movement & wandering, sprites are given 0x10 and it's decremented.
Definition spritedata.h:338
int faceDir
(0: down, 4: up, 8: left, $c: right)
Definition spritedata.h:288
SpriteDBEntry * toSprite()
Resolve this sprite to its DB entry.
int intraAnimationFrameCounter
Counter that helps delay between animation frames so things aren't so instant and fast.
Definition spritedata.h:331
void grassPriorityChanged()
int pictureID
Sprite data that applies to all sprites.
Definition spritedata.h:277
void intraAnimationFrameCounterChanged()
void imageIndexChanged()
void resetRangeDirByte()
Clear the optional rangeDirByte.
void rangeDirByteChanged()
int imageIndex
Basically, in the sprite sheet strip, which "pane" or "tile" is it at 0xFF if not on the screen.
Definition spritedata.h:285
void yPixelsChanged()
void trainerSetIDChanged()
void checkMissable(SaveFile *saveFile, var8 index)
Resolve whether this sprite is a missable.
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
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.
A map's sprite definition – base class for the four sprite kinds.
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56
One sprite definition: its name/picture-id and the maps that use it.
Definition sprites.h:38
Sprite facing-direction values, QML-visible.
Definition spritedata.h:47
static var8 random()
A random valid facing.
Sprite in-grass byte values, QML-visible.
Definition spritedata.h:108
static var8 random()
A random grass value.
Sprite mobility byte values, QML-visible.
Definition spritedata.h:67
static var8 random()
A random mobility value.
Sprite movement-status byte values, QML-visible.
Definition spritedata.h:31
@ Ready
Ready (advised value).
Definition spritedata.h:39
@ UnInit
Uninitialized.
Definition spritedata.h:38
Sprite movement-pattern byte values, QML-visible.
Definition spritedata.h:84
static var8 random()
A random movement pattern.