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

View file

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