Fix 'getBlock' functions use for tiles, add getTilePixels to API
This commit is contained in:
parent
6f872b7d96
commit
1abdb301c1
10 changed files with 78 additions and 34 deletions
|
@ -44,7 +44,7 @@ public:
|
|||
uint8_t terrainType; // FRLG only
|
||||
QString label;
|
||||
|
||||
static int getBlockIndex(int);
|
||||
static int getIndexInTileset(int);
|
||||
static QPoint coordFromPixmapCoord(const QPointF &pixelCoord);
|
||||
};
|
||||
|
||||
|
|
|
@ -6,25 +6,16 @@
|
|||
class Tile
|
||||
{
|
||||
public:
|
||||
Tile() :
|
||||
tileId(0),
|
||||
xflip(false),
|
||||
yflip(false),
|
||||
palette(0)
|
||||
{ }
|
||||
|
||||
Tile(int tileId, bool xflip, bool yflip, int palette) :
|
||||
tileId(tileId),
|
||||
xflip(xflip),
|
||||
yflip(yflip),
|
||||
palette(palette)
|
||||
{ }
|
||||
Tile();
|
||||
Tile(int tileId, bool xflip, bool yflip, int palette);
|
||||
|
||||
public:
|
||||
int tileId;
|
||||
bool xflip;
|
||||
bool yflip;
|
||||
int palette;
|
||||
|
||||
static int getIndexInTileset(int);
|
||||
};
|
||||
|
||||
#endif // TILE_H
|
||||
|
|
|
@ -34,7 +34,8 @@ public:
|
|||
QList<QList<QRgb>> palettes;
|
||||
QList<QList<QRgb>> palettePreviews;
|
||||
|
||||
static Tileset* getBlockTileset(int, Tileset*, Tileset*);
|
||||
static Tileset* getMetatileTileset(int, Tileset*, Tileset*);
|
||||
static Tileset* getTileTileset(int, Tileset*, Tileset*);
|
||||
static Metatile* getMetatile(int, Tileset*, Tileset*);
|
||||
static QList<QList<QRgb>> getBlockPalettes(Tileset*, Tileset*, bool useTruePalettes = false);
|
||||
static QList<QRgb> getPalette(int, Tileset*, Tileset*, bool useTruePalettes = false);
|
||||
|
|
|
@ -173,6 +173,7 @@ public:
|
|||
Q_INVOKABLE QJSValue getMetatileTiles(int metatileId, int tileStart = 0, int tileEnd = -1);
|
||||
Q_INVOKABLE void setMetatileTiles(int metatileId, QJSValue tilesObj, int tileStart = 0, int tileEnd = -1, bool forceRedraw = true);
|
||||
Q_INVOKABLE void setMetatileTiles(int metatileId, int tileId, bool xflip, bool yflip, int palette, int tileStart = 0, int tileEnd = -1, bool forceRedraw = true);
|
||||
Q_INVOKABLE QJSValue getTilePixels(int tileId);
|
||||
Q_INVOKABLE int getNumTilesInMetatile();
|
||||
Q_INVOKABLE int getNumMetatileLayers();
|
||||
Q_INVOKABLE QString getBaseGameVersion();
|
||||
|
|
|
@ -27,6 +27,7 @@ SOURCES += src/core/block.cpp \
|
|||
src/core/metatileparser.cpp \
|
||||
src/core/paletteutil.cpp \
|
||||
src/core/parseutil.cpp \
|
||||
src/core/tile.cpp \
|
||||
src/core/tileset.cpp \
|
||||
src/core/regionmap.cpp \
|
||||
src/core/wildmoninfo.cpp \
|
||||
|
|
|
@ -9,11 +9,11 @@ Metatile::Metatile() :
|
|||
terrainType(0)
|
||||
{ }
|
||||
|
||||
int Metatile::getBlockIndex(int index) {
|
||||
if (index < Project::getNumMetatilesPrimary()) {
|
||||
return index;
|
||||
int Metatile::getIndexInTileset(int metatileId) {
|
||||
if (metatileId < Project::getNumMetatilesPrimary()) {
|
||||
return metatileId;
|
||||
} else {
|
||||
return index - Project::getNumMetatilesPrimary();
|
||||
return metatileId - Project::getNumMetatilesPrimary();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
24
src/core/tile.cpp
Normal file
24
src/core/tile.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "tile.h"
|
||||
#include "project.h"
|
||||
|
||||
Tile::Tile() :
|
||||
tileId(0),
|
||||
xflip(false),
|
||||
yflip(false),
|
||||
palette(0)
|
||||
{ }
|
||||
|
||||
Tile::Tile(int tileId, bool xflip, bool yflip, int palette) :
|
||||
tileId(tileId),
|
||||
xflip(xflip),
|
||||
yflip(yflip),
|
||||
palette(palette)
|
||||
{ }
|
||||
|
||||
int Tile::getIndexInTileset(int tileId) {
|
||||
if (tileId < Project::getNumTilesPrimary()) {
|
||||
return tileId;
|
||||
} else {
|
||||
return tileId - Project::getNumTilesPrimary();
|
||||
}
|
||||
}
|
|
@ -59,21 +59,33 @@ Tileset &Tileset::operator=(const Tileset &other) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
Tileset* Tileset::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
if (metatile_index < Project::getNumMetatilesPrimary()) {
|
||||
Tileset* Tileset::getTileTileset(int tileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
if (tileId < Project::getNumTilesPrimary()) {
|
||||
return primaryTileset;
|
||||
} else {
|
||||
} else if (tileId < Project::getNumTilesTotal()) {
|
||||
return secondaryTileset;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Metatile* Tileset::getMetatile(int index, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
Tileset *tileset = Tileset::getBlockTileset(index, primaryTileset, secondaryTileset);
|
||||
int local_index = Metatile::getBlockIndex(index);
|
||||
Tileset* Tileset::getMetatileTileset(int metatileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
if (metatileId < Project::getNumMetatilesPrimary()) {
|
||||
return primaryTileset;
|
||||
} else if (metatileId < Project::getNumMetatilesTotal()) {
|
||||
return secondaryTileset;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Metatile* Tileset::getMetatile(int metatileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
Tileset *tileset = Tileset::getMetatileTileset(metatileId, primaryTileset, secondaryTileset);
|
||||
int index = Metatile::getIndexInTileset(metatileId);
|
||||
if (!tileset) {
|
||||
return nullptr;
|
||||
}
|
||||
return tileset->metatiles.value(local_index, nullptr);
|
||||
return tileset->metatiles.value(index, nullptr);
|
||||
}
|
||||
|
||||
bool Tileset::metatileIsValid(uint16_t metatileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
|
|
|
@ -812,8 +812,8 @@ void MainWindow::setMetatileLayerOpacity(QList<float> order) {
|
|||
}
|
||||
|
||||
void MainWindow::saveMetatilesByMetatileId(int metatileId) {
|
||||
Tileset * tileset = Tileset::getBlockTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
if (this->editor->project)
|
||||
Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
if (this->editor->project && tileset)
|
||||
this->editor->project->saveTilesetMetatiles(tileset);
|
||||
|
||||
// Refresh anything that can display metatiles (except the actual map view)
|
||||
|
@ -828,8 +828,8 @@ void MainWindow::saveMetatilesByMetatileId(int metatileId) {
|
|||
}
|
||||
|
||||
void MainWindow::saveMetatileAttributesByMetatileId(int metatileId) {
|
||||
Tileset * tileset = Tileset::getBlockTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
if (this->editor->project)
|
||||
Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
if (this->editor->project && tileset)
|
||||
this->editor->project->saveTilesetMetatileAttributes(tileset);
|
||||
|
||||
// If the Tileset Editor is currently displaying the updated metatile, refresh it
|
||||
|
@ -1008,6 +1008,20 @@ void MainWindow::setMetatileTile(int metatileId, int tileIndex, QJSValue tileObj
|
|||
this->setMetatileTiles(metatileId, tile.tileId, tile.xflip, tile.yflip, tile.palette, tileIndex, tileIndex, forceRedraw);
|
||||
}
|
||||
|
||||
QJSValue MainWindow::getTilePixels(int tileId) {
|
||||
if (tileId < 0 || !this->editor || !this->editor->project || !this->editor->map || !this->editor->map->layout)
|
||||
return QJSValue();
|
||||
QImage tileImage = getTileImage(tileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
|
||||
if (tileImage.isNull() || tileImage.sizeInBytes() < 64)
|
||||
return QJSValue();
|
||||
const uchar * pixels = tileImage.constBits();
|
||||
QJSValue pixelArray = Scripting::getEngine()->newArray(64);
|
||||
for (int i = 0; i < 64; i++) {
|
||||
pixelArray.setProperty(i, pixels[i]);
|
||||
}
|
||||
return pixelArray;
|
||||
}
|
||||
|
||||
int MainWindow::getNumTilesInMetatile() {
|
||||
return projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ QImage getMetatileImage(
|
|||
bool useTruePalettes)
|
||||
{
|
||||
Metatile* metatile = Tileset::getMetatile(metatileId, primaryTileset, secondaryTileset);
|
||||
Tileset* blockTileset = Tileset::getBlockTileset(metatileId, primaryTileset, secondaryTileset);
|
||||
Tileset* blockTileset = Tileset::getMetatileTileset(metatileId, primaryTileset, secondaryTileset);
|
||||
if (!metatile || !blockTileset) {
|
||||
QImage metatile_image(16, 16, QImage::Format_RGBA8888);
|
||||
metatile_image.fill(Qt::magenta);
|
||||
|
@ -106,12 +106,12 @@ QImage getMetatileImage(
|
|||
}
|
||||
|
||||
QImage getTileImage(uint16_t tileId, Tileset *primaryTileset, Tileset *secondaryTileset) {
|
||||
Tileset *tileset = Tileset::getBlockTileset(tileId, primaryTileset, secondaryTileset);
|
||||
int local_index = Metatile::getBlockIndex(tileId);
|
||||
Tileset *tileset = Tileset::getTileTileset(tileId, primaryTileset, secondaryTileset);
|
||||
int index = Tile::getIndexInTileset(tileId);
|
||||
if (!tileset) {
|
||||
return QImage();
|
||||
}
|
||||
return tileset->tiles.value(local_index, QImage());
|
||||
return tileset->tiles.value(index, QImage());
|
||||
}
|
||||
|
||||
QImage getColoredTileImage(uint16_t tileId, Tileset *primaryTileset, Tileset *secondaryTileset, QList<QRgb> palette) {
|
||||
|
|
Loading…
Reference in a new issue