Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
spriteSet.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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 <QJsonValue>
20#include <QString>
21#include <QVector>
22#include <QHash>
23#include <optional>
24
25#include <pse-common/types.h>
26#include "./db_autoport.h"
27
28struct SpriteDBEntry;
29struct MapDBEntry;
30class QQmlEngine;
31
32// Outdoor sprites have to be pre-loaded into memory.
33// A SpriteSet is a group of up to 11 sprites kept in memory for a given
34// outdoor area. Large maps may use two sets split by coordinate.
35
49 SpriteSetDBEntry(QJsonValue& data);
50 void deepLink();
51
52 [[nodiscard]] bool isDynamic() const;
53 [[nodiscard]] QVector<SpriteDBEntry*> getSprites(var8 x, var8 y) const;
54
55 var8 ind = 0;
56 QString split;
57
58 QVector<QString> spriteList;
59 QVector<SpriteDBEntry*> toSprites;
60
61 std::optional<var8> splitAt;
62 std::optional<var8> setWN;
63 std::optional<var8> setES;
64
67
68 QVector<MapDBEntry*> toMaps;
69};
70
78class DB_AUTOPORT SpriteSetDB : public QObject
79{
80 Q_OBJECT
81 Q_PROPERTY(int getStoreSize READ getStoreSize CONSTANT)
82
83public:
84 static SpriteSetDB* inst();
85
86 [[nodiscard]] const QVector<SpriteSetDBEntry*> getStore() const;
87 [[nodiscard]] const QHash<QString, SpriteSetDBEntry*> getInd() const;
88 [[nodiscard]] int getStoreSize() const;
89
90 Q_INVOKABLE SpriteSetDBEntry* getStoreAt(int idx) const;
91 Q_INVOKABLE SpriteSetDBEntry* getIndAt(const QString& key) const;
92
93public slots:
94 void load();
95 void index();
96 void deepLink();
97 void qmlProtect(const QQmlEngine* const engine) const;
98
99private slots:
100 void qmlRegister() const;
101
102private:
103 SpriteSetDB();
104
105 QVector<SpriteSetDBEntry*> store;
106 QHash<QString, SpriteSetDBEntry*> ind;
107};
int getStoreSize() const
Set count.
Definition spriteSet.cpp:97
void deepLink()
Resolve sprites, split neighbours, and maps.
void load()
Load sprite-sets from JSON.
static SpriteSetDB * inst()
< Number of sprite-sets.
Definition spriteSet.cpp:89
const QVector< SpriteSetDBEntry * > getStore() const
All sprite-sets.
Definition spriteSet.cpp:95
const QHash< QString, SpriteSetDBEntry * > getInd() const
Name->entry index.
Definition spriteSet.cpp:96
SpriteSetDBEntry * getStoreAt(int idx) const
Set by store index (for QML).
Definition spriteSet.cpp:99
void index()
Build the name->entry index.
SpriteSetDBEntry * getIndAt(const QString &key) const
Set by name key (for QML).
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
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 db library, plus the central list of DB entry pointer types declared opaq...
#define DB_AUTOPORT
Expands to the correct dllexport/dllimport decoration for this library.
Definition db_autoport.h:37
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
One sprite-set: the pre-loaded sprite group for an outdoor area.
Definition spriteSet.h:47
SpriteSetDBEntry()
Empty entry.
Definition spriteSet.cpp:35
QVector< SpriteDBEntry * > toSprites
Resolved sprites (deepLink).
Definition spriteSet.h:59
SpriteSetDBEntry * toSetES
Resolved East/South set (deepLink).
Definition spriteSet.h:66
bool isDynamic() const
True if this set is split by coordinate.
Definition spriteSet.cpp:79
void deepLink()
Resolve sprite list + split neighbours + maps.
Definition spriteSet.cpp:54
QVector< SpriteDBEntry * > getSprites(var8 x, var8 y) const
Sprites active at (x,y).
Definition spriteSet.cpp:81
std::optional< var8 > splitAt
Coordinate the set splits at, if dynamic.
Definition spriteSet.h:61
QVector< QString > spriteList
Sprite names in this set.
Definition spriteSet.h:58
std::optional< var8 > setES
East/South sub-set index, if split.
Definition spriteSet.h:63
std::optional< var8 > setWN
West/North sub-set index, if split.
Definition spriteSet.h:62
var8 ind
Set index.
Definition spriteSet.h:55
QVector< MapDBEntry * > toMaps
Maps using this set (back-ref).
Definition spriteSet.h:68
SpriteSetDBEntry * toSetWN
Resolved West/North set (deepLink).
Definition spriteSet.h:65
QString split
Split descriptor.
Definition spriteSet.h:56