Prevent some script edit feedback loops
This commit is contained in:
parent
8059b7dcae
commit
fbe5427c0b
4 changed files with 30 additions and 26 deletions
|
@ -85,10 +85,10 @@ public:
|
|||
void cacheCollision();
|
||||
bool getBlock(int x, int y, Block *out);
|
||||
void setBlock(int x, int y, Block block, bool enableScriptCallback = false);
|
||||
void setBlockdata(Blockdata blockdata);
|
||||
void setBlockdata(Blockdata blockdata, bool enableScriptCallback = false);
|
||||
uint16_t getBorderMetatileId(int x, int y);
|
||||
void setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback = false);
|
||||
void setBorderBlockData(Blockdata blockdata);
|
||||
void setBorderBlockData(Blockdata blockdata, bool enableScriptCallback = false);
|
||||
void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
||||
void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
||||
void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation);
|
||||
|
@ -98,8 +98,8 @@ public:
|
|||
void addEvent(Event*);
|
||||
QPixmap renderConnection(MapConnection, MapLayout *);
|
||||
QPixmap renderBorder(bool ignoreCache = false);
|
||||
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
|
||||
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
|
||||
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
||||
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
||||
void cacheBorder();
|
||||
bool hasUnsavedChanges();
|
||||
bool isWithinBounds(int x, int y);
|
||||
|
|
|
@ -47,7 +47,7 @@ void PaintMetatile::redo() {
|
|||
|
||||
if (!map) return;
|
||||
|
||||
map->setBlockdata(newMetatiles);
|
||||
map->setBlockdata(newMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -57,7 +57,7 @@ void PaintMetatile::redo() {
|
|||
void PaintMetatile::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setBlockdata(oldMetatiles);
|
||||
map->setBlockdata(oldMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -101,7 +101,7 @@ void PaintBorder::redo() {
|
|||
|
||||
if (!map) return;
|
||||
|
||||
map->setBorderBlockData(newBorder);
|
||||
map->setBorderBlockData(newBorder, true);
|
||||
|
||||
map->layout->lastCommitBlocks.border = map->layout->border;
|
||||
|
||||
|
@ -111,7 +111,7 @@ void PaintBorder::redo() {
|
|||
void PaintBorder::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setBorderBlockData(oldBorder);
|
||||
map->setBorderBlockData(oldBorder, true);
|
||||
|
||||
map->layout->lastCommitBlocks.border = map->layout->border;
|
||||
|
||||
|
@ -141,7 +141,7 @@ void ShiftMetatiles::redo() {
|
|||
|
||||
if (!map) return;
|
||||
|
||||
map->setBlockdata(newMetatiles);
|
||||
map->setBlockdata(newMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -151,7 +151,7 @@ void ShiftMetatiles::redo() {
|
|||
void ShiftMetatiles::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->setBlockdata(oldMetatiles);
|
||||
map->setBlockdata(oldMetatiles, true);
|
||||
|
||||
map->layout->lastCommitBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -212,10 +212,10 @@ void ResizeMap::redo() {
|
|||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = newMetatiles;
|
||||
map->setDimensions(newMapWidth, newMapHeight, false);
|
||||
map->setDimensions(newMapWidth, newMapHeight, false, true);
|
||||
|
||||
map->layout->border = newBorder;
|
||||
map->setBorderDimensions(newBorderWidth, newBorderHeight, false);
|
||||
map->setBorderDimensions(newBorderWidth, newBorderHeight, false, true);
|
||||
|
||||
map->layout->lastCommitBlocks.mapDimensions = QSize(map->getWidth(), map->getHeight());
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(map->getBorderWidth(), map->getBorderHeight());
|
||||
|
@ -227,10 +227,10 @@ void ResizeMap::undo() {
|
|||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = oldMetatiles;
|
||||
map->setDimensions(oldMapWidth, oldMapHeight, false);
|
||||
map->setDimensions(oldMapWidth, oldMapHeight, false, true);
|
||||
|
||||
map->layout->border = oldBorder;
|
||||
map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false);
|
||||
map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false, true);
|
||||
|
||||
map->layout->lastCommitBlocks.mapDimensions = QSize(map->getWidth(), map->getHeight());
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(map->getBorderWidth(), map->getBorderHeight());
|
||||
|
@ -538,7 +538,8 @@ void ScriptEditMap::redo() {
|
|||
map->layout->lastCommitBlocks.border = newBorder;
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight);
|
||||
|
||||
map->mapNeedsRedrawing();
|
||||
renderMapBlocks(map);
|
||||
map->borderItem->draw();
|
||||
}
|
||||
|
||||
void ScriptEditMap::undo() {
|
||||
|
@ -563,7 +564,8 @@ void ScriptEditMap::undo() {
|
|||
map->layout->lastCommitBlocks.border = oldBorder;
|
||||
map->layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight);
|
||||
|
||||
map->mapNeedsRedrawing();
|
||||
renderMapBlocks(map);
|
||||
map->borderItem->draw();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ void Map::setNewBorderDimensionsBlockdata(int newWidth, int newHeight) {
|
|||
layout->border = newBlockdata;
|
||||
}
|
||||
|
||||
void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
|
||||
void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool enableScriptCallback) {
|
||||
if (setNewBlockdata) {
|
||||
setNewDimensionsBlockdata(newWidth, newHeight);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
|
|||
layout->width = QString::number(newWidth);
|
||||
layout->height = QString::number(newHeight);
|
||||
|
||||
if (oldWidth != newWidth || oldHeight != newHeight) {
|
||||
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
|
||||
Scripting::cb_MapResized(oldWidth, oldHeight, newWidth, newHeight);
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
|
|||
emit mapDimensionsChanged(QSize(getWidth(), getHeight()));
|
||||
}
|
||||
|
||||
void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
|
||||
void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata, bool enableScriptCallback) {
|
||||
if (setNewBlockdata) {
|
||||
setNewBorderDimensionsBlockdata(newWidth, newHeight);
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata)
|
|||
layout->border_width = QString::number(newWidth);
|
||||
layout->border_height = QString::number(newHeight);
|
||||
|
||||
if (oldWidth != newWidth || oldHeight != newHeight) {
|
||||
if (enableScriptCallback && (oldWidth != newWidth || oldHeight != newHeight)) {
|
||||
Scripting::cb_BorderResized(oldWidth, oldHeight, newWidth, newHeight);
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ void Map::setBlock(int x, int y, Block block, bool enableScriptCallback) {
|
|||
}
|
||||
}
|
||||
|
||||
void Map::setBlockdata(Blockdata blockdata) {
|
||||
void Map::setBlockdata(Blockdata blockdata, bool enableScriptCallback) {
|
||||
int width = getWidth();
|
||||
int size = qMin(blockdata.size(), layout->blockdata.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -369,7 +369,8 @@ void Map::setBlockdata(Blockdata blockdata) {
|
|||
Block newBlock = blockdata.at(i);
|
||||
if (prevBlock != newBlock) {
|
||||
layout->blockdata.replace(i, newBlock);
|
||||
Scripting::cb_MetatileChanged(i % width, i / width, prevBlock, newBlock);
|
||||
if (enableScriptCallback)
|
||||
Scripting::cb_MetatileChanged(i % width, i / width, prevBlock, newBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +391,7 @@ void Map::setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScri
|
|||
}
|
||||
}
|
||||
|
||||
void Map::setBorderBlockData(Blockdata blockdata) {
|
||||
void Map::setBorderBlockData(Blockdata blockdata, bool enableScriptCallback) {
|
||||
int width = getBorderWidth();
|
||||
int size = qMin(blockdata.size(), layout->border.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -398,7 +399,8 @@ void Map::setBorderBlockData(Blockdata blockdata) {
|
|||
Block newBlock = blockdata.at(i);
|
||||
if (prevBlock != newBlock) {
|
||||
layout->border.replace(i, newBlock);
|
||||
Scripting::cb_BorderMetatileChanged(i % width, i / width, prevBlock.metatileId, newBlock.metatileId);
|
||||
if (enableScriptCallback)
|
||||
Scripting::cb_BorderMetatileChanged(i % width, i / width, prevBlock.metatileId, newBlock.metatileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2984,8 +2984,8 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked()
|
|||
QSize newMapDimensions(widthSpinBox->value(), heightSpinBox->value());
|
||||
QSize newBorderDimensions(bwidthSpinBox->value(), bheightSpinBox->value());
|
||||
if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) {
|
||||
editor->map->setDimensions(newMapDimensions.width(), newMapDimensions.height());
|
||||
editor->map->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height());
|
||||
editor->map->setDimensions(newMapDimensions.width(), newMapDimensions.height(), true);
|
||||
editor->map->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height(), true);
|
||||
editor->map->editHistory.push(new ResizeMap(map,
|
||||
oldMapDimensions, newMapDimensions,
|
||||
oldMetatiles, map->layout->blockdata,
|
||||
|
|
Loading…
Reference in a new issue