diff --git a/CHANGELOG.md b/CHANGELOG.md index feceffc3..1481ee53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,17 +12,17 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Added - Add Copy/Paste for metatiles in the Tileset Editor. -- Add new features to the scripting API, including the ability to set overlay opacity, get/set map header properties, read tile pixel data, and set blocks using a raw value. +- Add new features to the scripting API, including the ability to set overlay opacity, get/set map header properties, read tile pixel data, and set blocks or metatile attributes using a raw value. - Add button to copy the full metatile label to the clipboard in the Tileset Editor. - Add option to not open the most recent project on launch. - Add color picker to palette editor for taking colors from the screen. ### Changed +- Overhauled the region map editor, adding support for tilemaps, and significant customization. Also now supports pokefirered. - If an object event is inanimate, it will always render using its first frame. - Only log "Unknown custom script function" when a registered script function is not present in any script. - Unused metatile attribute bits that are set are preserved instead of being cleared. - The wild encounter editor is automatically disabled if the encounter JSON data cannot be read -- Overhauled the region map editor, adding support for tilemaps, and significant customization. Also now supports pokefirered. - Metatiles are always rendered accurately with 3 layers, and the unused layer is not assumed to be transparent. - `object_event_graphics_info.h` can now be parsed correctly if it uses structs with attributes. - Palette editor ui is updated a bit to allow hex and rgb value input. diff --git a/docsrc/manual/scripting-capabilities.rst b/docsrc/manual/scripting-capabilities.rst index 73950d4c..a18a6c5b 100644 --- a/docsrc/manual/scripting-capabilities.rst +++ b/docsrc/manual/scripting-capabilities.rst @@ -1054,6 +1054,22 @@ The following functions are related to tilesets and how they are rendered. The f :param number metatileId: id of target metatile :param number behavior: the behavior +.. js:function:: map.getMetatileAttributes(metatileId) + + Gets the raw attributes value for the specified metatile. + + :param number metatileId: id of target metatile + :returns number: the raw attributes value + +.. js:function:: map.setMetatileAttributes(metatileId, attributes) + + Sets the raw attributes value for the specified metatile. + + **Warning:** This function writes directly to the tileset. There is no undo for this. Porymap will not limit the value of existing attributes to their usual range. + + :param number metatileId: id of target metatile + :param number attributes: the raw attributes value + .. js:function:: map.getMetatileTile(metatileId, tileIndex) Gets the tile at the specified index of the metatile. diff --git a/include/mainwindow.h b/include/mainwindow.h index 19b8cbef..94c595cb 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -167,6 +167,8 @@ public: Q_INVOKABLE void setMetatileTerrainType(int metatileId, int terrainType); Q_INVOKABLE int getMetatileBehavior(int metatileId); Q_INVOKABLE void setMetatileBehavior(int metatileId, int behavior); + Q_INVOKABLE int getMetatileAttributes(int metatileId); + Q_INVOKABLE void setMetatileAttributes(int metatileId, int attributes); Q_INVOKABLE QJSValue getMetatileTile(int metatileId, int tileIndex); Q_INVOKABLE void setMetatileTile(int metatileId, int tileIndex, int tileId, bool xflip, bool yflip, int palette, bool forceRedraw = true); Q_INVOKABLE void setMetatileTile(int metatileId, int tileIndex, QJSValue tileObj, bool forceRedraw = true); diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index 784a0354..10ca897a 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -961,6 +961,22 @@ void MainWindow::setMetatileBehavior(int metatileId, int behavior) { this->saveMetatileAttributesByMetatileId(metatileId); } +int MainWindow::getMetatileAttributes(int metatileId) { + Metatile * metatile = this->getMetatile(metatileId); + if (!metatile) + return -1; + return metatile->getAttributes(projectConfig.getBaseGameVersion()); +} + +void MainWindow::setMetatileAttributes(int metatileId, int attributes) { + Metatile * metatile = this->getMetatile(metatileId); + uint32_t u_attributes = static_cast(attributes); + if (!metatile) + return; + metatile->setAttributes(u_attributes, projectConfig.getBaseGameVersion()); + this->saveMetatileAttributesByMetatileId(metatileId); +} + int MainWindow::calculateTileBounds(int * tileStart, int * tileEnd) { int maxNumTiles = this->getNumTilesInMetatile(); if (*tileEnd >= maxNumTiles || *tileEnd < 0)