Fix map resizing (broke from Blockdata refactoring)

This commit is contained in:
BigBahss 2021-02-14 18:14:04 -05:00 committed by huderlem
parent a3326a764b
commit 107ef528e2
3 changed files with 11 additions and 8 deletions

View file

@ -271,34 +271,38 @@ void Map::setNewDimensionsBlockdata(int newWidth, int newHeight) {
int oldWidth = getWidth();
int oldHeight = getHeight();
layout->blockdata.clear();
Blockdata newBlockdata;
for (int y = 0; y < newHeight; y++)
for (int x = 0; x < newWidth; x++) {
if (x < oldWidth && y < oldHeight) {
int index = y * oldWidth + x;
layout->blockdata.append(layout->blockdata.value(index));
newBlockdata.append(layout->blockdata.value(index));
} else {
layout->blockdata.append(0);
newBlockdata.append(0);
}
}
layout->blockdata = newBlockdata;
}
void Map::setNewBorderDimensionsBlockdata(int newWidth, int newHeight) {
int oldWidth = getBorderWidth();
int oldHeight = getBorderHeight();
layout->border.clear();
Blockdata newBlockdata;
for (int y = 0; y < newHeight; y++)
for (int x = 0; x < newWidth; x++) {
if (x < oldWidth && y < oldHeight) {
int index = y * oldWidth + x;
layout->border.append(layout->border.value(index));
newBlockdata.append(layout->border.value(index));
} else {
layout->border.append(0);
newBlockdata.append(0);
}
}
layout->border = newBlockdata;
}
void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {

View file

@ -2619,7 +2619,7 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) {
editor->map->setDimensions(newMapDimensions.width(), newMapDimensions.height());
editor->map->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height());
editor->map->editHistory.push(new ResizeMap(map,
editor->map->editHistory.push(new ResizeMap(map,
oldMapDimensions, newMapDimensions,
oldMetatiles, map->layout->blockdata,
oldBorderDimensions, newBorderDimensions,

View file

@ -1183,7 +1183,6 @@ bool Project::loadBlockdata(Map *map) {
QString path = QString("%1/%2").arg(root).arg(map->layout->blockdata_path);
map->layout->blockdata = readBlockdata(path);
map->layout->lastCommitMapBlocks.blocks.clear();
map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata;
map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight());