Add get/setMetatileBehaviorName
This commit is contained in:
parent
d2a0d9299f
commit
28831a7ff0
4 changed files with 42 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -123,6 +123,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 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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue