Simplify some usages of Blockdata
This commit is contained in:
parent
f09e28f06c
commit
a3326a764b
5 changed files with 27 additions and 48 deletions
|
@ -75,8 +75,8 @@ public:
|
||||||
int getBorderHeight();
|
int getBorderHeight();
|
||||||
QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr);
|
QPixmap render(bool ignoreCache, MapLayout * fromLayout = nullptr);
|
||||||
QPixmap renderCollision(qreal opacity, bool ignoreCache);
|
QPixmap renderCollision(qreal opacity, bool ignoreCache);
|
||||||
bool mapBlockChanged(int i, Blockdata cache);
|
bool mapBlockChanged(int i, const Blockdata &cache);
|
||||||
bool borderBlockChanged(int i, Blockdata cache);
|
bool borderBlockChanged(int i, const Blockdata &cache);
|
||||||
void cacheBlockdata();
|
void cacheBlockdata();
|
||||||
void cacheCollision();
|
void cacheCollision();
|
||||||
bool getBlock(int x, int y, Block *out);
|
bool getBlock(int x, int y, Block *out);
|
||||||
|
|
|
@ -78,7 +78,7 @@ int Map::getBorderHeight() {
|
||||||
return layout->border_height.toInt(nullptr, 0);
|
return layout->border_height.toInt(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::mapBlockChanged(int i, Blockdata cache) {
|
bool Map::mapBlockChanged(int i, const Blockdata &cache) {
|
||||||
if (cache.length() <= i)
|
if (cache.length() <= i)
|
||||||
return true;
|
return true;
|
||||||
if (layout->blockdata.length() <= i)
|
if (layout->blockdata.length() <= i)
|
||||||
|
@ -87,7 +87,7 @@ bool Map::mapBlockChanged(int i, Blockdata cache) {
|
||||||
return layout->blockdata.at(i) != cache.at(i);
|
return layout->blockdata.at(i) != cache.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Map::borderBlockChanged(int i, Blockdata cache) {
|
bool Map::borderBlockChanged(int i, const Blockdata &cache) {
|
||||||
if (cache.length() <= i)
|
if (cache.length() <= i)
|
||||||
return true;
|
return true;
|
||||||
if (layout->border.length() <= i)
|
if (layout->border.length() <= i)
|
||||||
|
|
|
@ -21,9 +21,8 @@ void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Blockdata newBorder = map->layout->border;
|
if (map->layout->border != oldBorder) {
|
||||||
if (newBorder != oldBorder) {
|
map->editHistory.push(new PaintBorder(map, oldBorder, map->layout->border, 0));
|
||||||
map->editHistory.push(new PaintBorder(map, oldBorder, newBorder, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit borderMetatilesChanged();
|
emit borderMetatilesChanged();
|
||||||
|
|
|
@ -65,9 +65,8 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
||||||
map->setBlock(pos.x(), pos.y(), block, true);
|
map->setBlock(pos.x(), pos.y(), block, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Blockdata newCollision = map->layout->blockdata;
|
if (map->layout->blockdata != oldCollision) {
|
||||||
if (newCollision != oldCollision) {
|
map->editHistory.push(new PaintCollision(map, oldCollision, map->layout->blockdata, actionId_));
|
||||||
map->editHistory.push(new PaintCollision(map, oldCollision, newCollision, actionId_));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,9 +82,8 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
||||||
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
||||||
map->floodFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
map->floodFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
||||||
|
|
||||||
Blockdata newCollision = map->layout->blockdata;
|
if (map->layout->blockdata != oldCollision) {
|
||||||
if (newCollision != oldCollision) {
|
map->editHistory.push(new BucketFillCollision(map, oldCollision, map->layout->blockdata));
|
||||||
map->editHistory.push(new BucketFillCollision(map, oldCollision, newCollision));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,9 +98,8 @@ void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
|
||||||
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
||||||
map->magicFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
map->magicFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
||||||
|
|
||||||
Blockdata newCollision = map->layout->blockdata;
|
if (map->layout->blockdata != oldCollision) {
|
||||||
if (newCollision != oldCollision) {
|
map->editHistory.push(new MagicFillCollision(map, oldCollision, map->layout->blockdata));
|
||||||
map->editHistory.push(new MagicFillCollision(map, oldCollision, newCollision));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,8 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
|
void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
|
||||||
Blockdata backupBlockdata = map->layout->blockdata;
|
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
|
||||||
|
|
||||||
for (int i = 0; i < map->getWidth(); i++)
|
for (int i = 0; i < map->getWidth(); i++)
|
||||||
for (int j = 0; j < map->getHeight(); j++) {
|
for (int j = 0; j < map->getHeight(); j++) {
|
||||||
int destX = i + xDelta;
|
int destX = i + xDelta;
|
||||||
|
@ -89,15 +90,12 @@ void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) {
|
||||||
destY %= map->getHeight();
|
destY %= map->getHeight();
|
||||||
|
|
||||||
int blockIndex = j * map->getWidth() + i;
|
int blockIndex = j * map->getWidth() + i;
|
||||||
Block srcBlock = backupBlockdata.at(blockIndex);
|
Block srcBlock = oldMetatiles.at(blockIndex);
|
||||||
map->setBlock(destX, destY, srcBlock);
|
map->setBlock(destX, destY, srcBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromScriptCall) {
|
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||||
Blockdata newMetatiles = map->layout->blockdata;
|
map->editHistory.push(new ShiftMetatiles(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||||
if (newMetatiles != backupBlockdata) {
|
|
||||||
map->editHistory.push(new ShiftMetatiles(map, backupBlockdata, newMetatiles, actionId_));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,11 +135,8 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromScriptCall) {
|
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||||
Blockdata newMetatiles = map->layout->blockdata;
|
map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||||
if (newMetatiles != oldMetatiles) {
|
|
||||||
map->editHistory.push(new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,11 +248,8 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
||||||
map->setBlock(actualX, actualY, block, !fromScriptCall);
|
map->setBlock(actualX, actualY, block, !fromScriptCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromScriptCall) {
|
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||||
Blockdata newMetatiles = map->layout->blockdata;
|
map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||||
if (newMetatiles != oldMetatiles) {
|
|
||||||
map->editHistory.push(new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,11 +424,8 @@ void MapPixmapItem::magicFill(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromScriptCall) {
|
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||||
Blockdata newMetatiles = map->layout->blockdata;
|
map->editHistory.push(new MagicFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||||
if (newMetatiles != oldMetatiles) {
|
|
||||||
map->editHistory.push(new MagicFillMetatile(map, oldMetatiles, newMetatiles, actionId_));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,11 +502,8 @@ void MapPixmapItem::floodFill(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromScriptCall) {
|
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||||
Blockdata newMetatiles = map->layout->blockdata;
|
map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||||
if (newMetatiles != oldMetatiles) {
|
|
||||||
map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,11 +621,8 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromScriptCall) {
|
if (!fromScriptCall && map->layout->blockdata != oldMetatiles) {
|
||||||
Blockdata newMetatiles = map->layout->blockdata;
|
map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata, actionId_));
|
||||||
if (newMetatiles != oldMetatiles) {
|
|
||||||
map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue