Add getNumTilesetMetatiles, getNumTilesInMetatile, and isPrimary/SecondaryTileset to API

This commit is contained in:
GriffinR 2021-11-30 19:16:25 -05:00 committed by huderlem
parent 6bae415fc1
commit 83a7ccac8b
2 changed files with 34 additions and 1 deletions

View file

@ -97,6 +97,10 @@ public:
Q_INVOKABLE QJSValue getPrimaryTilesetPalettesPreview();
Q_INVOKABLE QJSValue getSecondaryTilesetPalettePreview(int paletteIndex);
Q_INVOKABLE QJSValue getSecondaryTilesetPalettesPreview();
Q_INVOKABLE int getNumPrimaryTilesetMetatiles();
Q_INVOKABLE int getNumSecondaryTilesetMetatiles();
Q_INVOKABLE bool isPrimaryTileset(QString tilesetName);
Q_INVOKABLE bool isSecondaryTileset(QString tilesetName);
Q_INVOKABLE QString getPrimaryTileset();
Q_INVOKABLE QString getSecondaryTileset();
Q_INVOKABLE void setPrimaryTileset(QString tileset);
@ -128,6 +132,7 @@ 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 getNumTilesInMetatile();
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);

View file

@ -470,6 +470,30 @@ QJSValue MainWindow::getSecondaryTilesetPalettesPreview() {
return this->getTilesetPalettes(this->editor->map->layout->tileset_secondary->palettePreviews);
}
int MainWindow::getNumPrimaryTilesetMetatiles() {
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
return 0;
return this->editor->map->layout->tileset_primary->metatiles.length();
}
int MainWindow::getNumSecondaryTilesetMetatiles() {
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_secondary)
return 0;
return this->editor->map->layout->tileset_secondary->metatiles.length();
}
bool MainWindow::isPrimaryTileset(QString tilesetName) {
if (!this->editor || !this->editor->project)
return false;
return this->editor->project->tilesetLabels["primary"].contains(tilesetName);
}
bool MainWindow::isSecondaryTileset(QString tilesetName) {
if (!this->editor || !this->editor->project)
return false;
return this->editor->project->tilesetLabels["secondary"].contains(tilesetName);
}
QString MainWindow::getPrimaryTileset() {
if (!this->editor || !this->editor->map || !this->editor->map->layout || !this->editor->map->layout->tileset_primary)
return QString();
@ -697,8 +721,12 @@ void MainWindow::setMetatileBehavior(int metatileId, int behavior) {
this->saveMetatileAttributesByMetatileId(metatileId);
}
int MainWindow::getNumTilesInMetatile() {
return projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
}
int MainWindow::calculateTileBounds(int * tileStart, int * tileEnd) {
int maxNumTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8;
int maxNumTiles = this->getNumTilesInMetatile();
if (*tileEnd >= maxNumTiles || *tileEnd < 0)
*tileEnd = maxNumTiles - 1;
if (*tileStart >= maxNumTiles || *tileStart < 0)