diff --git a/include/core/metatile.h b/include/core/metatile.h index c016ae7c..5b9bb813 100644 --- a/include/core/metatile.h +++ b/include/core/metatile.h @@ -11,16 +11,17 @@ class Metatile { public: Metatile(); + Metatile(const Metatile &other) = default; + Metatile &operator=(const Metatile &other) = default; + public: - QList *tiles = nullptr; + QList tiles; uint16_t behavior; // 8 bits RSE, 9 bits FRLG uint8_t layerType; uint8_t encounterType; // FRLG only uint8_t terrainType; // FRLG only QString label; - Metatile *copy(); - void copyInPlace(Metatile*); static int getBlockIndex(int); static QPoint coordFromPixmapCoord(const QPointF &pixelCoord); }; diff --git a/include/core/metatileparser.h b/include/core/metatileparser.h index 7bf0b096..2008d60f 100644 --- a/include/core/metatileparser.h +++ b/include/core/metatileparser.h @@ -10,7 +10,7 @@ class MetatileParser { public: MetatileParser(); - QList *parse(QString filepath, bool *error, bool primaryTileset); + QList parse(QString filepath, bool *error, bool primaryTileset); }; #endif // METATILEPARSER_H diff --git a/include/core/tile.h b/include/core/tile.h index e2b1ec4d..dfcb7117 100644 --- a/include/core/tile.h +++ b/include/core/tile.h @@ -6,8 +6,20 @@ class Tile { public: - Tile() {} - Tile(int tile, bool xflip, bool yflip, int palette); + Tile() : + tile(0), + xflip(false), + yflip(false), + palette(0) + { } + + Tile(int tile, bool xflip, bool yflip, int palette) : + tile(tile), + xflip(xflip), + yflip(yflip), + palette(palette) + { } + public: int tile; bool xflip; diff --git a/include/core/tileset.h b/include/core/tileset.h index c6349cfe..2ffeea85 100644 --- a/include/core/tileset.h +++ b/include/core/tileset.h @@ -9,7 +9,10 @@ class Tileset { public: - Tileset(); + Tileset() = default; + Tileset(const Tileset &other) = default; + Tileset &operator=(const Tileset &other) = default; + public: QString name; QString is_compressed; @@ -24,14 +27,12 @@ public: QString metatile_attrs_path; QString tilesImagePath; QImage tilesImage; - QList palettePaths; + QStringList palettePaths; - QList *tiles = nullptr; - QList *metatiles = nullptr; - QList> *palettes = nullptr; - QList> *palettePreviews = nullptr; - - Tileset* copy(); + QList tiles; + QList metatiles; + QList> palettes; + QList> palettePreviews; static Tileset* getBlockTileset(int, Tileset*, Tileset*); static Metatile* getMetatile(int, Tileset*, Tileset*); diff --git a/include/mainwindow.h b/include/mainwindow.h index 4d333e5c..63d430a7 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -77,8 +77,8 @@ public: Q_INVOKABLE void setPrimaryTilesetPalettes(QList>> palettes); Q_INVOKABLE void setSecondaryTilesetPalette(int paletteIndex, QList> colors); Q_INVOKABLE void setSecondaryTilesetPalettes(QList>> palettes); - QJSValue getTilesetPalette(QList> *palettes, int paletteIndex); - QJSValue getTilesetPalettes(QList> *palettes); + QJSValue getTilesetPalette(const QList> &palettes, int paletteIndex); + QJSValue getTilesetPalettes(const QList> &palettes); Q_INVOKABLE QJSValue getPrimaryTilesetPalette(int paletteIndex); Q_INVOKABLE QJSValue getPrimaryTilesetPalettes(); Q_INVOKABLE QJSValue getSecondaryTilesetPalette(int paletteIndex); diff --git a/porymap.pro b/porymap.pro index 1c3b2fac..91763837 100644 --- a/porymap.pro +++ b/porymap.pro @@ -25,7 +25,6 @@ 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 \ diff --git a/src/core/metatile.cpp b/src/core/metatile.cpp index e870dcad..4c97418d 100644 --- a/src/core/metatile.cpp +++ b/src/core/metatile.cpp @@ -2,35 +2,12 @@ #include "tileset.h" #include "project.h" -Metatile::Metatile() -{ - tiles = new QList; -} - -Metatile* Metatile::copy() { - Metatile *copy = new Metatile; - copy->behavior = this->behavior; - copy->layerType = this->layerType; - copy->encounterType = this->encounterType; - copy->terrainType = this->terrainType; - copy->tiles = new QList; - copy->label = this->label; - for (Tile tile : *this->tiles) { - copy->tiles->append(tile); - } - return copy; -} - -void Metatile::copyInPlace(Metatile *other) { - this->behavior = other->behavior; - this->layerType = other->layerType; - this->encounterType = other->encounterType; - this->terrainType = other->terrainType; - this->label = other->label; - for (int i = 0; i < this->tiles->length(); i++) { - (*this->tiles)[i] = other->tiles->at(i); - } -} +Metatile::Metatile() : + behavior(0), + layerType(0), + encounterType(0), + terrainType(0) +{ } int Metatile::getBlockIndex(int index) { if (index < Project::getNumMetatilesPrimary()) { diff --git a/src/core/metatileparser.cpp b/src/core/metatileparser.cpp index 7c52c187..3bbed668 100644 --- a/src/core/metatileparser.cpp +++ b/src/core/metatileparser.cpp @@ -8,13 +8,13 @@ MetatileParser::MetatileParser() } -QList *MetatileParser::parse(QString filepath, bool *error, bool primaryTileset) +QList MetatileParser::parse(QString filepath, bool *error, bool primaryTileset) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { *error = true; logError(QString("Could not open Advance Map 1.92 Metatile .bvd file '%1': ").arg(filepath) + file.errorString()); - return nullptr; + return { }; } QByteArray in = file.readAll(); @@ -23,7 +23,7 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim if (in.length() < 9 || in.length() % 2 != 0) { *error = true; logError(QString("Advance Map 1.92 Metatile .bvd file '%1' is an unexpected size.").arg(filepath)); - return nullptr; + return { }; } int projIdOffset = in.length() - 4; @@ -46,7 +46,7 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim } else { *error = true; logError(QString("Detected unsupported game type from .bvd file. Last 4 bytes of file must be 'RSE ' or 'FRLG'.")); - return nullptr; + return { }; } int maxMetatiles = primaryTileset ? Project::getNumMetatilesPrimary() : Project::getNumMetatilesTotal() - Project::getNumMetatilesPrimary(); @@ -57,32 +57,32 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim if (numMetatiles > maxMetatiles) { *error = true; logError(QString(".bvd file contains data for %1 metatiles, but the maximum number of metatiles is %2.").arg(numMetatiles).arg(maxMetatiles)); - return nullptr; + return { }; } if (numMetatiles < 1) { *error = true; logError(QString(".bvd file contains no data for metatiles.")); - return nullptr; + return { }; } int expectedFileSize = 4 + (metatileSize * numMetatiles) + (attrSize * numMetatiles) + 4; if (in.length() != expectedFileSize) { *error = true; logError(QString(".bvd file is an unexpected size. Expected %1 bytes, but it has %2 bytes.").arg(expectedFileSize).arg(in.length())); - return nullptr; + return { }; } - QList *metatiles = new QList(); + QList metatiles; for (int i = 0; i < numMetatiles; i++) { Metatile *metatile = new Metatile(); - QList *tiles = new QList(); + QList tiles; for (int j = 0; j < 8; j++) { int metatileOffset = 4 + i * metatileSize + j * 2; uint16_t word = static_cast( static_cast(in.at(metatileOffset)) | (static_cast(in.at(metatileOffset + 1)) << 8)); Tile tile(word & 0x3ff, (word >> 10) & 1, (word >> 11) & 1, (word >> 12) & 0xf); - tiles->append(tile); + tiles.append(tile); } int attrOffset = 4 + (numMetatiles * metatileSize) + (i * attrSize); @@ -104,7 +104,7 @@ QList *MetatileParser::parse(QString filepath, bool *error, bool prim metatile->terrainType = 0; } metatile->tiles = tiles; - metatiles->append(metatile); + metatiles.append(metatile); } return metatiles; diff --git a/src/core/tile.cpp b/src/core/tile.cpp deleted file mode 100644 index 1077f98f..00000000 --- a/src/core/tile.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "tile.h" - -Tile::Tile(int tile, bool xflip, bool yflip, int palette) -{ - this->tile = tile; - this->xflip = xflip; - this->yflip = yflip; - this->palette = palette; -} diff --git a/src/core/tileset.cpp b/src/core/tileset.cpp index b3c81bc5..f710f165 100644 --- a/src/core/tileset.cpp +++ b/src/core/tileset.cpp @@ -7,55 +7,6 @@ #include #include -Tileset::Tileset() -{ - -} - -Tileset* Tileset::copy() { - Tileset *copy = new Tileset; - copy->name = this->name; - copy->is_compressed = this->is_compressed; - copy->is_secondary = this->is_secondary; - copy->padding = this->padding; - copy->tiles_label = this->tiles_label; - copy->palettes_label = this->palettes_label; - copy->metatiles_label = this->metatiles_label; - copy->metatiles_path = this->metatiles_path; - copy->callback_label = this->callback_label; - copy->metatile_attrs_label = this->metatile_attrs_label; - copy->metatile_attrs_path = this->metatile_attrs_path; - copy->tilesImage = this->tilesImage.copy(); - copy->tilesImagePath = this->tilesImagePath; - for (int i = 0; i < this->palettePaths.length(); i++) { - copy->palettePaths.append(this->palettePaths.at(i)); - } - copy->tiles = new QList; - for (QImage tile : *this->tiles) { - copy->tiles->append(tile.copy()); - } - copy->metatiles = new QList; - for (Metatile *metatile : *this->metatiles) { - copy->metatiles->append(metatile->copy()); - } - copy->palettes = new QList>; - for (QList palette : *this->palettes) { - QList copyPalette; - for (QRgb color : palette) { - copyPalette.append(color); - } - copy->palettes->append(copyPalette); - } - copy->palettePreviews = new QList>; - for (QList palette : *this->palettePreviews) { - QList copyPalette; - for (QRgb color : palette) { - copyPalette.append(color); - } - copy->palettePreviews->append(copyPalette); - } - return copy; -} Tileset* Tileset::getBlockTileset(int metatile_index, Tileset *primaryTileset, Tileset *secondaryTileset) { if (metatile_index < Project::getNumMetatilesPrimary()) { @@ -68,21 +19,20 @@ Tileset* Tileset::getBlockTileset(int metatile_index, Tileset *primaryTileset, T Metatile* Tileset::getMetatile(int index, Tileset *primaryTileset, Tileset *secondaryTileset) { Tileset *tileset = Tileset::getBlockTileset(index, primaryTileset, secondaryTileset); int local_index = Metatile::getBlockIndex(index); - if (!tileset || !tileset->metatiles) { + if (!tileset) { return nullptr; } - Metatile *metatile = tileset->metatiles->value(local_index, nullptr); - return metatile; + return tileset->metatiles.value(local_index, nullptr); } bool Tileset::metatileIsValid(uint16_t metatileId, Tileset *primaryTileset, Tileset *secondaryTileset) { if (metatileId >= Project::getNumMetatilesTotal()) return false; - if (metatileId < Project::getNumMetatilesPrimary() && metatileId >= primaryTileset->metatiles->length()) + if (metatileId < Project::getNumMetatilesPrimary() && metatileId >= primaryTileset->metatiles.length()) return false; - if (metatileId >= Project::getNumMetatilesPrimary() + secondaryTileset->metatiles->length()) + if (metatileId >= Project::getNumMetatilesPrimary() + secondaryTileset->metatiles.length()) return false; return true; @@ -92,11 +42,11 @@ QList> Tileset::getBlockPalettes(Tileset *primaryTileset, Tileset *s QList> palettes; auto primaryPalettes = useTruePalettes ? primaryTileset->palettes : primaryTileset->palettePreviews; for (int i = 0; i < Project::getNumPalettesPrimary(); i++) { - palettes.append(primaryPalettes->at(i)); + palettes.append(primaryPalettes.at(i)); } auto secondaryPalettes = useTruePalettes ? secondaryTileset->palettes : secondaryTileset->palettePreviews; for (int i = Project::getNumPalettesPrimary(); i < Project::getNumPalettesTotal(); i++) { - palettes.append(secondaryPalettes->at(i)); + palettes.append(secondaryPalettes.at(i)); } return palettes; } @@ -107,8 +57,8 @@ QList Tileset::getPalette(int paletteId, Tileset *primaryTileset, Tileset ? primaryTileset : secondaryTileset; auto palettes = useTruePalettes ? tileset->palettes : tileset->palettePreviews; - for (int i = 0; i < palettes->at(paletteId).length(); i++) { - paletteTable.append(palettes->at(paletteId).at(i)); + for (int i = 0; i < palettes.at(paletteId).length(); i++) { + paletteTable.append(palettes.at(paletteId).at(i)); } return paletteTable; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 559c6f4c..caff3893 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1212,46 +1212,39 @@ void MainWindow::on_actionNew_Tileset_triggered() { newSet->metatile_attrs_path = fullDirectoryPath + "/metatile_attributes.bin"; newSet->is_secondary = createTilesetDialog->isSecondary ? "TRUE" : "FALSE"; int numMetaTiles = createTilesetDialog->isSecondary ? (Project::getNumTilesTotal() - Project::getNumTilesPrimary()) : Project::getNumTilesPrimary(); - QImage *tilesImage = new QImage(":/images/blank_tileset.png"); - editor->project->loadTilesetTiles(newSet, *tilesImage); - newSet->metatiles = new QList(); + QImage tilesImage(":/images/blank_tileset.png"); + editor->project->loadTilesetTiles(newSet, tilesImage); for(int i = 0; i < numMetaTiles; ++i) { int tilesPerMetatile = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8; Metatile *mt = new Metatile(); for(int j = 0; j < tilesPerMetatile; ++j){ - Tile *tile = new Tile(); + Tile tile(0, false, false, 0); //Create a checkerboard-style dummy tileset if(((i / 8) % 2) == 0) - tile->tile = ((i % 2) == 0) ? 1 : 2; + tile.tile = ((i % 2) == 0) ? 1 : 2; else - tile->tile = ((i % 2) == 1) ? 1 : 2; - tile->xflip = false; - tile->yflip = false; - tile->palette = 0; - mt->tiles->append(*tile); + tile.tile = ((i % 2) == 1) ? 1 : 2; + mt->tiles.append(tile); } mt->behavior = 0; mt->layerType = 0; mt->encounterType = 0; mt->terrainType = 0; - newSet->metatiles->append(mt); + newSet->metatiles.append(mt); } - newSet->palettes = new QList>(); - newSet->palettePreviews = new QList>(); - newSet->palettePaths = *new QList(); for(int i = 0; i < 16; ++i) { - QList *currentPal = new QList(); + QList currentPal; for(int i = 0; i < 16;++i) { - currentPal->append(qRgb(0,0,0)); + currentPal.append(qRgb(0,0,0)); } - newSet->palettes->append(*currentPal); - newSet->palettePreviews->append(*currentPal); + newSet->palettes.append(currentPal); + newSet->palettePreviews.append(currentPal); QString fileName = QString("%1.pal").arg(i, 2, 10, QLatin1Char('0')); newSet->palettePaths.append(fullDirectoryPath+"/palettes/" + fileName); } - (*newSet->palettes)[0][1] = qRgb(255,0,255); - (*newSet->palettePreviews)[0][1] = qRgb(255,0,255); + newSet->palettes[0][1] = qRgb(255,0,255); + newSet->palettePreviews[0][1] = qRgb(255,0,255); newSet->is_compressed = "TRUE"; newSet->padding = "0"; editor->project->saveTilesetTilesImage(newSet); diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index 6fa61340..2084973e 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -260,7 +260,7 @@ void MainWindow::refreshAfterPaletteChange(Tileset *tileset) { void MainWindow::setTilesetPalette(Tileset *tileset, int paletteIndex, QList> colors) { if (!this->editor || !this->editor->map || !this->editor->map->layout) return; - if (paletteIndex >= tileset->palettes->size()) + if (paletteIndex >= tileset->palettes.size()) return; if (colors.size() != 16) return; @@ -268,8 +268,8 @@ void MainWindow::setTilesetPalette(Tileset *tileset, int paletteIndex, QListpalettes)[paletteIndex][i] = qRgb(colors[i][0], colors[i][1], colors[i][2]); - (*tileset->palettePreviews)[paletteIndex][i] = qRgb(colors[i][0], colors[i][1], colors[i][2]); + tileset->palettes[paletteIndex][i] = qRgb(colors[i][0], colors[i][1], colors[i][2]); + tileset->palettePreviews[paletteIndex][i] = qRgb(colors[i][0], colors[i][1], colors[i][2]); } } @@ -305,22 +305,22 @@ void MainWindow::setSecondaryTilesetPalettes(QList>> palettes) this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary); } -QJSValue MainWindow::getTilesetPalette(QList> *palettes, int paletteIndex) { - if (paletteIndex >= palettes->size()) +QJSValue MainWindow::getTilesetPalette(const QList> &palettes, int paletteIndex) { + if (paletteIndex >= palettes.size()) return QJSValue(); QList> palette; - for (auto color : palettes->value(paletteIndex)) { + for (auto color : palettes.value(paletteIndex)) { palette.append(QList({qRed(color), qGreen(color), qBlue(color)})); } return Scripting::getEngine()->toScriptValue(palette); } -QJSValue MainWindow::getTilesetPalettes(QList> *palettes) { +QJSValue MainWindow::getTilesetPalettes(const QList> &palettes) { QList>> outPalettes; - for (int i = 0; i < palettes->size(); i++) { + for (int i = 0; i < palettes.size(); i++) { QList> colors; - for (auto color : palettes->value(i)) { + for (auto color : palettes.value(i)) { colors.append(QList({qRed(color), qGreen(color), qBlue(color)})); } outPalettes.append(colors); @@ -363,7 +363,7 @@ void MainWindow::refreshAfterPalettePreviewChange() { void MainWindow::setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QList> colors) { if (!this->editor || !this->editor->map || !this->editor->map->layout) return; - if (paletteIndex >= tileset->palettePreviews->size()) + if (paletteIndex >= tileset->palettePreviews.size()) return; if (colors.size() != 16) return; @@ -371,8 +371,7 @@ void MainWindow::setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QL for (int i = 0; i < 16; i++) { if (colors[i].size() != 3) continue; - auto palettes = tileset->palettePreviews; - (*palettes)[paletteIndex][i] = qRgb(colors[i][0], colors[i][1], colors[i][2]); + tileset->palettePreviews[paletteIndex][i] = qRgb(colors[i][0], colors[i][1], colors[i][2]); } } diff --git a/src/project.cpp b/src/project.cpp index 0eb61aba..0a7d2dea 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -955,16 +955,16 @@ void Project::saveTilesetMetatileLabels(Tileset *primaryTileset, Tileset *second } // Add the new labels. - for (int i = 0; i < primaryTileset->metatiles->size(); i++) { - Metatile *metatile = primaryTileset->metatiles->at(i); + for (int i = 0; i < primaryTileset->metatiles.size(); i++) { + Metatile *metatile = primaryTileset->metatiles.at(i); if (metatile->label.size() != 0) { QString defineName = QString("%1%2").arg(primaryPrefix, metatile->label); defines.insert(defineName, i); definesFileModified = true; } } - for (int i = 0; i < secondaryTileset->metatiles->size(); i++) { - Metatile *metatile = secondaryTileset->metatiles->at(i); + for (int i = 0; i < secondaryTileset->metatiles.size(); i++) { + Metatile *metatile = secondaryTileset->metatiles.at(i); if (metatile->label.size() != 0) { QString defineName = QString("%1%2").arg(secondaryPrefix, metatile->label); defines.insert(defineName, i + Project::num_tiles_primary); @@ -1021,7 +1021,7 @@ void Project::saveTilesetMetatileAttributes(Tileset *tileset) { QByteArray data; if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { - for (Metatile *metatile : *tileset->metatiles) { + for (Metatile *metatile : tileset->metatiles) { data.append(static_cast(metatile->behavior)); data.append(static_cast(metatile->behavior >> 8) | static_cast(metatile->terrainType << 1)); @@ -1030,7 +1030,7 @@ void Project::saveTilesetMetatileAttributes(Tileset *tileset) { static_cast(metatile->layerType << 5)); } } else { - for (Metatile *metatile : *tileset->metatiles) { + for (Metatile *metatile : tileset->metatiles) { data.append(static_cast(metatile->behavior)); data.append(static_cast((metatile->layerType << 4) & 0xF0)); } @@ -1045,10 +1045,10 @@ void Project::saveTilesetMetatiles(Tileset *tileset) { QFile metatiles_file(tileset->metatiles_path); if (metatiles_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { QByteArray data; - for (Metatile *metatile : *tileset->metatiles) { + for (Metatile *metatile : tileset->metatiles) { int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8; for (int i = 0; i < numTiles; i++) { - Tile tile = metatile->tiles->at(i); + Tile tile = metatile->tiles.at(i); uint16_t value = static_cast((tile.tile & 0x3ff) | ((tile.xflip & 1) << 10) | ((tile.yflip & 1) << 11) @@ -1059,7 +1059,7 @@ void Project::saveTilesetMetatiles(Tileset *tileset) { } metatiles_file.write(data); } else { - tileset->metatiles = new QList; + tileset->metatiles.clear(); logError(QString("Could not open tileset metatiles file '%1'").arg(tileset->metatiles_path)); } } @@ -1072,7 +1072,7 @@ void Project::saveTilesetPalettes(Tileset *tileset) { PaletteUtil paletteParser; for (int i = 0; i < Project::getNumPalettesTotal(); i++) { QString filepath = tileset->palettePaths.at(i); - paletteParser.writeJASC(filepath, tileset->palettes->at(i).toVector(), 0, 16); + paletteParser.writeJASC(filepath, tileset->palettes.at(i).toVector(), 0, 16); } } @@ -1504,8 +1504,8 @@ void Project::loadTilesetAssets(Tileset* tileset) { this->loadTilesetMetatileLabels(tileset); // palettes - QList> *palettes = new QList>; - QList> *palettePreviews = new QList>; + QList> palettes; + QList> palettePreviews; for (int i = 0; i < tileset->palettePaths.length(); i++) { QList palette; QString path = tileset->palettePaths.value(i); @@ -1539,21 +1539,21 @@ void Project::loadTilesetAssets(Tileset* tileset) { logError(QString("Could not open tileset palette path '%1'").arg(path)); } - palettes->append(palette); - palettePreviews->append(palette); + palettes.append(palette); + palettePreviews.append(palette); } tileset->palettes = palettes; tileset->palettePreviews = palettePreviews; } void Project::loadTilesetTiles(Tileset *tileset, QImage image) { - QList *tiles = new QList; + QList tiles; int w = 8; int h = 8; for (int y = 0; y < image.height(); y += h) for (int x = 0; x < image.width(); x += w) { QImage tile = image.copy(x, y, w, h); - tiles->append(tile); + tiles.append(tile); } tileset->tilesImage = image; tileset->tiles = tiles; @@ -1566,7 +1566,7 @@ void Project::loadTilesetMetatiles(Tileset* tileset) { int metatile_data_length = projectConfig.getTripleLayerMetatilesEnabled() ? 24 : 16; int num_metatiles = data.length() / metatile_data_length; int num_layers = projectConfig.getTripleLayerMetatilesEnabled() ? 3 : 2; - QList *metatiles = new QList; + QList metatiles; for (int i = 0; i < num_metatiles; i++) { Metatile *metatile = new Metatile; int index = i * (2 * 4 * num_layers); @@ -1578,20 +1578,20 @@ void Project::loadTilesetMetatiles(Tileset* tileset) { tile.xflip = (word >> 10) & 1; tile.yflip = (word >> 11) & 1; tile.palette = (word >> 12) & 0xf; - metatile->tiles->append(tile); + metatile->tiles.append(tile); } - metatiles->append(metatile); + metatiles.append(metatile); } tileset->metatiles = metatiles; } else { - tileset->metatiles = new QList; + tileset->metatiles.clear(); logError(QString("Could not open tileset metatiles file '%1'").arg(tileset->metatiles_path)); } QFile attrs_file(tileset->metatile_attrs_path); if (attrs_file.open(QIODevice::ReadOnly)) { QByteArray data = attrs_file.readAll(); - int num_metatiles = tileset->metatiles->count(); + int num_metatiles = tileset->metatiles.count(); if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { int num_metatileAttrs = data.length() / 4; @@ -1606,10 +1606,10 @@ void Project::loadTilesetMetatiles(Tileset* tileset) { (static_cast(data.at(i * 4 + 2)) << 16) | (static_cast(data.at(i * 4 + 1)) << 8) | (static_cast(data.at(i * 4 + 0))); - tileset->metatiles->at(i)->behavior = value & 0x1FF; - tileset->metatiles->at(i)->terrainType = (value & 0x3E00) >> 9; - tileset->metatiles->at(i)->encounterType = (value & 0x7000000) >> 24; - tileset->metatiles->at(i)->layerType = (value & 0x60000000) >> 29; + tileset->metatiles.at(i)->behavior = value & 0x1FF; + tileset->metatiles.at(i)->terrainType = (value & 0x3E00) >> 9; + tileset->metatiles.at(i)->encounterType = (value & 0x7000000) >> 24; + tileset->metatiles.at(i)->layerType = (value & 0x60000000) >> 29; if (value & ~(0x67003FFF)) unusedAttribute = true; } @@ -1624,10 +1624,10 @@ void Project::loadTilesetMetatiles(Tileset* tileset) { } for (int i = 0; i < num_metatileAttrs; i++) { int value = (static_cast(data.at(i * 2 + 1)) << 8) | static_cast(data.at(i * 2)); - tileset->metatiles->at(i)->behavior = value & 0xFF; - tileset->metatiles->at(i)->layerType = (value & 0xF000) >> 12; - tileset->metatiles->at(i)->encounterType = 0; - tileset->metatiles->at(i)->terrainType = 0; + tileset->metatiles.at(i)->behavior = value & 0xFF; + tileset->metatiles.at(i)->layerType = (value & 0xF000) >> 12; + tileset->metatiles.at(i)->encounterType = 0; + tileset->metatiles.at(i)->terrainType = 0; } } } else { @@ -1686,7 +1686,7 @@ Tileset* Project::getTileset(QString label, bool forceLoad) { } if (existingTileset && !forceLoad) { - return tilesetCache.value(label); + return existingTileset; } else { Tileset *tileset = loadTileset(label, existingTileset); return tileset; diff --git a/src/ui/imageproviders.cpp b/src/ui/imageproviders.cpp index a9d7cf29..44a7e4f2 100644 --- a/src/ui/imageproviders.cpp +++ b/src/ui/imageproviders.cpp @@ -26,7 +26,7 @@ QImage getMetatileImage( metatile_image.fill(Qt::black); Metatile* metatile = Tileset::getMetatile(tile, primaryTileset, secondaryTileset); - if (!metatile || !metatile->tiles) { + if (!metatile) { metatile_image.fill(Qt::magenta); return metatile_image; } @@ -46,7 +46,7 @@ QImage getMetatileImage( for (int x = 0; x < 2; x++) { int l = layerOrder.size() >= numLayers ? layerOrder[layer] : layer; int bottomLayer = layerOrder.size() >= numLayers ? layerOrder[0] : 0; - Tile tile_ = metatile->tiles->value((y * 2) + x + (l * 4)); + Tile tile_ = metatile->tiles.value((y * 2) + x + (l * 4)); QImage tile_image = getTileImage(tile_.tile, primaryTileset, secondaryTileset); if (tile_image.isNull()) { // Some metatiles specify tiles that are outside the valid range. @@ -97,10 +97,10 @@ QImage getMetatileImage( QImage getTileImage(uint16_t tile, Tileset *primaryTileset, Tileset *secondaryTileset) { Tileset *tileset = Tileset::getBlockTileset(tile, primaryTileset, secondaryTileset); int local_index = Metatile::getBlockIndex(tile); - if (!tileset || !tileset->tiles) { + if (!tileset) { return QImage(); } - return tileset->tiles->value(local_index, QImage()); + return tileset->tiles.value(local_index, QImage()); } QImage getColoredTileImage(uint16_t tile, Tileset *primaryTileset, Tileset *secondaryTileset, QList palette) { diff --git a/src/ui/metatilelayersitem.cpp b/src/ui/metatilelayersitem.cpp index 9883c4d5..2f5f8b80 100644 --- a/src/ui/metatilelayersitem.cpp +++ b/src/ui/metatilelayersitem.cpp @@ -25,7 +25,7 @@ void MetatileLayersItem::draw() { QPainter painter(&pixmap); int numTiles = isTripleLayerMetatile ? 12 : 8; for (int i = 0; i < numTiles; i++) { - Tile tile = this->metatile->tiles->at(i); + Tile tile = this->metatile->tiles.at(i); QImage tileImage = getPalettedTileImage(tile.tile, this->primaryTileset, this->secondaryTileset, tile.palette, true) .mirrored(tile.xflip, tile.yflip) .scaled(16, 16); diff --git a/src/ui/metatileselector.cpp b/src/ui/metatileselector.cpp index c360da5f..80f05c59 100644 --- a/src/ui/metatileselector.cpp +++ b/src/ui/metatileselector.cpp @@ -12,13 +12,12 @@ QPoint MetatileSelector::getSelectionDimensions() { } void MetatileSelector::draw() { - if (!this->primaryTileset || !this->primaryTileset->metatiles - || !this->secondaryTileset || !this->secondaryTileset->metatiles) { + if (!this->primaryTileset || !this->secondaryTileset) { this->setPixmap(QPixmap()); } - int primaryLength = this->primaryTileset->metatiles->length(); - int length_ = primaryLength + this->secondaryTileset->metatiles->length(); + int primaryLength = this->primaryTileset->metatiles.length(); + int length_ = primaryLength + this->secondaryTileset->metatiles.length(); int height_ = length_ / this->numMetatilesWide; if (length_ % this->numMetatilesWide != 0) { height_++; @@ -69,7 +68,7 @@ void MetatileSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTi if (this->externalSelection) { this->select(0); } else { - this->select(Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles->length() - 1); + this->select(Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles.length() - 1); } } else if (this->externalSelection) { emit selectedMetatilesChanged(); @@ -181,10 +180,10 @@ bool MetatileSelector::selectionIsValid() { uint16_t MetatileSelector::getMetatileId(int x, int y) { int index = y * this->numMetatilesWide + x; - if (index < this->primaryTileset->metatiles->length()) { + if (index < this->primaryTileset->metatiles.length()) { return static_cast(index); } else { - return static_cast(Project::getNumMetatilesPrimary() + index - this->primaryTileset->metatiles->length()); + return static_cast(Project::getNumMetatilesPrimary() + index - this->primaryTileset->metatiles.length()); } } @@ -197,7 +196,7 @@ QPoint MetatileSelector::getMetatileIdCoords(uint16_t metatileId) { int index = metatileId < Project::getNumMetatilesPrimary() ? metatileId - : metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles->length(); + : metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles.length(); return QPoint(index % this->numMetatilesWide, index / this->numMetatilesWide); } diff --git a/src/ui/paletteeditor.cpp b/src/ui/paletteeditor.cpp index 0e1366e6..f376dc3b 100644 --- a/src/ui/paletteeditor.cpp +++ b/src/ui/paletteeditor.cpp @@ -151,9 +151,9 @@ void PaletteEditor::refreshColorSliders() { for (int i = 0; i < 16; i++) { QRgb color; if (paletteNum < Project::getNumPalettesPrimary()) { - color = this->primaryTileset->palettes->at(paletteNum).at(i); + color = this->primaryTileset->palettes.at(paletteNum).at(i); } else { - color = this->secondaryTileset->palettes->at(paletteNum).at(i); + color = this->secondaryTileset->palettes.at(paletteNum).at(i); } this->sliders[i][0]->setValue(qRed(color) / 8); @@ -204,8 +204,8 @@ void PaletteEditor::setColor(int colorIndex) { Tileset *tileset = paletteNum < Project::getNumPalettesPrimary() ? this->primaryTileset : this->secondaryTileset; - (*tileset->palettes)[paletteNum][colorIndex] = qRgb(red, green, blue); - (*tileset->palettePreviews)[paletteNum][colorIndex] = qRgb(red, green, blue); + tileset->palettes[paletteNum][colorIndex] = qRgb(red, green, blue); + tileset->palettePreviews[paletteNum][colorIndex] = qRgb(red, green, blue); this->refreshColor(colorIndex); this->commitEditHistory(paletteNum); emit this->changedPaletteColor(); @@ -255,11 +255,11 @@ void PaletteEditor::setColorsFromHistory(PaletteHistoryItem *history, int palett for (int i = 0; i < 16; i++) { if (paletteId < Project::getNumPalettesPrimary()) { - (*this->primaryTileset->palettes)[paletteId][i] = history->colors.at(i); - (*this->primaryTileset->palettePreviews)[paletteId][i] = history->colors.at(i); + this->primaryTileset->palettes[paletteId][i] = history->colors.at(i); + this->primaryTileset->palettePreviews[paletteId][i] = history->colors.at(i); } else { - (*this->secondaryTileset->palettes)[paletteId][i] = history->colors.at(i); - (*this->secondaryTileset->palettePreviews)[paletteId][i] = history->colors.at(i); + this->secondaryTileset->palettes[paletteId][i] = history->colors.at(i); + this->secondaryTileset->palettePreviews[paletteId][i] = history->colors.at(i); } } @@ -307,11 +307,11 @@ void PaletteEditor::on_actionImport_Palette_triggered() int paletteId = this->ui->spinBox_PaletteId->value(); for (int i = 0; i < 16; i++) { if (paletteId < Project::getNumPalettesPrimary()) { - (*this->primaryTileset->palettes)[paletteId][i] = palette.at(i); - (*this->primaryTileset->palettePreviews)[paletteId][i] = palette.at(i); + this->primaryTileset->palettes[paletteId][i] = palette.at(i); + this->primaryTileset->palettePreviews[paletteId][i] = palette.at(i); } else { - (*this->secondaryTileset->palettes)[paletteId][i] = palette.at(i); - (*this->secondaryTileset->palettePreviews)[paletteId][i] = palette.at(i); + this->secondaryTileset->palettes[paletteId][i] = palette.at(i); + this->secondaryTileset->palettePreviews[paletteId][i] = palette.at(i); } } diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 2729fd37..4fd61a83 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -81,8 +81,8 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel); if (this->primaryTileset) delete this->primaryTileset; if (this->secondaryTileset) delete this->secondaryTileset; - this->primaryTileset = primaryTileset->copy(); - this->secondaryTileset = secondaryTileset->copy(); + this->primaryTileset = new Tileset(*primaryTileset); + this->secondaryTileset = new Tileset(*secondaryTileset); if (paletteEditor) paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset); } @@ -262,7 +262,7 @@ void TilesetEditor::restoreWindowState() { } void TilesetEditor::initMetatileHistory() { - MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, this->metatile->copy()); + MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, new Metatile(*metatile)); metatileHistory.push(commit); } @@ -361,7 +361,7 @@ void TilesetEditor::onSelectedTilesChanged() { } void TilesetEditor::onMetatileLayerTileChanged(int x, int y) { - const QList tileCoords = QList{ + static const QList tileCoords = QList{ QPoint(0, 0), QPoint(1, 0), QPoint(0, 1), @@ -375,7 +375,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) { QPoint(4, 1), QPoint(5, 1), }; - Metatile *prevMetatile = this->metatile->copy(); + Metatile *prevMetatile = new Metatile(*this->metatile); QPoint dimensions = this->tileSelector->getSelectionDimensions(); QList tiles = this->tileSelector->getSelectedTiles(); int selectedTileIndex = 0; @@ -387,11 +387,11 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) { if (tileIndex < maxTileIndex && tileCoords.at(tileIndex).x() >= x && tileCoords.at(tileIndex).y() >= y){ - Tile *tile = &(*this->metatile->tiles)[tileIndex]; - tile->tile = tiles.at(selectedTileIndex).tile; - tile->xflip = tiles.at(selectedTileIndex).xflip; - tile->yflip = tiles.at(selectedTileIndex).yflip; - tile->palette = tiles.at(selectedTileIndex).palette; + Tile &tile = this->metatile->tiles[tileIndex]; + tile.tile = tiles.at(selectedTileIndex).tile; + tile.xflip = tiles.at(selectedTileIndex).xflip; + tile.yflip = tiles.at(selectedTileIndex).yflip; + tile.palette = tiles.at(selectedTileIndex).palette; } selectedTileIndex++; } @@ -401,7 +401,8 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) { this->metatileLayersItem->draw(); this->hasUnsavedChanges = true; - MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy()); + MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), + prevMetatile, new Metatile(*this->metatile)); metatileHistory.push(commit); } @@ -416,7 +417,7 @@ void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int for (int i = 0; i < width; i++) { int tileIndex = ((x + i) / 2 * 4) + ((y + j) * 2) + ((x + i) % 2); if (tileIndex < maxTileIndex) { - tiles.append(this->metatile->tiles->at(tileIndex)); + tiles.append(this->metatile->tiles.at(tileIndex)); tileIdxs.append(tileIndex); } } @@ -465,9 +466,10 @@ void TilesetEditor::on_checkBox_yFlip_stateChanged(int checked) void TilesetEditor::on_comboBox_metatileBehaviors_activated(const QString &metatileBehavior) { if (this->metatile) { - Metatile *prevMetatile = this->metatile->copy(); + Metatile *prevMetatile = new Metatile(*this->metatile); this->metatile->behavior = static_cast(project->metatileBehaviorMap[metatileBehavior]); - MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy()); + MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), + prevMetatile, new Metatile(*this->metatile)); metatileHistory.push(commit); this->hasUnsavedChanges = true; } @@ -482,9 +484,10 @@ void TilesetEditor::saveMetatileLabel() { // Only commit if the field has changed. if (this->metatile && this->metatile->label != this->ui->lineEdit_metatileLabel->text()) { - Metatile *prevMetatile = this->metatile->copy(); + Metatile *prevMetatile = new Metatile(*this->metatile); this->metatile->label = this->ui->lineEdit_metatileLabel->text(); - MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy()); + MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), + prevMetatile, new Metatile(*this->metatile)); metatileHistory.push(commit); this->hasUnsavedChanges = true; } @@ -493,9 +496,10 @@ void TilesetEditor::saveMetatileLabel() void TilesetEditor::on_comboBox_layerType_activated(int layerType) { if (this->metatile) { - Metatile *prevMetatile = this->metatile->copy(); + Metatile *prevMetatile = new Metatile(*this->metatile); this->metatile->layerType = static_cast(layerType); - MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy()); + MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), + prevMetatile, new Metatile(*this->metatile)); metatileHistory.push(commit); this->hasUnsavedChanges = true; } @@ -504,9 +508,10 @@ void TilesetEditor::on_comboBox_layerType_activated(int layerType) void TilesetEditor::on_comboBox_encounterType_activated(int encounterType) { if (this->metatile) { - Metatile *prevMetatile = this->metatile->copy(); + Metatile *prevMetatile = new Metatile(*this->metatile); this->metatile->encounterType = static_cast(encounterType); - MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy()); + MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), + prevMetatile, new Metatile(*this->metatile)); metatileHistory.push(commit); this->hasUnsavedChanges = true; } @@ -515,9 +520,10 @@ void TilesetEditor::on_comboBox_encounterType_activated(int encounterType) void TilesetEditor::on_comboBox_terrainType_activated(int terrainType) { if (this->metatile) { - Metatile *prevMetatile = this->metatile->copy(); + Metatile *prevMetatile = new Metatile(*this->metatile); this->metatile->terrainType = static_cast(terrainType); - MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), prevMetatile, this->metatile->copy()); + MetatileHistoryItem *commit = new MetatileHistoryItem(metatileSelector->getSelectedMetatile(), + prevMetatile, new Metatile(*this->metatile)); metatileHistory.push(commit); this->hasUnsavedChanges = true; } @@ -710,8 +716,8 @@ void TilesetEditor::on_actionChange_Metatiles_Count_triggered() secondarySpinBox->setMinimum(1); primarySpinBox->setMaximum(Project::getNumMetatilesPrimary()); secondarySpinBox->setMaximum(Project::getNumMetatilesTotal() - Project::getNumMetatilesPrimary()); - primarySpinBox->setValue(this->primaryTileset->metatiles->length()); - secondarySpinBox->setValue(this->secondaryTileset->metatiles->length()); + primarySpinBox->setValue(this->primaryTileset->metatiles.length()); + secondarySpinBox->setValue(this->secondaryTileset->metatiles.length()); form.addRow(new QLabel("Primary Tileset"), primarySpinBox); form.addRow(new QLabel("Secondary Tileset"), secondarySpinBox); @@ -724,45 +730,35 @@ void TilesetEditor::on_actionChange_Metatiles_Count_triggered() int numPrimaryMetatiles = primarySpinBox->value(); int numSecondaryMetatiles = secondarySpinBox->value(); int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8; - while (this->primaryTileset->metatiles->length() > numPrimaryMetatiles) { - Metatile *metatile = this->primaryTileset->metatiles->takeLast(); - delete metatile; + while (this->primaryTileset->metatiles.length() > numPrimaryMetatiles) { + delete this->primaryTileset->metatiles.takeLast(); } - while (this->primaryTileset->metatiles->length() < numPrimaryMetatiles) { - Tile tile; - tile.palette = 0; - tile.tile = 0; - tile.xflip = false; - tile.yflip = false; + while (this->primaryTileset->metatiles.length() < numPrimaryMetatiles) { + Tile tile(0, false, false, 0); Metatile *metatile = new Metatile; metatile->behavior = 0; metatile->layerType = 0; metatile->encounterType = 0; metatile->terrainType = 0; for (int i = 0; i < numTiles; i++) { - metatile->tiles->append(tile); + metatile->tiles.append(tile); } - this->primaryTileset->metatiles->append(metatile); + this->primaryTileset->metatiles.append(metatile); } - while (this->secondaryTileset->metatiles->length() > numSecondaryMetatiles) { - Metatile *metatile = this->secondaryTileset->metatiles->takeLast(); - delete metatile; + while (this->secondaryTileset->metatiles.length() > numSecondaryMetatiles) { + delete this->secondaryTileset->metatiles.takeLast(); } - while (this->secondaryTileset->metatiles->length() < numSecondaryMetatiles) { - Tile tile; - tile.palette = 0; - tile.tile = 0; - tile.xflip = 0; - tile.yflip = 0; + while (this->secondaryTileset->metatiles.length() < numSecondaryMetatiles) { + Tile tile(0, false, false, 0); Metatile *metatile = new Metatile; metatile->behavior = 0; metatile->layerType = 0; metatile->encounterType = 0; metatile->terrainType = 0; for (int i = 0; i < numTiles; i++) { - metatile->tiles->append(tile); + metatile->tiles.append(tile); } - this->secondaryTileset->metatiles->append(metatile); + this->secondaryTileset->metatiles.append(metatile); } this->metatileSelector->updateSelectedMetatile(); @@ -811,7 +807,7 @@ void TilesetEditor::on_actionUndo_triggered() Metatile *temp = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset); if (temp) { this->metatile = temp; - this->metatile->copyInPlace(prev); + *this->metatile = *prev; this->metatileSelector->select(commit->metatileId); this->metatileSelector->draw(); this->metatileLayersItem->draw(); @@ -828,8 +824,8 @@ void TilesetEditor::on_actionRedo_triggered() Metatile *temp = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset); if (temp) { - this->metatile = Tileset::getMetatile(commit->metatileId, this->primaryTileset, this->secondaryTileset); - this->metatile->copyInPlace(next); + this->metatile = temp; + *this->metatile = *next; this->metatileSelector->select(commit->metatileId); this->metatileSelector->draw(); this->metatileLayersItem->draw(); @@ -885,7 +881,7 @@ void TilesetEditor::importTilesetMetatiles(Tileset *tileset, bool primary) MetatileParser parser; bool error = false; - QList *metatiles = parser.parse(filepath, &error, primary); + QList metatiles = parser.parse(filepath, &error, primary); if (error) { QMessageBox msgBox(this); msgBox.setText("Failed to import metatiles from Advance Map 1.92 .bvd file."); @@ -900,13 +896,14 @@ void TilesetEditor::importTilesetMetatiles(Tileset *tileset, bool primary) // TODO: This is crude because it makes a history entry for every newly-imported metatile. // Revisit this when tiles and num metatiles are added to tileset editory history. int metatileIdBase = primary ? 0 : Project::getNumMetatilesPrimary(); - for (int i = 0; i < metatiles->length(); i++) { - if (i >= tileset->metatiles->length()) { + for (int i = 0; i < metatiles.length(); i++) { + if (i >= tileset->metatiles.length()) { break; } - Metatile *prevMetatile = tileset->metatiles->at(i)->copy(); - MetatileHistoryItem *commit = new MetatileHistoryItem(static_cast(metatileIdBase + i), prevMetatile, metatiles->at(i)->copy()); + Metatile *prevMetatile = new Metatile(*tileset->metatiles.at(i)); + MetatileHistoryItem *commit = new MetatileHistoryItem(static_cast(metatileIdBase + i), + prevMetatile, new Metatile(*metatiles.at(i))); metatileHistory.push(commit); } diff --git a/src/ui/tileseteditormetatileselector.cpp b/src/ui/tileseteditormetatileselector.cpp index dddfdbbd..c7df404b 100644 --- a/src/ui/tileseteditormetatileselector.cpp +++ b/src/ui/tileseteditormetatileselector.cpp @@ -4,13 +4,12 @@ #include void TilesetEditorMetatileSelector::draw() { - if (!this->primaryTileset || !this->primaryTileset->metatiles - || !this->secondaryTileset || !this->secondaryTileset->metatiles) { + if (!this->primaryTileset || !this->secondaryTileset) { this->setPixmap(QPixmap()); } - int primaryLength = this->primaryTileset->metatiles->length(); - int length_ = primaryLength + this->secondaryTileset->metatiles->length(); + int primaryLength = this->primaryTileset->metatiles.length(); + int length_ = primaryLength + this->secondaryTileset->metatiles.length(); int height_ = length_ / this->numMetatilesWide; if (length_ % this->numMetatilesWide != 0) { height_++; @@ -63,7 +62,7 @@ void TilesetEditorMetatileSelector::updateSelectedMetatile() { if (Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) this->selectedMetatile = metatileId; else - this->selectedMetatile = Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles->length() - 1; + this->selectedMetatile = Project::getNumMetatilesPrimary() + this->secondaryTileset->metatiles.length() - 1; emit selectedMetatileChanged(this->selectedMetatile); } @@ -73,10 +72,10 @@ uint16_t TilesetEditorMetatileSelector::getSelectedMetatile() { uint16_t TilesetEditorMetatileSelector::getMetatileId(int x, int y) { int index = y * this->numMetatilesWide + x; - if (index < this->primaryTileset->metatiles->length()) { + if (index < this->primaryTileset->metatiles.length()) { return static_cast(index); } else { - return static_cast(Project::getNumMetatilesPrimary() + index - this->primaryTileset->metatiles->length()); + return static_cast(Project::getNumMetatilesPrimary() + index - this->primaryTileset->metatiles.length()); } } @@ -119,10 +118,10 @@ QPoint TilesetEditorMetatileSelector::getMetatileIdCoords(uint16_t metatileId) { { // Invalid metatile id. return QPoint(0, 0); - } + } int index = metatileId < Project::getNumMetatilesPrimary() ? metatileId - : metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles->length(); + : metatileId - Project::getNumMetatilesPrimary() + this->primaryTileset->metatiles.length(); return QPoint(index % this->numMetatilesWide, index / this->numMetatilesWide); } diff --git a/src/ui/tileseteditortileselector.cpp b/src/ui/tileseteditortileselector.cpp index 1b68466a..54a2da0e 100644 --- a/src/ui/tileseteditortileselector.cpp +++ b/src/ui/tileseteditortileselector.cpp @@ -13,14 +13,13 @@ QPoint TilesetEditorTileSelector::getSelectionDimensions() { } void TilesetEditorTileSelector::draw() { - if (!this->primaryTileset || !this->primaryTileset->tiles - || !this->secondaryTileset || !this->secondaryTileset->tiles) { + if (!this->primaryTileset || !this->secondaryTileset) { this->setPixmap(QPixmap()); } int totalTiles = Project::getNumTilesTotal(); - int primaryLength = this->primaryTileset->tiles->length(); - int secondaryLength = this->secondaryTileset->tiles->length(); + int primaryLength = this->primaryTileset->tiles.length(); + int secondaryLength = this->secondaryTileset->tiles.length(); int height = totalTiles / this->numTilesWide; QList palette = Tileset::getPalette(this->paletteId, this->primaryTileset, this->secondaryTileset, true); QImage image(this->numTilesWide * 16, height * 16, QImage::Format_RGBA8888); @@ -218,12 +217,11 @@ QPoint TilesetEditorTileSelector::getTileCoordsOnWidget(uint16_t tile) { } QImage TilesetEditorTileSelector::buildPrimaryTilesIndexedImage() { - if (!this->primaryTileset || !this->primaryTileset->tiles - || !this->secondaryTileset || !this->secondaryTileset->tiles) { + if (!this->primaryTileset || !this->secondaryTileset) { return QImage(); } - int primaryLength = this->primaryTileset->tiles->length(); + int primaryLength = this->primaryTileset->tiles.length(); int height = qCeil(primaryLength / static_cast(this->numTilesWide)); QImage image(this->numTilesWide * 8, height * 8, QImage::Format_RGBA8888); @@ -254,12 +252,11 @@ QImage TilesetEditorTileSelector::buildPrimaryTilesIndexedImage() { } QImage TilesetEditorTileSelector::buildSecondaryTilesIndexedImage() { - if (!this->primaryTileset || !this->primaryTileset->tiles - || !this->secondaryTileset || !this->secondaryTileset->tiles) { + if (!this->primaryTileset || !this->secondaryTileset) { return QImage(); } - int secondaryLength = this->secondaryTileset->tiles->length(); + int secondaryLength = this->secondaryTileset->tiles.length(); int height = qCeil(secondaryLength / static_cast(this->numTilesWide)); QImage image(this->numTilesWide * 8, height * 8, QImage::Format_RGBA8888);