diff --git a/docsrc/manual/scripting-capabilities.rst b/docsrc/manual/scripting-capabilities.rst index 215f4f53..b8c5742a 100644 --- a/docsrc/manual/scripting-capabilities.rst +++ b/docsrc/manual/scripting-capabilities.rst @@ -640,12 +640,13 @@ All tileset functions are callable via the global ``map`` object. :param number paletteIndex: the palette index :returns array: array of colors. Each color is a 3-element RGB array -.. js:function:: map.setPrimaryTilesetPalettePreview(paletteIndex, colors) +.. js:function:: map.setPrimaryTilesetPalettePreview(paletteIndex, colors, forceRedraw = true) Sets a palette in the primary tileset of the currently-opened map. This will NOT affect the true underlying colors--it only displays these colors in the map-editing area of Porymap. :param number paletteIndex: the palette index :param array colors: array of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palette. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getPrimaryTilesetPalettesPreview() @@ -653,11 +654,12 @@ All tileset functions are callable via the global ``map`` object. :returns array: array of arrays of colors. Each color is a 3-element RGB array -.. js:function:: map.setPrimaryTilesetPalettesPreview(palettes) +.. js:function:: map.setPrimaryTilesetPalettesPreview(palettes, forceRedraw = true) Sets all of the palettes in the primary tileset of the currently-opened map. This will NOT affect the true underlying colors--it only displays these colors in the map-editing area of Porymap. :param array palettes: array of arrays of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palettes. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getSecondaryTilesetPalettePreview(paletteIndex) @@ -666,12 +668,13 @@ All tileset functions are callable via the global ``map`` object. :param number paletteIndex: the palette index :returns array: array of colors. Each color is a 3-element RGB array -.. js:function:: map.setSecondaryTilesetPalettePreview(paletteIndex, colors) +.. js:function:: map.setSecondaryTilesetPalettePreview(paletteIndex, colors, forceRedraw = true) Sets a palette in the secondary tileset of the currently-opened map. This will NOT affect the true underlying colors--it only displays these colors in the map-editing area of Porymap. :param number paletteIndex: the palette index :param array colors: array of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palette. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getSecondaryTilesetPalettesPreview() @@ -679,11 +682,12 @@ All tileset functions are callable via the global ``map`` object. :returns array: array of arrays of colors. Each color is a 3-element RGB array -.. js:function:: map.setSecondaryTilesetPalettesPreview(palettes) +.. js:function:: map.setSecondaryTilesetPalettesPreview(palettes, forceRedraw = true) Sets all of the palettes in the secondary tileset of the currently-opened map. This will NOT affect the true underlying colors--it only displays these colors in the map-editing area of Porymap. :param array palettes: array of arrays of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palettes. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getPrimaryTilesetPalette(paletteIndex) @@ -692,12 +696,13 @@ All tileset functions are callable via the global ``map`` object. :param number paletteIndex: the palette index :returns array: array of colors. Each color is a 3-element RGB array -.. js:function:: map.setPrimaryTilesetPalette(paletteIndex, colors) +.. js:function:: map.setPrimaryTilesetPalette(paletteIndex, colors, forceRedraw = true) Sets a palette in the primary tileset of the currently-opened map. This will permanently affect the palette and save the palette to disk. :param number paletteIndex: the palette index :param array colors: array of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palette. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getPrimaryTilesetPalettes() @@ -705,11 +710,12 @@ All tileset functions are callable via the global ``map`` object. :returns array: array of arrays of colors. Each color is a 3-element RGB array -.. js:function:: map.setPrimaryTilesetPalettes(palettes) +.. js:function:: map.setPrimaryTilesetPalettes(palettes, forceRedraw = true) Sets all of the palettes in the primary tileset of the currently-opened map. This will permanently affect the palettes and save the palettes to disk. :param array palettes: array of arrays of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palettes. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getSecondaryTilesetPalette(paletteIndex) @@ -718,12 +724,13 @@ All tileset functions are callable via the global ``map`` object. :param number paletteIndex: the palette index :returns array: array of colors. Each color is a 3-element RGB array -.. js:function:: map.setSecondaryTilesetPalette(paletteIndex, colors) +.. js:function:: map.setSecondaryTilesetPalette(paletteIndex, colors, forceRedraw = true) Sets a palette in the secondary tileset of the currently-opened map. This will permanently affect the palette and save the palette to disk. :param number paletteIndex: the palette index :param array colors: array of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palette. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getSecondaryTilesetPalettes() @@ -731,11 +738,12 @@ All tileset functions are callable via the global ``map`` object. :returns array: array of arrays of colors. Each color is a 3-element RGB array -.. js:function:: map.setSecondaryTilesetPalettes(palettes) +.. js:function:: map.setSecondaryTilesetPalettes(palettes, forceRedraw = true) Sets all of the palettes in the secondary tileset of the currently-opened map. This will permanently affect the palettes and save the palettes to disk. :param array palettes: array of arrays of colors. Each color is a 3-element RGB array + :param boolean forceRedraw: Redraw the elements with the updated palettes. Defaults to ``true``. Redrawing the elements that use palettes is expensive, so it can be useful to batch together many calls to palette functions and only set ``redraw`` to ``true`` on the final call. .. js:function:: map.getMetatileLayerOrder() diff --git a/include/mainwindow.h b/include/mainwindow.h index 89319d0e..d8fa4201 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -78,10 +78,10 @@ public: Q_INVOKABLE void setBorderHeight(int height); void refreshAfterPaletteChange(Tileset *tileset); void setTilesetPalette(Tileset *tileset, int paletteIndex, QList> colors); - Q_INVOKABLE void setPrimaryTilesetPalette(int paletteIndex, QList> colors); - Q_INVOKABLE void setPrimaryTilesetPalettes(QList>> palettes); - Q_INVOKABLE void setSecondaryTilesetPalette(int paletteIndex, QList> colors); - Q_INVOKABLE void setSecondaryTilesetPalettes(QList>> palettes); + Q_INVOKABLE void setPrimaryTilesetPalette(int paletteIndex, QList> colors, bool forceRedraw = true); + Q_INVOKABLE void setPrimaryTilesetPalettes(QList>> palettes, bool forceRedraw = true); + Q_INVOKABLE void setSecondaryTilesetPalette(int paletteIndex, QList> colors, bool forceRedraw = true); + Q_INVOKABLE void setSecondaryTilesetPalettes(QList>> palettes, bool forceRedraw = true); QJSValue getTilesetPalette(const QList> &palettes, int paletteIndex); QJSValue getTilesetPalettes(const QList> &palettes); Q_INVOKABLE QJSValue getPrimaryTilesetPalette(int paletteIndex); @@ -90,10 +90,10 @@ public: Q_INVOKABLE QJSValue getSecondaryTilesetPalettes(); void refreshAfterPalettePreviewChange(); void setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QList> colors); - Q_INVOKABLE void setPrimaryTilesetPalettePreview(int paletteIndex, QList> colors); - Q_INVOKABLE void setPrimaryTilesetPalettesPreview(QList>> palettes); - Q_INVOKABLE void setSecondaryTilesetPalettePreview(int paletteIndex, QList> colors); - Q_INVOKABLE void setSecondaryTilesetPalettesPreview(QList>> palettes); + Q_INVOKABLE void setPrimaryTilesetPalettePreview(int paletteIndex, QList> colors, bool forceRedraw = true); + Q_INVOKABLE void setPrimaryTilesetPalettesPreview(QList>> palettes, bool forceRedraw = true); + Q_INVOKABLE void setSecondaryTilesetPalettePreview(int paletteIndex, QList> colors, bool forceRedraw = true); + Q_INVOKABLE void setSecondaryTilesetPalettesPreview(QList>> palettes, bool forceRedraw = true); Q_INVOKABLE QJSValue getPrimaryTilesetPalettePreview(int paletteIndex); Q_INVOKABLE QJSValue getPrimaryTilesetPalettesPreview(); Q_INVOKABLE QJSValue getSecondaryTilesetPalettePreview(int paletteIndex); diff --git a/src/scriptapi/apimap.cpp b/src/scriptapi/apimap.cpp index 419ef1c6..9451d1ee 100644 --- a/src/scriptapi/apimap.cpp +++ b/src/scriptapi/apimap.cpp @@ -347,36 +347,44 @@ void MainWindow::setTilesetPalette(Tileset *tileset, int paletteIndex, QList> colors) { +void MainWindow::setPrimaryTilesetPalette(int paletteIndex, QList> colors, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary) return; this->setTilesetPalette(this->editor->map->layout->tileset_primary, paletteIndex, colors); - this->refreshAfterPaletteChange(this->editor->map->layout->tileset_primary); + if (forceRedraw) { + this->refreshAfterPaletteChange(this->editor->map->layout->tileset_primary); + } } -void MainWindow::setPrimaryTilesetPalettes(QList>> palettes) { +void MainWindow::setPrimaryTilesetPalettes(QList>> palettes, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary) return; for (int i = 0; i < palettes.size(); i++) { this->setTilesetPalette(this->editor->map->layout->tileset_primary, i, palettes[i]); } - this->refreshAfterPaletteChange(this->editor->map->layout->tileset_primary); + if (forceRedraw) { + this->refreshAfterPaletteChange(this->editor->map->layout->tileset_primary); + } } -void MainWindow::setSecondaryTilesetPalette(int paletteIndex, QList> colors) { +void MainWindow::setSecondaryTilesetPalette(int paletteIndex, QList> colors, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary) return; this->setTilesetPalette(this->editor->map->layout->tileset_secondary, paletteIndex, colors); - this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary); + if (forceRedraw) { + this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary); + } } -void MainWindow::setSecondaryTilesetPalettes(QList>> palettes) { +void MainWindow::setSecondaryTilesetPalettes(QList>> palettes, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary) return; for (int i = 0; i < palettes.size(); i++) { this->setTilesetPalette(this->editor->map->layout->tileset_secondary, i, palettes[i]); } - this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary); + if (forceRedraw) { + this->refreshAfterPaletteChange(this->editor->map->layout->tileset_secondary); + } } QJSValue MainWindow::getTilesetPalette(const QList> &palettes, int paletteIndex) { @@ -449,36 +457,44 @@ void MainWindow::setTilesetPalettePreview(Tileset *tileset, int paletteIndex, QL } } -void MainWindow::setPrimaryTilesetPalettePreview(int paletteIndex, QList> colors) { +void MainWindow::setPrimaryTilesetPalettePreview(int paletteIndex, QList> colors, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary) return; this->setTilesetPalettePreview(this->editor->map->layout->tileset_primary, paletteIndex, colors); - this->refreshAfterPalettePreviewChange(); + if (forceRedraw) { + this->refreshAfterPalettePreviewChange(); + } } -void MainWindow::setPrimaryTilesetPalettesPreview(QList>> palettes) { +void MainWindow::setPrimaryTilesetPalettesPreview(QList>> palettes, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary) return; for (int i = 0; i < palettes.size(); i++) { this->setTilesetPalettePreview(this->editor->map->layout->tileset_primary, i, palettes[i]); } - this->refreshAfterPalettePreviewChange(); + if (forceRedraw) { + this->refreshAfterPalettePreviewChange(); + } } -void MainWindow::setSecondaryTilesetPalettePreview(int paletteIndex, QList> colors) { +void MainWindow::setSecondaryTilesetPalettePreview(int paletteIndex, QList> colors, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary) return; this->setTilesetPalettePreview(this->editor->map->layout->tileset_secondary, paletteIndex, colors); - this->refreshAfterPalettePreviewChange(); + if (forceRedraw) { + this->refreshAfterPalettePreviewChange(); + } } -void MainWindow::setSecondaryTilesetPalettesPreview(QList>> palettes) { +void MainWindow::setSecondaryTilesetPalettesPreview(QList>> palettes, bool forceRedraw) { if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary) return; for (int i = 0; i < palettes.size(); i++) { this->setTilesetPalettePreview(this->editor->map->layout->tileset_secondary, i, palettes[i]); } - this->refreshAfterPalettePreviewChange(); + if (forceRedraw) { + this->refreshAfterPalettePreviewChange(); + } } QJSValue MainWindow::getPrimaryTilesetPalettePreview(int paletteIndex) {