Add sanity checks to setMetatileLayerOrder
This commit is contained in:
parent
d86d388db8
commit
3a2d2ef3c2
2 changed files with 18 additions and 1 deletions
|
@ -794,6 +794,23 @@ QList<int> MainWindow::getMetatileLayerOrder() {
|
||||||
void MainWindow::setMetatileLayerOrder(QList<int> order) {
|
void MainWindow::setMetatileLayerOrder(QList<int> order) {
|
||||||
if (!this->editor || !this->editor->map)
|
if (!this->editor || !this->editor->map)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const int numLayers = 3;
|
||||||
|
int size = order.size();
|
||||||
|
if (size < numLayers) {
|
||||||
|
logError(QString("Metatile layer order has insufficient elements (%1), needs at least %2.").arg(size).arg(numLayers));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bool invalid = false;
|
||||||
|
for (int i = 0; i < numLayers; i++) {
|
||||||
|
int layer = order.at(i);
|
||||||
|
if (layer < 0 || layer >= numLayers) {
|
||||||
|
logError(QString("'%1' is not a valid metatile layer order value, must be in range 0-%2.").arg(layer).arg(numLayers - 1));
|
||||||
|
invalid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (invalid) return;
|
||||||
|
|
||||||
this->editor->map->metatileLayerOrder = order;
|
this->editor->map->metatileLayerOrder = order;
|
||||||
this->refreshAfterPalettePreviewChange();
|
this->refreshAfterPalettePreviewChange();
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ QImage getMetatileImage(
|
||||||
for (int layer = 0; layer < numLayers; layer++)
|
for (int layer = 0; layer < numLayers; layer++)
|
||||||
for (int y = 0; y < 2; y++)
|
for (int y = 0; y < 2; y++)
|
||||||
for (int x = 0; x < 2; x++) {
|
for (int x = 0; x < 2; x++) {
|
||||||
int l = layerOrder.size() >= numLayers ? (layerOrder[layer] % numLayers) : layer;
|
int l = layerOrder.size() >= numLayers ? layerOrder[layer] : layer;
|
||||||
int bottomLayer = layerOrder.size() >= numLayers ? layerOrder[0] : 0;
|
int bottomLayer = layerOrder.size() >= numLayers ? layerOrder[0] : 0;
|
||||||
|
|
||||||
// Get the tile to render next
|
// Get the tile to render next
|
||||||
|
|
Loading…
Reference in a new issue