-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tile-manager.h
96 lines (72 loc) · 2.25 KB
/
tile-manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef TILE_MANAGER_H
#define TILE_MANAGER_H
#include <array>
#include <cstddef>
#include <QColor>
#include <QFile>
#include <QObject>
#include <QPixmap>
#include <QVector>
#include "libsonassmd.h"
#include "palette.h"
#include "signal-wrapper.h"
class TileManager : public QObject
{
Q_OBJECT
public:
enum class PixmapType
{
NO_BACKGROUND,
WITH_BACKGROUND,
TRANSPARENT,
MAX
};
static constexpr int TILE_WIDTH = 8;
static constexpr int TILE_HEIGHT = 8;
static constexpr int TILE_SIZE_IN_BYTES = TILE_WIDTH * TILE_HEIGHT / 2;
TileManager(const SignalWrapper<Palette> &palette_manager);
void unloadTiles()
{
tiles.clear();
tile_pixmaps.clear();
emit pixmapsChanged();
}
void loadTilesFromFile(const QString &file_path, libsonassmd::Tiles::Format format)
{
tiles = Tiles(file_path.toStdString(), format);
tile_pixmaps.resize(tiles.size()); // TODO: Reserve instead?
regeneratePixmaps();
}
const QPixmap& pixmaps(const int tile_index, const int palette_line, const PixmapType type) const
{
if (tile_index >= tile_pixmaps.size())
return invalid_tile_pixmaps[static_cast<std::size_t>(type)];
else
return tile_pixmaps[tile_index][palette_line][static_cast<std::size_t>(type)];
}
int total_tiles() const
{
return tile_pixmaps.size();
}
void deleteTile(int tile_index);
void duplicateTile(int tile_index, int insert_index);
void clearTile(int tile_index);
void modifyTiles(const std::function<void(std::vector<libsonassmd::Tile>&)> &callback);
auto& getTiles() const
{
return tiles;
}
signals:
void pixmapsChanged();
private slots:
void regeneratePixmaps();
private:
void regeneratePixmap(int tile_index);
std::array<QPixmap, static_cast<std::size_t>(PixmapType::MAX)> createPixmaps(const std::array<std::array<QColor, TILE_WIDTH>, TILE_HEIGHT> rgb_pixels);
static std::array<std::array<QColor, TILE_WIDTH>, TILE_HEIGHT> createInvalidTilePixmap();
const Palette &palette;
std::array<QPixmap, static_cast<std::size_t>(PixmapType::MAX)> invalid_tile_pixmaps;
Tiles tiles;
QVector<std::array<std::array<QPixmap, static_cast<std::size_t>(PixmapType::MAX)>, Palette::TOTAL_LINES>> tile_pixmaps;
};
#endif // TILE_MANAGER_H