Skip to content

Commit

Permalink
Add get/setMetatileBehaviorName
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Jan 3, 2024
1 parent d2a0d92 commit 28831a7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d

## [Unreleased]
### Added
- Add `getMetatileBehaviorName` and `setMetatileBehaviorName` to the API.
- Add `metatile_behaviors`, `num_primary_palettes`, and `num_secondary_palettes` to `constants` in the API.

### Changed
Expand Down
20 changes: 20 additions & 0 deletions docsrc/manual/scripting-capabilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,26 @@ All tileset functions are callable via the global ``map`` object.
:param behavior: the behavior
: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)

Gets the raw attributes value for the specified metatile.
Expand Down
2 changes: 2 additions & 0 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class MainWindow : public QMainWindow
Q_INVOKABLE void setMetatileTerrainType(int metatileId, int terrainType);
Q_INVOKABLE int getMetatileBehavior(int metatileId);
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 void setMetatileAttributes(int metatileId, int attributes);
Q_INVOKABLE QJSValue getMetatileTile(int metatileId, int tileIndex);
Expand Down
19 changes: 19 additions & 0 deletions src/scriptapi/apimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,25 @@ void MainWindow::setMetatileBehavior(int metatileId, int behavior) {
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) {
Metatile * metatile = this->getMetatile(metatileId);
if (!metatile)
Expand Down

0 comments on commit 28831a7

Please sign in to comment.