fix the scripting api and many other changes

- remove obsolete Map::commit()
- add ScriptEditMap command
- reorganize metatile history
- fix next selected event for multi event deletion
This commit is contained in:
garakmon 2020-08-03 20:49:00 -04:00 committed by garak
parent 6c2d035dfa
commit 392e595a03
18 changed files with 210 additions and 145 deletions

View file

@ -12,22 +12,22 @@ class DraggablePixmapItem;
class Editor;
enum CommandId {
ID_PaintMetatile, // - done
ID_BucketFillMetatile, // - done
ID_MagicFillMetatile, // - done
ID_ShiftMetatiles, // - done
ID_PaintCollision, // -
ID_BucketFillCollision, // -
ID_MagicFillCollision, // -
ID_ResizeMap, // - done
ID_PaintBorder, // - done
ID_EventMove, // - done
ID_EventShift, // - done
ID_EventCreate, // - done
ID_EventDelete, // - done
ID_EventDuplicate, // - done
ID_EventSetData, // - ?
// Region map editor history commands
ID_PaintMetatile,
ID_BucketFillMetatile,
ID_MagicFillMetatile,
ID_ShiftMetatiles,
ID_PaintCollision,
ID_BucketFillCollision,
ID_MagicFillCollision,
ID_ResizeMap,
ID_PaintBorder,
ID_EventMove,
ID_EventShift,
ID_EventCreate,
ID_EventDelete,
ID_EventDuplicate,
ID_EventSetData,
ID_ScriptEditMap,
};
@ -85,7 +85,7 @@ public:
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override { return false; };
bool mergeWith(const QUndoCommand *) override { return false; };
int id() const override { return CommandId::ID_PaintBorder; }
private:
@ -108,7 +108,7 @@ public:
unsigned actionId, QUndoCommand *parent = nullptr);
~BucketFillMetatile();
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_BucketFillMetatile; }
};
@ -125,7 +125,7 @@ public:
setText("Flood Fill Collision");
}
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_BucketFillCollision; }
};
@ -140,7 +140,7 @@ public:
unsigned actionId, QUndoCommand *parent = nullptr);
~MagicFillMetatile();
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_BucketFillMetatile; }
};
@ -156,7 +156,7 @@ public:
setText("Magic Fill Collision");
}
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_MagicFillCollision; }
};
@ -200,7 +200,7 @@ public:
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_ResizeMap; }
private:
@ -274,7 +274,7 @@ public:
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_EventCreate; }
private:
@ -297,7 +297,7 @@ public:
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_EventDelete; }
private:
@ -319,7 +319,7 @@ public:
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override { return false; }
bool mergeWith(const QUndoCommand *) override { return false; }
int id() const override { return CommandId::ID_EventDuplicate; }
private:
@ -328,4 +328,34 @@ private:
Editor *editor;
};
/// Implements a command to commit map edits from the scripting API.
/// The scripting api can edit metatiles and map dimensions.
class ScriptEditMap : public QUndoCommand {
public:
ScriptEditMap(Map *map,
QSize oldMapDimensions, QSize newMapDimensions,
Blockdata *oldMetatiles, Blockdata *newMetatiles,
QUndoCommand *parent = nullptr);
~ScriptEditMap();
void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *) override { return false; };
int id() const override { return CommandId::ID_ScriptEditMap; }
private:
Map *map;
Blockdata *newMetatiles;
Blockdata *oldMetatiles;
int oldMapWidth;
int oldMapHeight;
int newMapWidth;
int newMapHeight;
};
#endif // EDITCOMMANDS_H

View file

@ -1,35 +0,0 @@
#ifndef HISTORYITEM_H
#define HISTORYITEM_H
#include "blockdata.h"
class HistoryItem {
public:
Blockdata *metatiles;
Blockdata *border;
int layoutWidth;
int layoutHeight;
int borderWidth;
int borderHeight;
HistoryItem(Blockdata *metatiles, Blockdata *border, int layoutWidth, int layoutHeight, int borderWidth, int borderHeight);
~HistoryItem();
};
enum RegionMapEditorBox {
BackgroundImage = 1,
CityMapImage = 2,
};
class RegionMapHistoryItem {
public:
int which;
int mapWidth = 0;
int mapHeight = 0;
QVector<uint8_t> tiles;
QString cityMap;
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, QString cityMap);
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, int width, int height);
~RegionMapHistoryItem();
};
#endif // HISTORYITEM_H

View file

@ -2,8 +2,6 @@
#define MAP_H
#include "blockdata.h"
#include "history.h"
#include "historyitem.h"
#include "mapconnection.h"
#include "maplayout.h"
#include "tileset.h"
@ -59,7 +57,6 @@ public:
QPixmap collision_pixmap;
QImage image;
QPixmap pixmap;
History<HistoryItem*> metatileHistory;
QMap<QString, QList<Event*>> events;
QList<MapConnection*> connections;
QList<int> metatileLayerOrder;
@ -104,8 +101,6 @@ public:
BorderMetatilesPixmapItem *borderItem = nullptr;
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
void commit(); // TODO: delete this
QUndoStack editHistory;
private:

View file

@ -30,6 +30,10 @@ public:
Blockdata *cached_blockdata = nullptr;
Blockdata *cached_collision = nullptr;
Blockdata *cached_border = nullptr;
struct {
Blockdata *blocks = nullptr;
QSize dimensions;
} lastCommitMapBlocks; // to track map changes
};
#endif // MAPLAYOUT_H

View file

@ -5,7 +5,6 @@
#include "project.h"
#include "tilemaptileselector.h"
#include "history.h"
#include "historyitem.h"
#include <QStringList>
#include <QString>
@ -15,6 +14,32 @@
#include <QGraphicsScene>
#include <QGraphicsView>
enum RegionMapEditorBox {
BackgroundImage = 1,
CityMapImage = 2,
};
class RegionMapHistoryItem {
public:
int which;
int mapWidth = 0;
int mapHeight = 0;
QVector<uint8_t> tiles;
QString cityMap;
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, QString cityMap) {
this->which = which;
this->tiles = tiles;
this->cityMap = cityMap;
}
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, int width, int height) {
this->which = which;
this->tiles = tiles;
this->mapWidth = width;
this->mapHeight = height;
}
~RegionMapHistoryItem() {}
};
class RegionMapEntry
{
public:

View file

@ -60,7 +60,7 @@ public:
virtual void pick(QGraphicsSceneMouseEvent*);
virtual void select(QGraphicsSceneMouseEvent*);
virtual void shift(QGraphicsSceneMouseEvent*);
void shift(int xDelta, int yDelta);
void shift(int xDelta, int yDelta, bool fromScriptCall = false);
virtual void draw(bool ignoreCache = false);
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
void paintNormal(int x, int y, bool fromScriptCall = false);

View file

@ -6,8 +6,6 @@
#include "regionmaplayoutpixmapitem.h"
#include "regionmapentriespixmapitem.h"
#include "regionmap.h"
#include "history.h"
#include "historyitem.h"
#include <QMainWindow>
#include <QGraphicsSceneMouseEvent>

View file

@ -18,7 +18,6 @@ SOURCES += src/core/block.cpp \
src/core/blockdata.cpp \
src/core/event.cpp \
src/core/heallocation.cpp \
src/core/historyitem.cpp \
src/core/imageexport.cpp \
src/core/map.cpp \
src/core/maplayout.cpp \
@ -84,7 +83,6 @@ HEADERS += include/core/block.h \
include/core/event.h \
include/core/heallocation.h \
include/core/history.h \
include/core/historyitem.h \
include/core/imageexport.h \
include/core/map.h \
include/core/mapconnection.h \

View file

@ -38,6 +38,8 @@ void PaintMetatile::redo() {
map->layout->blockdata->copyFrom(newMetatiles);
}
map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata);
renderMapBlocks(map);
}
@ -48,6 +50,8 @@ void PaintMetatile::undo() {
map->layout->blockdata->copyFrom(oldMetatiles);
}
map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata);
renderMapBlocks(map);
QUndoCommand::undo();
@ -172,6 +176,8 @@ void ShiftMetatiles::redo() {
map->layout->blockdata->copyFrom(newMetatiles);
}
map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata);
renderMapBlocks(map, true);
}
@ -182,6 +188,8 @@ void ShiftMetatiles::undo() {
map->layout->blockdata->copyFrom(oldMetatiles);
}
map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata);
renderMapBlocks(map, true);
QUndoCommand::undo();
@ -253,6 +261,8 @@ void ResizeMap::redo() {
map->setBorderDimensions(newBorderWidth, newBorderHeight, false);
}
map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight());
map->mapNeedsRedrawing();
}
@ -269,6 +279,8 @@ void ResizeMap::undo() {
map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false);
}
map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight());
map->mapNeedsRedrawing();
QUndoCommand::undo();
@ -420,7 +432,8 @@ void EventDelete::redo() {
map->objectsChanged();
editor->selected_events->clear();
editor->selected_events->append(nextSelectedEvent->pixmapItem);
if (nextSelectedEvent)
editor->selected_events->append(nextSelectedEvent->pixmapItem);
editor->updateSelectedEvents();
}
@ -499,3 +512,65 @@ void EventDuplicate::undo() {
QUndoCommand::undo();
}
/******************************************************************************
************************************************************************
******************************************************************************/
ScriptEditMap::ScriptEditMap(Map *map,
QSize oldMapDimensions, QSize newMapDimensions,
Blockdata *oldMetatiles, Blockdata *newMetatiles,
QUndoCommand *parent) : QUndoCommand(parent) {
setText("Script Edit Map");
this->map = map;
this->newMetatiles = newMetatiles;
this->oldMetatiles = oldMetatiles;
this->oldMapWidth = oldMapWidth;
this->oldMapHeight = oldMapHeight;
this->newMapWidth = newMapWidth;
this->newMapHeight = newMapHeight;
}
ScriptEditMap::~ScriptEditMap() {
if (newMetatiles) delete newMetatiles;
if (oldMetatiles) delete oldMetatiles;
}
void ScriptEditMap::redo() {
QUndoCommand::redo();
if (!map) return;
if (map->layout->blockdata) {
map->layout->blockdata->copyFrom(newMetatiles);
if (newMapWidth != map->getWidth() || newMapHeight != map->getHeight()) {
map->setDimensions(newMapWidth, newMapHeight);
}
}
map->layout->lastCommitMapBlocks.blocks->copyFrom(newMetatiles);
map->layout->lastCommitMapBlocks.dimensions = QSize(newMapWidth, newMapHeight);
renderMapBlocks(map);
}
void ScriptEditMap::undo() {
if (!map) return;
if (map->layout->blockdata) {
map->layout->blockdata->copyFrom(oldMetatiles);
if (oldMapWidth != map->getWidth() || oldMapHeight != map->getHeight()) {
map->setDimensions(oldMapWidth, oldMapHeight);
}
}
map->layout->lastCommitMapBlocks.blocks->copyFrom(oldMetatiles);
map->layout->lastCommitMapBlocks.dimensions = QSize(oldMapWidth, oldMapHeight);
renderMapBlocks(map);
QUndoCommand::undo();
}

View file

@ -1,4 +0,0 @@
#include "history.h"
#include "historyitem.h"

View file

@ -1,30 +0,0 @@
#include "historyitem.h"
HistoryItem::HistoryItem(Blockdata *metatiles, Blockdata *border, int layoutWidth, int layoutHeight, int borderWidth, int borderHeight) {
this->metatiles = metatiles;
this->border = border;
this->layoutWidth = layoutWidth;
this->layoutHeight = layoutHeight;
this->borderWidth = borderWidth;
this->borderHeight = borderHeight;
}
HistoryItem::~HistoryItem() {
if (this->metatiles) delete this->metatiles;
if (this->border) delete this->border;
}
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector<uint8_t> tiles, QString cityMap) {
this->which = which;
this->tiles = tiles;
this->cityMap = cityMap;
}
RegionMapHistoryItem::RegionMapHistoryItem(int which, QVector<uint8_t> tiles, int width, int height) {
this->which = which;
this->tiles = tiles;
this->mapWidth = width;
this->mapHeight = height;
}
RegionMapHistoryItem::~RegionMapHistoryItem() {}

View file

@ -1,5 +1,4 @@
#include "history.h"
#include "historyitem.h"
#include "map.h"
#include "imageproviders.h"
#include "scripting.h"
@ -416,15 +415,10 @@ void Map::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_
}
}
void Map::commit() {
return;
}
void Map::floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
Block *block = getBlock(x, y);
if (block && (block->collision != collision || block->elevation != elevation)) {
_floodFillCollisionElevation(x, y, collision, elevation);
commit();
}
}
@ -444,7 +438,6 @@ void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t colli
}
}
}
commit();
}
}

View file

@ -1,4 +1,5 @@
#include "regionmap.h"
#include "regionmapeditor.h"
#include "paletteutil.h"
#include "log.h"
#include "config.h"

View file

@ -108,6 +108,7 @@ void MainWindow::initExtraShortcuts() {
new QShortcut(QKeySequence("Ctrl+G"), ui->checkBox_ToggleGrid, SLOT(toggle()));
new QShortcut(QKeySequence("Ctrl+D"), this, SLOT(duplicate()));
new QShortcut(QKeySequence::Delete, this, SLOT(on_toolButton_deleteObject_clicked()));
new QShortcut(QKeySequence("Backspace"), this, SLOT(on_toolButton_deleteObject_clicked()));
ui->actionZoom_In->setShortcuts({QKeySequence("Ctrl++"), QKeySequence("Ctrl+=")});
}
@ -2131,13 +2132,15 @@ void MainWindow::on_toolButton_deleteObject_clicked() {
if (editor->selected_events->length()) {
DraggablePixmapItem *nextSelectedEvent = nullptr;
QList<Event *> selectedEvents;
int numEvents = editor->selected_events->length();
int numDeleted = 0;
for (DraggablePixmapItem *item : *editor->selected_events) {
QString event_group = item->event->get("event_group_type");
if (event_group != "heal_event_group") {
// Get the index for the event that should be selected after this event has been deleted.
// If it's at the end of the list, select the previous event, otherwise select the next one.
// Don't bother getting the event to select if there are still more events to delete
if (editor->selected_events->length() == 1) {
if (++numDeleted == numEvents) {
int index = editor->map->events.value(event_group).indexOf(item->event);
if (index != editor->map->events.value(event_group).size() - 1)
index++;
@ -2161,7 +2164,7 @@ void MainWindow::on_toolButton_deleteObject_clicked() {
logWarn(QString("Cannot delete event of type '%1'").arg(item->event->get("event_type")));
}
}
editor->map->editHistory.push(new EventDelete(editor, editor->map, selectedEvents, nextSelectedEvent->event));
editor->map->editHistory.push(new EventDelete(editor, editor->map, selectedEvents, nextSelectedEvent ? nextSelectedEvent->event : nullptr));
}
}
}

View file

@ -1,6 +1,9 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "scripting.h"
#include "editcommands.h"
static Blockdata *oldBlockdata;
QJSValue MainWindow::getBlock(int x, int y) {
if (!this->editor || !this->editor->map)
@ -21,7 +24,13 @@ void MainWindow::tryRedrawMapArea(bool forceRedraw) {
void MainWindow::tryCommitMapChanges(bool commitChanges) {
if (commitChanges) {
this->editor->map->commit();
Map *map = this->editor->map;
if (map) {
map->editHistory.push(new ScriptEditMap(map,
map->layout->lastCommitMapBlocks.dimensions, QSize(map->getWidth(), map->getHeight()),
map->layout->lastCommitMapBlocks.blocks->copy(), map->layout->blockdata->copy()
));
}
}
}
@ -179,7 +188,7 @@ void MainWindow::setDimensions(int width, int height) {
if (!Project::mapDimensionsValid(width, height))
return;
this->editor->map->setDimensions(width, height);
this->editor->map->commit();
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
}
@ -189,7 +198,7 @@ void MainWindow::setWidth(int width) {
if (!Project::mapDimensionsValid(width, this->editor->map->getHeight()))
return;
this->editor->map->setDimensions(width, this->editor->map->getHeight());
this->editor->map->commit();
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
}
@ -199,7 +208,7 @@ void MainWindow::setHeight(int height) {
if (!Project::mapDimensionsValid(this->editor->map->getWidth(), height))
return;
this->editor->map->setDimensions(this->editor->map->getWidth(), height);
this->editor->map->commit();
this->tryCommitMapChanges(true);
this->onMapNeedsRedrawing();
}

View file

@ -1,7 +1,6 @@
#include "project.h"
#include "config.h"
#include "history.h"
#include "historyitem.h"
#include "log.h"
#include "parseutil.h"
#include "paletteutil.h"
@ -170,8 +169,6 @@ Map* Project::loadMap(QString map_name) {
if (!(loadMapData(map) && loadMapLayout(map)))
return nullptr;
map->commit();
map->metatileHistory.save();
mapCache->insert(map_name, map);
return map;
}
@ -1186,6 +1183,12 @@ bool Project::loadBlockdata(Map *map) {
QString path = QString("%1/%2").arg(root).arg(map->layout->blockdata_path);
map->layout->blockdata = readBlockdata(path);
if (map->layout->lastCommitMapBlocks.blocks) {
delete map->layout->lastCommitMapBlocks.blocks;
}
map->layout->lastCommitMapBlocks.blocks = new Blockdata;
map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata);
map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight());
if (map->layout->blockdata->blocks->count() != map->getWidth() * map->getHeight()) {
logWarn(QString("Layout blockdata length %1 does not match dimensions %2x%3 (should be %4). Resizing blockdata.")
@ -1204,6 +1207,8 @@ void Project::setNewMapBlockdata(Map *map) {
blockdata->addBlock(qint16(0x3001));
}
map->layout->blockdata = blockdata;
map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata);
map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight());
}
bool Project::loadMapBorder(Map *map) {
@ -1251,7 +1256,6 @@ void Project::saveLayoutBorder(Map *map) {
void Project::saveLayoutBlockdata(Map* map) {
QString path = QString("%1/%2").arg(root).arg(map->layout->blockdata_path);
writeBlockdata(path, map->layout->blockdata);
map->metatileHistory.save();
}
void Project::writeBlockdata(QString path, Blockdata *blockdata) {
@ -1897,8 +1901,6 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
setNewMapBorder(map);
setNewMapEvents(map);
setNewMapConnections(map);
map->commit();
map->metatileHistory.save();
mapCache->insert(mapName, map);
return map;
@ -1928,9 +1930,6 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool
setNewMapEvents(map);
setNewMapConnections(map);
map->commit();
map->metatileHistory.save();
return map;
}

View file

@ -54,7 +54,6 @@ void BorderMetatilesPixmapItem::draw() {
}
painter.end();
map->commit();
this->setPixmap(QPixmap::fromImage(image));
emit borderMetatilesChanged();

View file

@ -52,7 +52,7 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
}
}
void MapPixmapItem::shift(int xDelta, int yDelta) {
void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
Blockdata *backupBlockdata = map->layout->blockdata->copy();
for (int i = 0; i < map->getWidth(); i++)
for (int j = 0; j < map->getHeight(); j++) {
@ -70,9 +70,11 @@ void MapPixmapItem::shift(int xDelta, int yDelta) {
map->setBlock(destX, destY, srcBlock);
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
ShiftMetatiles *paintEvent = new ShiftMetatiles(map, backupBlockdata, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
if (!fromScriptCall) {
map->editHistory.push(new ShiftMetatiles(map, backupBlockdata, map->layout->blockdata->copy(), actionId_));
} else {
delete backupBlockdata;
}
}
void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
@ -93,7 +95,8 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
y = initialY + (yDiff / selectionDimensions.y()) * selectionDimensions.y();
// for edit history
Blockdata *oldMetatiles = map->layout->blockdata->copy();
Blockdata *oldMetatiles;
if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy();
for (int i = 0; i < selectionDimensions.x() && i + x < map->getWidth(); i++)
for (int j = 0; j < selectionDimensions.y() && j + y < map->getHeight(); j++) {
@ -111,9 +114,9 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
}
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
PaintMetatile *paintEvent = new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
if (!fromScriptCall) {
map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata->copy(), actionId_));
}
}
// These are tile offsets from the top-left tile in the 3x3 smart path selection.
@ -339,7 +342,8 @@ void MapPixmapItem::magicFill(
return;
}
Blockdata *oldMetatiles = map->layout->blockdata->copy();
Blockdata *oldMetatiles;
if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy();
bool setCollisions = selectedCollisions && selectedCollisions->length() == selectedMetatiles->length();
uint16_t tile = block->tile;
@ -364,9 +368,9 @@ void MapPixmapItem::magicFill(
}
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
MagicFillMetatile *paintEvent = new MagicFillMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
if (!fromScriptCall) {
map->editHistory.push(new MagicFillMetatile(map, oldMetatiles, map->layout->blockdata->copy(), actionId_));
}
}
}
@ -397,7 +401,8 @@ void MapPixmapItem::floodFill(
for (int i = 0; i < numMetatiles; i++)
visited[i] = false;
Blockdata *oldMetatiles = map->layout->blockdata->copy();
Blockdata *oldMetatiles;
if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy();
QList<QPoint> todo;
todo.append(QPoint(initialX, initialY));
@ -447,9 +452,9 @@ void MapPixmapItem::floodFill(
}
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
BucketFillMetatile *paintEvent = new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
if (!fromScriptCall) {
map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata->copy(), actionId_));
}
delete[] visited;
}