Privatize Block members

This commit is contained in:
GriffinR 2023-12-12 18:32:54 -05:00
parent 8164aae151
commit 2228f78117
10 changed files with 136 additions and 124 deletions

View file

@ -14,10 +14,18 @@ public:
Block &operator=(const Block &);
bool operator ==(Block) const;
bool operator !=(Block) const;
uint16_t metatileId:10;
uint16_t collision:2;
uint16_t elevation:4;
void setMetatileId(uint16_t metatileId) { m_metatileId = metatileId; }
void setCollision(uint16_t collision) { m_collision = collision; }
void setElevation(uint16_t elevation) { m_elevation = elevation; }
uint16_t metatileId() const { return m_metatileId; }
uint16_t collision() const { return m_collision; }
uint16_t elevation() const { return m_elevation; }
uint16_t rawValue() const;
private:
uint16_t m_metatileId; // 10
uint16_t m_collision; // 2
uint16_t m_elevation; // 4
};
#endif // BLOCK_H

View file

@ -1,41 +1,45 @@
#include "block.h"
Block::Block() : metatileId(0), collision(0), elevation(0) { }
Block::Block() :
m_metatileId(0),
m_collision(0),
m_elevation(0)
{ }
Block::Block(uint16_t metatileId, uint16_t collision, uint16_t elevation) :
metatileId(metatileId),
collision(collision),
elevation(elevation)
m_metatileId(metatileId),
m_collision(collision),
m_elevation(elevation)
{ }
Block::Block(uint16_t word) :
metatileId(word & 0x3ff),
collision((word >> 10) & 0x3),
elevation((word >> 12) & 0xf)
m_metatileId(word & 0x3ff),
m_collision((word >> 10) & 0x3),
m_elevation((word >> 12) & 0xf)
{ }
Block::Block(const Block &other) :
metatileId(other.metatileId),
collision(other.collision),
elevation(other.elevation)
m_metatileId(other.m_metatileId),
m_collision(other.m_collision),
m_elevation(other.m_elevation)
{ }
Block &Block::operator=(const Block &other) {
metatileId = other.metatileId;
collision = other.collision;
elevation = other.elevation;
m_metatileId = other.m_metatileId;
m_collision = other.m_collision;
m_elevation = other.m_elevation;
return *this;
}
uint16_t Block::rawValue() const {
return static_cast<uint16_t>(
(metatileId & 0x3ff) +
((collision & 0x3) << 10) +
((elevation & 0xf) << 12));
(m_metatileId & 0x3ff) +
((m_collision & 0x3) << 10) +
((m_elevation & 0xf) << 12));
}
bool Block::operator ==(Block other) const {
return (metatileId == other.metatileId) && (collision == other.collision) && (elevation == other.elevation);
return (m_metatileId == other.m_metatileId) && (m_collision == other.m_collision) && (m_elevation == other.m_elevation);
}
bool Block::operator !=(Block other) const {

View file

@ -160,7 +160,7 @@ QPixmap Map::render(bool ignoreCache, MapLayout * fromLayout, QRect bounds) {
QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
Block block = layout->blockdata.at(i);
QImage metatile_image = getMetatileImage(
block.metatileId,
block.metatileId(),
fromLayout ? fromLayout->tileset_primary : layout->tileset_primary,
fromLayout ? fromLayout->tileset_secondary : layout->tileset_secondary,
metatileLayerOrder,
@ -201,7 +201,7 @@ QPixmap Map::renderBorder(bool ignoreCache) {
changed_any = true;
Block block = layout->border.at(i);
uint16_t metatileId = block.metatileId;
uint16_t metatileId = block.metatileId();
QImage metatile_image = getMetatileImage(metatileId, layout->tileset_primary, layout->tileset_secondary, metatileLayerOrder, metatileLayerOpacity);
int map_y = width_ ? i / width_ : 0;
int map_x = width_ ? i % width_ : 0;
@ -364,14 +364,14 @@ void Map::setBlockdata(Blockdata blockdata, bool enableScriptCallback) {
uint16_t Map::getBorderMetatileId(int x, int y) {
int i = y * getBorderWidth() + x;
return layout->border[i].metatileId;
return layout->border[i].metatileId();
}
void Map::setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback) {
int i = y * getBorderWidth() + x;
if (i < layout->border.size()) {
uint16_t prevMetatileId = layout->border[i].metatileId;
layout->border[i].metatileId = metatileId;
uint16_t prevMetatileId = layout->border[i].metatileId();
layout->border[i].setMetatileId(metatileId);
if (prevMetatileId != metatileId && enableScriptCallback) {
Scripting::cb_BorderMetatileChanged(x, y, prevMetatileId, metatileId);
}
@ -387,7 +387,7 @@ void Map::setBorderBlockData(Blockdata blockdata, bool enableScriptCallback) {
if (prevBlock != newBlock) {
layout->border.replace(i, newBlock);
if (enableScriptCallback)
Scripting::cb_BorderMetatileChanged(i % width, i / width, prevBlock.metatileId, newBlock.metatileId);
Scripting::cb_BorderMetatileChanged(i % width, i / width, prevBlock.metatileId(), newBlock.metatileId());
}
}
}
@ -404,25 +404,25 @@ void Map::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_
continue;
}
uint old_coll = block.collision;
uint old_elev = block.elevation;
uint old_coll = block.collision();
uint old_elev = block.elevation();
if (old_coll == collision && old_elev == elevation) {
continue;
}
block.collision = collision;
block.elevation = elevation;
block.setCollision(collision);
block.setElevation(elevation);
setBlock(x, y, block, true);
if (getBlock(x + 1, y, &block) && block.collision == old_coll && block.elevation == old_elev) {
if (getBlock(x + 1, y, &block) && block.collision() == old_coll && block.elevation() == old_elev) {
todo.append(QPoint(x + 1, y));
}
if (getBlock(x - 1, y, &block) && block.collision == old_coll && block.elevation == old_elev) {
if (getBlock(x - 1, y, &block) && block.collision() == old_coll && block.elevation() == old_elev) {
todo.append(QPoint(x - 1, y));
}
if (getBlock(x, y + 1, &block) && block.collision == old_coll && block.elevation == old_elev) {
if (getBlock(x, y + 1, &block) && block.collision() == old_coll && block.elevation() == old_elev) {
todo.append(QPoint(x, y + 1));
}
if (getBlock(x, y - 1, &block) && block.collision == old_coll && block.elevation == old_elev) {
if (getBlock(x, y - 1, &block) && block.collision() == old_coll && block.elevation() == old_elev) {
todo.append(QPoint(x, y - 1));
}
}
@ -430,22 +430,22 @@ void Map::_floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_
void Map::floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
Block block;
if (getBlock(x, y, &block) && (block.collision != collision || block.elevation != elevation)) {
if (getBlock(x, y, &block) && (block.collision() != collision || block.elevation() != elevation)) {
_floodFillCollisionElevation(x, y, collision, elevation);
}
}
void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t collision, uint16_t elevation) {
Block block;
if (getBlock(initialX, initialY, &block) && (block.collision != collision || block.elevation != elevation)) {
uint old_coll = block.collision;
uint old_elev = block.elevation;
if (getBlock(initialX, initialY, &block) && (block.collision() != collision || block.elevation() != elevation)) {
uint old_coll = block.collision();
uint old_elev = block.elevation();
for (int y = 0; y < getHeight(); y++) {
for (int x = 0; x < getWidth(); x++) {
if (getBlock(x, y, &block) && block.collision == old_coll && block.elevation == old_elev) {
block.collision = collision;
block.elevation = elevation;
if (getBlock(x, y, &block) && block.collision() == old_coll && block.elevation() == old_elev) {
block.setCollision(collision);
block.setElevation(elevation);
setBlock(x, y, block, true);
}
}

View file

@ -1027,7 +1027,7 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
this->updateCursorRectPos(x, y);
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
int blockIndex = y * map->getWidth() + x;
int metatileId = map->layout->blockdata.at(blockIndex).metatileId;
int metatileId = map->layout->blockdata.at(blockIndex).metatileId();
this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x")
.arg(x)
.arg(y)
@ -1059,8 +1059,8 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
this->updateCursorRectPos(x, y);
if (map_item->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
int blockIndex = y * map->getWidth() + x;
uint16_t collision = map->layout->blockdata.at(blockIndex).collision;
uint16_t elevation = map->layout->blockdata.at(blockIndex).elevation;
uint16_t collision = map->layout->blockdata.at(blockIndex).collision();
uint16_t elevation = map->layout->blockdata.at(blockIndex).elevation();
QString message = QString("X: %1, Y: %2, %3")
.arg(x)
.arg(y)

View file

@ -99,7 +99,7 @@ int MainWindow::getMetatileId(int x, int y) {
if (!this->editor->map->getBlock(x, y, &block)) {
return 0;
}
return block.metatileId;
return block.metatileId();
}
void MainWindow::setMetatileId(int x, int y, int metatileId, bool forceRedraw, bool commitChanges) {
@ -109,7 +109,7 @@ void MainWindow::setMetatileId(int x, int y, int metatileId, bool forceRedraw, b
if (!this->editor->map->getBlock(x, y, &block)) {
return;
}
this->editor->map->setBlock(x, y, Block(metatileId, block.collision, block.elevation));
this->editor->map->setBlock(x, y, Block(metatileId, block.collision(), block.elevation()));
this->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw);
}
@ -121,7 +121,7 @@ int MainWindow::getCollision(int x, int y) {
if (!this->editor->map->getBlock(x, y, &block)) {
return 0;
}
return block.collision;
return block.collision();
}
void MainWindow::setCollision(int x, int y, int collision, bool forceRedraw, bool commitChanges) {
@ -131,7 +131,7 @@ void MainWindow::setCollision(int x, int y, int collision, bool forceRedraw, boo
if (!this->editor->map->getBlock(x, y, &block)) {
return;
}
this->editor->map->setBlock(x, y, Block(block.metatileId, collision, block.elevation));
this->editor->map->setBlock(x, y, Block(block.metatileId(), collision, block.elevation()));
this->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw);
}
@ -143,7 +143,7 @@ int MainWindow::getElevation(int x, int y) {
if (!this->editor->map->getBlock(x, y, &block)) {
return 0;
}
return block.elevation;
return block.elevation();
}
void MainWindow::setElevation(int x, int y, int elevation, bool forceRedraw, bool commitChanges) {
@ -153,7 +153,7 @@ void MainWindow::setElevation(int x, int y, int elevation, bool forceRedraw, boo
if (!this->editor->map->getBlock(x, y, &block)) {
return;
}
this->editor->map->setBlock(x, y, Block(block.metatileId, block.collision, elevation));
this->editor->map->setBlock(x, y, Block(block.metatileId(), block.collision(), elevation));
this->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw);
}

View file

@ -305,9 +305,9 @@ void Scripting::cb_BorderVisibilityToggled(bool visible) {
QJSValue Scripting::fromBlock(Block block) {
QJSValue obj = instance->engine->newObject();
obj.setProperty("metatileId", block.metatileId);
obj.setProperty("collision", block.collision);
obj.setProperty("elevation", block.elevation);
obj.setProperty("metatileId", block.metatileId());
obj.setProperty("collision", block.collision());
obj.setProperty("elevation", block.elevation());
obj.setProperty("rawValue", block.rawValue());
return obj;
}

View file

@ -75,8 +75,8 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
Block block;
if (map->getBlock(pos.x(), pos.y(), &block)) {
block.collision = this->selectedCollision->value();
block.elevation = this->selectedElevation->value();
block.setCollision(this->selectedCollision->value());
block.setElevation(this->selectedElevation->value());
map->setBlock(pos.x(), pos.y(), block, true);
}
@ -139,7 +139,7 @@ void CollisionPixmapItem::updateSelection(QPoint pos) {
Block block;
if (map->getBlock(pos.x(), pos.y(), &block)) {
const QSignalBlocker blocker(this->selectedCollision); // We only need a signal for changing one of them, not both
this->selectedCollision->setValue(block.collision);
this->selectedElevation->setValue(block.elevation);
this->selectedCollision->setValue(block.collision());
this->selectedElevation->setValue(block.elevation());
}
}

View file

@ -5,7 +5,7 @@
#include <QPainter>
QImage getCollisionMetatileImage(Block block) {
return getCollisionMetatileImage(block.collision, block.elevation);
return getCollisionMetatileImage(block.collision(), block.elevation());
}
QImage getCollisionMetatileImage(int collision, int elevation) {

View file

@ -129,11 +129,11 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
MetatileSelectionItem item = selection.metatileItems.at(index);
if (!item.enabled)
continue;
block.metatileId = item.metatileId;
block.setMetatileId(item.metatileId);
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
CollisionSelectionItem collisionItem = selection.collisionItems.at(index);
block.collision = collisionItem.collision;
block.elevation = collisionItem.elevation;
block.setCollision(collisionItem.collision);
block.setElevation(collisionItem.elevation);
}
map->setBlock(actualX, actualY, block, !fromScriptCall);
}
@ -195,13 +195,13 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
return;
// Shift to the middle tile of the smart path selection.
uint16_t openTile = selection.metatileItems.at(4).metatileId;
uint16_t openTileCollision = 0;
uint16_t openTileElevation = 0;
uint16_t openMetatileId = selection.metatileItems.at(4).metatileId;
uint16_t openCollision = 0;
uint16_t openElevation = 0;
bool setCollisions = false;
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
openTileCollision = selection.collisionItems.at(4).collision;
openTileElevation = selection.collisionItems.at(4).elevation;
openCollision = selection.collisionItems.at(4).collision;
openElevation = selection.collisionItems.at(4).elevation;
setCollisions = true;
}
@ -217,10 +217,10 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
int actualY = j + y;
Block block;
if (map->getBlock(actualX, actualY, &block)) {
block.metatileId = openTile;
block.setMetatileId(openMetatileId);
if (setCollisions) {
block.collision = openTileCollision;
block.elevation = openTileElevation;
block.setCollision(openCollision);
block.setElevation(openElevation);
}
map->setBlock(actualX, actualY, block, !fromScriptCall);
}
@ -240,7 +240,7 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
int actualX = i + x;
int actualY = j + y;
Block block;
if (!map->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!map->getBlock(actualX, actualY, &block) || !isSmartPathTile(selection.metatileItems, block.metatileId())) {
continue;
}
@ -251,20 +251,20 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
Block left;
// Get marching squares value, to determine which tile to use.
if (map->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
if (map->getBlock(actualX, actualY - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId()))
id += 1;
if (map->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
if (map->getBlock(actualX + 1, actualY, &right) && isSmartPathTile(selection.metatileItems, right.metatileId()))
id += 2;
if (map->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
if (map->getBlock(actualX, actualY + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId()))
id += 4;
if (map->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
if (map->getBlock(actualX - 1, actualY, &left) && isSmartPathTile(selection.metatileItems, left.metatileId()))
id += 8;
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
block.setMetatileId(selection.metatileItems.at(smartPathTable[id]).metatileId);
if (setCollisions) {
CollisionSelectionItem collisionItem = selection.collisionItems.at(smartPathTable[id]);
block.collision = collisionItem.collision;
block.elevation = collisionItem.elevation;
block.setCollision(collisionItem.collision);
block.setElevation(collisionItem.elevation);
}
map->setBlock(actualX, actualY, block, !fromScriptCall);
}
@ -326,7 +326,7 @@ void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
selection.append(QPoint(pos.x(), pos.y()));
Block block;
if (map->getBlock(pos.x(), pos.y(), &block)) {
this->metatileSelector->selectFromMap(block.metatileId, block.collision, block.elevation);
this->metatileSelector->selectFromMap(block.metatileId(), block.collision(), block.elevation());
}
} else if (event->type() == QEvent::GraphicsSceneMouseMove) {
int x1 = selection_origin.x();
@ -349,12 +349,12 @@ void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
int y = point.y();
Block block;
if (map->getBlock(x, y, &block)) {
metatiles.append(block.metatileId);
metatiles.append(block.metatileId());
}
int blockIndex = y * map->getWidth() + x;
block = map->layout->blockdata.at(blockIndex);
auto collision = block.collision;
auto elevation = block.elevation;
auto collision = block.collision();
auto elevation = block.elevation();
collisions.append(QPair<uint16_t, uint16_t>(collision, elevation));
}
@ -371,7 +371,7 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
Block block;
MetatileSelection selection = this->metatileSelector->getMetatileSelection();
int metatileId = selection.metatileItems.first().metatileId;
if (selection.metatileItems.count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.metatileId != metatileId)) {
if (selection.metatileItems.count() > 1 || (map->getBlock(pos.x(), pos.y(), &block) && block.metatileId() != metatileId)) {
bool smartPathsEnabled = event->modifiers() & Qt::ShiftModifier;
if ((this->settings->smartPathsEnabled || smartPathsEnabled) && selection.dimensions.x() == 3 && selection.dimensions.y() == 3)
this->floodFillSmartPath(pos.x(), pos.y());
@ -413,17 +413,17 @@ void MapPixmapItem::magicFill(
bool fromScriptCall) {
Block block;
if (map->getBlock(initialX, initialY, &block)) {
if (selectedMetatiles.length() == 1 && selectedMetatiles.at(0).metatileId == block.metatileId) {
if (selectedMetatiles.length() == 1 && selectedMetatiles.at(0).metatileId == block.metatileId()) {
return;
}
Blockdata oldMetatiles = !fromScriptCall ? map->layout->blockdata : Blockdata();
bool setCollisions = selectedCollisions.length() == selectedMetatiles.length();
uint16_t metatileId = block.metatileId;
uint16_t metatileId = block.metatileId();
for (int y = 0; y < map->getHeight(); y++) {
for (int x = 0; x < map->getWidth(); x++) {
if (map->getBlock(x, y, &block) && block.metatileId == metatileId) {
if (map->getBlock(x, y, &block) && block.metatileId() == metatileId) {
int xDiff = x - initialX;
int yDiff = y - initialY;
int i = xDiff % selectionDimensions.x();
@ -432,11 +432,11 @@ void MapPixmapItem::magicFill(
if (j < 0) j = selectionDimensions.y() + j;
int index = j * selectionDimensions.x() + i;
if (selectedMetatiles.at(index).enabled) {
block.metatileId = selectedMetatiles.at(index).metatileId;
block.setMetatileId(selectedMetatiles.at(index).metatileId);
if (setCollisions) {
CollisionSelectionItem item = selectedCollisions.at(index);
block.collision = item.collision;
block.elevation = item.elevation;
block.setCollision(item.collision);
block.setElevation(item.elevation);
}
map->setBlock(x, y, block, !fromScriptCall);
}
@ -492,29 +492,29 @@ void MapPixmapItem::floodFill(
if (j < 0) j = selectionDimensions.y() + j;
int index = j * selectionDimensions.x() + i;
uint16_t metatileId = selectedMetatiles.at(index).metatileId;
uint16_t old_metatileId = block.metatileId;
uint16_t old_metatileId = block.metatileId();
if (selectedMetatiles.at(index).enabled && (selectedMetatiles.count() != 1 || old_metatileId != metatileId)) {
block.metatileId = metatileId;
block.setMetatileId(metatileId);
if (setCollisions) {
CollisionSelectionItem item = selectedCollisions.at(index);
block.collision = item.collision;
block.elevation = item.elevation;
block.setCollision(item.collision);
block.setElevation(item.elevation);
}
map->setBlock(x, y, block, !fromScriptCall);
}
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && block.metatileId == old_metatileId) {
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x + 1, y));
visited.insert(x + 1 + y * map->getWidth());
}
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && block.metatileId == old_metatileId) {
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x - 1, y));
visited.insert(x - 1 + y * map->getWidth());
}
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && block.metatileId == old_metatileId) {
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x, y + 1));
visited.insert(x + (y + 1) * map->getWidth());
}
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && block.metatileId == old_metatileId) {
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x, y - 1));
visited.insert(x + (y - 1) * map->getWidth());
}
@ -531,14 +531,14 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
return;
// Shift to the middle tile of the smart path selection.
uint16_t openTile = selection.metatileItems.at(4).metatileId;
uint16_t openTileCollision = 0;
uint16_t openTileElevation = 0;
uint16_t openMetatileId = selection.metatileItems.at(4).metatileId;
uint16_t openCollision = 0;
uint16_t openElevation = 0;
bool setCollisions = false;
if (selection.hasCollision && selection.collisionItems.length() == selection.metatileItems.length()) {
CollisionSelectionItem item = selection.collisionItems.at(4);
openTileCollision = item.collision;
openTileElevation = item.elevation;
openCollision = item.collision;
openElevation = item.elevation;
setCollisions = true;
}
@ -556,27 +556,27 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
continue;
}
uint16_t old_metatileId = block.metatileId;
if (old_metatileId == openTile) {
uint16_t old_metatileId = block.metatileId();
if (old_metatileId == openMetatileId) {
continue;
}
block.metatileId = openTile;
block.setMetatileId(openMetatileId);
if (setCollisions) {
block.collision = openTileCollision;
block.elevation = openTileElevation;
block.setCollision(openCollision);
block.setElevation(openElevation);
}
map->setBlock(x, y, block, !fromScriptCall);
if (map->getBlock(x + 1, y, &block) && block.metatileId == old_metatileId) {
if (map->getBlock(x + 1, y, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x + 1, y));
}
if (map->getBlock(x - 1, y, &block) && block.metatileId == old_metatileId) {
if (map->getBlock(x - 1, y, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x - 1, y));
}
if (map->getBlock(x, y + 1, &block) && block.metatileId == old_metatileId) {
if (map->getBlock(x, y + 1, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x, y + 1));
}
if (map->getBlock(x, y - 1, &block) && block.metatileId == old_metatileId) {
if (map->getBlock(x, y - 1, &block) && block.metatileId() == old_metatileId) {
todo.append(QPoint(x, y - 1));
}
}
@ -602,37 +602,37 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
Block left;
// Get marching squares value, to determine which tile to use.
if (map->getBlock(x, y - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId))
if (map->getBlock(x, y - 1, &top) && isSmartPathTile(selection.metatileItems, top.metatileId()))
id += 1;
if (map->getBlock(x + 1, y, &right) && isSmartPathTile(selection.metatileItems, right.metatileId))
if (map->getBlock(x + 1, y, &right) && isSmartPathTile(selection.metatileItems, right.metatileId()))
id += 2;
if (map->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId))
if (map->getBlock(x, y + 1, &bottom) && isSmartPathTile(selection.metatileItems, bottom.metatileId()))
id += 4;
if (map->getBlock(x - 1, y, &left) && isSmartPathTile(selection.metatileItems, left.metatileId))
if (map->getBlock(x - 1, y, &left) && isSmartPathTile(selection.metatileItems, left.metatileId()))
id += 8;
block.metatileId = selection.metatileItems.at(smartPathTable[id]).metatileId;
block.setMetatileId(selection.metatileItems.at(smartPathTable[id]).metatileId);
if (setCollisions) {
CollisionSelectionItem item = selection.collisionItems.at(smartPathTable[id]);
block.collision = item.collision;
block.elevation = item.elevation;
block.setCollision(item.collision);
block.setElevation(item.elevation);
}
map->setBlock(x, y, block, !fromScriptCall);
// Visit neighbors if they are smart-path tiles, and don't revisit any.
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x + 1 + y * map->getWidth()) && map->getBlock(x + 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId())) {
todo.append(QPoint(x + 1, y));
visited.insert(x + 1 + y * map->getWidth());
}
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x - 1 + y * map->getWidth()) && map->getBlock(x - 1, y, &block) && isSmartPathTile(selection.metatileItems, block.metatileId())) {
todo.append(QPoint(x - 1, y));
visited.insert(x - 1 + y * map->getWidth());
}
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x + (y + 1) * map->getWidth()) && map->getBlock(x, y + 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId())) {
todo.append(QPoint(x, y + 1));
visited.insert(x + (y + 1) * map->getWidth());
}
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId)) {
if (!visited.contains(x + (y - 1) * map->getWidth()) && map->getBlock(x, y - 1, &block) && isSmartPathTile(selection.metatileItems, block.metatileId())) {
todo.append(QPoint(x, y - 1));
visited.insert(x + (y - 1) * map->getWidth());
}
@ -647,7 +647,7 @@ void MapPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
Block block;
if (map->getBlock(pos.x(), pos.y(), &block)) {
this->metatileSelector->selectFromMap(block.metatileId, block.collision, block.elevation);
this->metatileSelector->selectFromMap(block.metatileId(), block.collision(), block.elevation());
}
}

View file

@ -1057,7 +1057,7 @@ void TilesetEditor::countMetatileUsage() {
// for each block in the layout, mark in the vector that it is used
for (int i = 0; i < layout->blockdata.length(); i++) {
uint16_t metatileId = layout->blockdata.at(i).metatileId;
uint16_t metatileId = layout->blockdata.at(i).metatileId();
if (metatileId < this->project->getNumMetatilesPrimary()) {
if (usesPrimary) metatileSelector->usedMetatiles[metatileId]++;
} else {
@ -1066,7 +1066,7 @@ void TilesetEditor::countMetatileUsage() {
}
for (int i = 0; i < layout->border.length(); i++) {
uint16_t metatileId = layout->border.at(i).metatileId;
uint16_t metatileId = layout->border.at(i).metatileId();
if (metatileId < this->project->getNumMetatilesPrimary()) {
if (usesPrimary) metatileSelector->usedMetatiles[metatileId]++;
} else {