Add get/setMetatileBehaviorName

This commit is contained in:
GriffinR 2024-01-03 16:58:50 -05:00
parent d2a0d9299f
commit 28831a7ff0
4 changed files with 42 additions and 0 deletions

View file

@ -8,6 +8,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
## [Unreleased] ## [Unreleased]
### Added ### Added
- Add `getMetatileBehaviorName` and `setMetatileBehaviorName` to the API.
- Add `metatile_behaviors`, `num_primary_palettes`, and `num_secondary_palettes` to `constants` in the API. - Add `metatile_behaviors`, `num_primary_palettes`, and `num_secondary_palettes` to `constants` in the API.
### Changed ### Changed

View file

@ -1069,6 +1069,26 @@ All tileset functions are callable via the global ``map`` object.
:param behavior: the behavior :param behavior: the behavior
:type behavior: number :type behavior: number
.. js:function:: map.getMetatileBehaviorName(metatileId)
Gets the behavior name for the specified metatile. Returns an empty string if the metatile's behavior value has no name.
:param metatileId: id of target metatile
:type metatileId: number
:returns: the behavior name
:rtype: string
.. js:function:: map.setMetatileBehaviorName(metatileId, behavior)
Sets the behavior name for the specified metatile. Does nothing if there is no metatile behavior define with the specified name.
**Warning:** This function writes directly to the tileset. There is no undo for this.
:param metatileId: id of target metatile
:type metatileId: number
:param behavior: the behavior name
:type behavior: string
.. js:function:: map.getMetatileAttributes(metatileId) .. js:function:: map.getMetatileAttributes(metatileId)
Gets the raw attributes value for the specified metatile. Gets the raw attributes value for the specified metatile.

View file

@ -123,6 +123,8 @@ public:
Q_INVOKABLE void setMetatileTerrainType(int metatileId, int terrainType); Q_INVOKABLE void setMetatileTerrainType(int metatileId, int terrainType);
Q_INVOKABLE int getMetatileBehavior(int metatileId); Q_INVOKABLE int getMetatileBehavior(int metatileId);
Q_INVOKABLE void setMetatileBehavior(int metatileId, int behavior); Q_INVOKABLE void setMetatileBehavior(int metatileId, int behavior);
Q_INVOKABLE QString getMetatileBehaviorName(int metatileId);
Q_INVOKABLE void setMetatileBehaviorName(int metatileId, QString behavior);
Q_INVOKABLE int getMetatileAttributes(int metatileId); Q_INVOKABLE int getMetatileAttributes(int metatileId);
Q_INVOKABLE void setMetatileAttributes(int metatileId, int attributes); Q_INVOKABLE void setMetatileAttributes(int metatileId, int attributes);
Q_INVOKABLE QJSValue getMetatileTile(int metatileId, int tileIndex); Q_INVOKABLE QJSValue getMetatileTile(int metatileId, int tileIndex);

View file

@ -687,6 +687,25 @@ void MainWindow::setMetatileBehavior(int metatileId, int behavior) {
this->saveMetatileAttributesByMetatileId(metatileId); this->saveMetatileAttributesByMetatileId(metatileId);
} }
QString MainWindow::getMetatileBehaviorName(int metatileId) {
Metatile * metatile = this->getMetatile(metatileId);
if (!metatile || !this->editor->project)
return QString();
return this->editor->project->metatileBehaviorMapInverse.value(metatile->behavior(), QString());
}
void MainWindow::setMetatileBehaviorName(int metatileId, QString behavior) {
Metatile * metatile = this->getMetatile(metatileId);
if (!metatile || !this->editor->project)
return;
if (!this->editor->project->metatileBehaviorMap.contains(behavior)) {
logError(QString("Unknown metatile behavior '%1'").arg(behavior));
return;
}
metatile->setBehavior(this->editor->project->metatileBehaviorMap.value(behavior));
this->saveMetatileAttributesByMetatileId(metatileId);
}
int MainWindow::getMetatileAttributes(int metatileId) { int MainWindow::getMetatileAttributes(int metatileId) {
Metatile * metatile = this->getMetatile(metatileId); Metatile * metatile = this->getMetatile(metatileId);
if (!metatile) if (!metatile)