Trigger onBlockChanged for blocks changed by undo/redo
This commit is contained in:
parent
d00cba3382
commit
8f62268d00
3 changed files with 22 additions and 8 deletions
|
@ -81,6 +81,7 @@ 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 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);
|
||||
|
|
|
@ -49,7 +49,7 @@ void PaintMetatile::redo() {
|
|||
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = newMetatiles;
|
||||
map->setBlockdata(newMetatiles);
|
||||
|
||||
map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -59,7 +59,7 @@ void PaintMetatile::redo() {
|
|||
void PaintMetatile::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = oldMetatiles;
|
||||
map->setBlockdata(oldMetatiles);
|
||||
|
||||
map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -139,7 +139,7 @@ void ShiftMetatiles::redo() {
|
|||
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = newMetatiles;
|
||||
map->setBlockdata(newMetatiles);
|
||||
|
||||
map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -149,7 +149,7 @@ void ShiftMetatiles::redo() {
|
|||
void ShiftMetatiles::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = oldMetatiles;
|
||||
map->setBlockdata(oldMetatiles);
|
||||
|
||||
map->layout->lastCommitMapBlocks.blocks = map->layout->blockdata;
|
||||
|
||||
|
@ -209,7 +209,7 @@ void ResizeMap::redo() {
|
|||
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = newMetatiles;
|
||||
map->setBlockdata(newMetatiles);
|
||||
map->setDimensions(newMapWidth, newMapHeight, false);
|
||||
|
||||
map->layout->border = newBorder;
|
||||
|
@ -223,7 +223,7 @@ void ResizeMap::redo() {
|
|||
void ResizeMap::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = oldMetatiles;
|
||||
map->setBlockdata(oldMetatiles);
|
||||
map->setDimensions(oldMapWidth, oldMapHeight, false);
|
||||
|
||||
map->layout->border = oldBorder;
|
||||
|
@ -510,7 +510,7 @@ void ScriptEditMap::redo() {
|
|||
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = newMetatiles;
|
||||
map->setBlockdata(newMetatiles);
|
||||
if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) {
|
||||
map->setDimensions(newMapWidth, newMapHeight, false);
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ void ScriptEditMap::redo() {
|
|||
void ScriptEditMap::undo() {
|
||||
if (!map) return;
|
||||
|
||||
map->layout->blockdata = oldMetatiles;
|
||||
map->setBlockdata(oldMetatiles);
|
||||
if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) {
|
||||
map->setDimensions(oldMapWidth, oldMapHeight, false);
|
||||
}
|
||||
|
|
|
@ -354,6 +354,19 @@ void Map::setBlock(int x, int y, Block block, bool enableScriptCallback) {
|
|||
}
|
||||
}
|
||||
|
||||
void Map::setBlockdata(Blockdata blockdata) {
|
||||
int width = getWidth();
|
||||
int size = qMin(blockdata.size(), layout->blockdata.size());
|
||||
for (int i = 0; i < size; i++) {
|
||||
Block prevBlock = layout->blockdata.at(i);
|
||||
Block newBlock = blockdata.at(i);
|
||||
if (prevBlock != newBlock) {
|
||||
layout->blockdata.replace(i, newBlock);
|
||||
Scripting::cb_MetatileChanged(i % width, i / width, prevBlock, newBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
|
||||
QList<QPoint> todo;
|
||||
todo.append(QPoint(x, y));
|
||||
|
|
Loading…
Reference in a new issue