Fix tileset editor including unused primary metatiles

This commit is contained in:
GriffinR 2022-10-06 02:09:49 -04:00
parent e70b049887
commit 2fc4b6b53b

View file

@ -13,7 +13,7 @@ TilesetEditorMetatileSelector::TilesetEditorMetatileSelector(Tileset *primaryTil
} }
QImage TilesetEditorMetatileSelector::buildAllMetatilesImage() { QImage TilesetEditorMetatileSelector::buildAllMetatilesImage() {
return this->buildImage(0, Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles.length()); return this->buildImage(0, this->primaryTileset->metatiles.length() + this->secondaryTileset->metatiles.length());
} }
QImage TilesetEditorMetatileSelector::buildPrimaryMetatilesImage() { QImage TilesetEditorMetatileSelector::buildPrimaryMetatilesImage() {
@ -30,12 +30,19 @@ QImage TilesetEditorMetatileSelector::buildImage(int metatileIdStart, int numMet
// Round up height for incomplete last row // Round up height for incomplete last row
numMetatilesHigh++; numMetatilesHigh++;
} }
int numPrimary = this->primaryTileset->metatiles.length();
int maxPrimary = Project::getNumMetatilesPrimary();
bool includesPrimary = metatileIdStart < maxPrimary;
QImage image(this->numMetatilesWide * 32, numMetatilesHigh * 32, QImage::Format_RGBA8888); QImage image(this->numMetatilesWide * 32, numMetatilesHigh * 32, QImage::Format_RGBA8888);
image.fill(Qt::magenta); image.fill(Qt::magenta);
QPainter painter(&image); QPainter painter(&image);
for (int i = 0; i < numMetatiles; i++) { for (int i = 0; i < numMetatiles; i++) {
int metatileId = i + metatileIdStart;
if (includesPrimary && metatileId >= numPrimary)
metatileId += maxPrimary - numPrimary; // Skip over unused region of primary tileset
QImage metatile_image = getMetatileImage( QImage metatile_image = getMetatileImage(
i + metatileIdStart, metatileId,
this->primaryTileset, this->primaryTileset,
this->secondaryTileset, this->secondaryTileset,
map->metatileLayerOrder, map->metatileLayerOrder,