From 0944f9888c0054bc4eae7e8559d938f1212abe58 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 17 Dec 2021 13:45:48 -0500 Subject: [PATCH] Remove addTilesImage, add overloaded addTileImage, add transparency to addMetatileImage --- include/mainwindow.h | 4 ++-- src/mainwindow_scriptapi.cpp | 30 ++++++------------------------ 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index 0a53847b..8d456476 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -96,8 +96,8 @@ public: bool xflip = false, bool yflip = false, int paletteId = -1, bool setTransparency = false, int layer = 0, bool useCache = true); Q_INVOKABLE void addTileImage(int x, int y, int tileId, bool xflip, bool yflip, int paletteId, bool setTransparency = false, int layer = 0); - Q_INVOKABLE void addTilesImage(int x, int y, QJSValue tilesObj, int layer = 0); - Q_INVOKABLE void addMetatileImage(int x, int y, int metatileId, int layer = 0); + Q_INVOKABLE void addTileImage(int x, int y, QJSValue tileObj, bool setTransparency = false, int layer = 0); + Q_INVOKABLE void addMetatileImage(int x, int y, int metatileId, bool setTransparency = false, int layer = 0); void refreshAfterPaletteChange(Tileset *tileset); void setTilesetPalette(Tileset *tileset, int paletteIndex, QList> colors); Q_INVOKABLE void setPrimaryTilesetPalette(int paletteIndex, QList> colors); diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index fd5d3ab7..f0ccc0bc 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -407,32 +407,12 @@ void MainWindow::addTileImage(int x, int y, int tileId, bool xflip, bool yflip, this->ui->graphicsView_Map->scene()->update(); } -void MainWindow::addTilesImage(int x, int y, QJSValue tilesObj, int layer) { - if (!this->ui || !this->ui->graphicsView_Map || !this->editor || !this->editor->map || !this->editor->map->layout - || !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary) - return; - - // Create metatile from JS tiles array - Metatile metatile; - int numTiles = this->getNumTilesInMetatile(); - int numTileObjs = qMin(tilesObj.property("length").toInt(), numTiles); - int i = 0; - for (; i < numTileObjs; i++) - metatile.tiles.append(Scripting::toTile(tilesObj.property(i))); - for (; i < numTiles; i++) - metatile.tiles.append(Tile()); - - // Create image from metatile - QImage image = getMetatileImage(&metatile, - this->editor->map->layout->tileset_primary, - this->editor->map->layout->tileset_secondary, - this->editor->map->metatileLayerOrder, - this->editor->map->metatileLayerOpacity); - if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, image)) - this->ui->graphicsView_Map->scene()->update(); +void MainWindow::addTileImage(int x, int y, QJSValue tileObj, bool setTransparency, int layer) { + Tile tile = Scripting::toTile(tileObj); + this->addTileImage(x, y, tile.tileId, tile.xflip, tile.yflip, tile.palette, setTransparency, layer); } -void MainWindow::addMetatileImage(int x, int y, int metatileId, int layer) { +void MainWindow::addMetatileImage(int x, int y, int metatileId, bool setTransparency, int layer) { if (!this->ui || !this->ui->graphicsView_Map || !this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary || !this->editor->map->layout->tileset_secondary) return; @@ -441,6 +421,8 @@ void MainWindow::addMetatileImage(int x, int y, int metatileId, int layer) { this->editor->map->layout->tileset_secondary, this->editor->map->metatileLayerOrder, this->editor->map->metatileLayerOpacity); + if (setTransparency) + image.setColor(0, qRgba(0, 0, 0, 0)); if (this->ui->graphicsView_Map->getOverlay(layer)->addImage(x, y, image)) this->ui->graphicsView_Map->scene()->update(); }