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 &); Block &operator=(const Block &);
bool operator ==(Block) const; bool operator ==(Block) const;
bool operator !=(Block) const; bool operator !=(Block) const;
uint16_t metatileId:10; void setMetatileId(uint16_t metatileId) { m_metatileId = metatileId; }
uint16_t collision:2; void setCollision(uint16_t collision) { m_collision = collision; }
uint16_t elevation:4; 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; uint16_t rawValue() const;
private:
uint16_t m_metatileId; // 10
uint16_t m_collision; // 2
uint16_t m_elevation; // 4
}; };
#endif // BLOCK_H #endif // BLOCK_H

View file

@ -1,41 +1,45 @@
#include "block.h" #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) : Block::Block(uint16_t metatileId, uint16_t collision, uint16_t elevation) :
metatileId(metatileId), m_metatileId(metatileId),
collision(collision), m_collision(collision),
elevation(elevation) m_elevation(elevation)
{ } { }
Block::Block(uint16_t word) : Block::Block(uint16_t word) :
metatileId(word & 0x3ff), m_metatileId(word & 0x3ff),
collision((word >> 10) & 0x3), m_collision((word >> 10) & 0x3),
elevation((word >> 12) & 0xf) m_elevation((word >> 12) & 0xf)
{ } { }
Block::Block(const Block &other) : Block::Block(const Block &other) :
metatileId(other.metatileId), m_metatileId(other.m_metatileId),
collision(other.collision), m_collision(other.m_collision),
elevation(other.elevation) m_elevation(other.m_elevation)
{ } { }
Block &Block::operator=(const Block &other) { Block &Block::operator=(const Block &other) {
metatileId = other.metatileId; m_metatileId = other.m_metatileId;
collision = other.collision; m_collision = other.m_collision;
elevation = other.elevation; m_elevation = other.m_elevation;
return *this; return *this;
} }
uint16_t Block::rawValue() const { uint16_t Block::rawValue() const {
return static_cast<uint16_t>( return static_cast<uint16_t>(
(metatileId & 0x3ff) + (m_metatileId & 0x3ff) +
((collision & 0x3) << 10) + ((m_collision & 0x3) << 10) +
((elevation & 0xf) << 12)); ((m_elevation & 0xf) << 12));
} }
bool Block::operator ==(Block other) const { 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 { 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); QPoint metatile_origin = QPoint(map_x * 16, map_y * 16);
Block block = layout->blockdata.at(i); Block block = layout->blockdata.at(i);
QImage metatile_image = getMetatileImage( QImage metatile_image = getMetatileImage(
block.metatileId, block.metatileId(),
fromLayout ? fromLayout->tileset_primary : layout->tileset_primary, fromLayout ? fromLayout->tileset_primary : layout->tileset_primary,
fromLayout ? fromLayout->tileset_secondary : layout->tileset_secondary, fromLayout ? fromLayout->tileset_secondary : layout->tileset_secondary,
metatileLayerOrder, metatileLayerOrder,
@ -201,7 +201,7 @@ QPixmap Map::renderBorder(bool ignoreCache) {
changed_any = true; changed_any = true;
Block block = layout->border.at(i); 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); QImage metatile_image = getMetatileImage(metatileId, layout->tileset_primary, layout->tileset_secondary, metatileLayerOrder, metatileLayerOpacity);
int map_y = width_ ? i / width_ : 0; int map_y = width_ ? i / width_ : 0;
int map_x = 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) { uint16_t Map::getBorderMetatileId(int x, int y) {
int i = y * getBorderWidth() + x; 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) { void Map::setBorderMetatileId(int x, int y, uint16_t metatileId, bool enableScriptCallback) {
int i = y * getBorderWidth() + x; int i = y * getBorderWidth() + x;
if (i < layout->border.size()) { if (i < layout->border.size()) {
uint16_t prevMetatileId = layout->border[i].metatileId; uint16_t prevMetatileId = layout->border[i].metatileId();
layout->border[i].metatileId = metatileId; layout->border[i].setMetatileId(metatileId);
if (prevMetatileId != metatileId && enableScriptCallback) { if (prevMetatileId != metatileId && enableScriptCallback) {
Scripting::cb_BorderMetatileChanged(x, y, prevMetatileId, metatileId); Scripting::cb_BorderMetatileChanged(x, y, prevMetatileId, metatileId);
} }
@ -387,7 +387,7 @@ void Map::setBorderBlockData(Blockdata blockdata, bool enableScriptCallback) {
if (prevBlock != newBlock) { if (prevBlock != newBlock) {
layout->border.replace(i, newBlock); layout->border.replace(i, newBlock);
if (enableScriptCallback) 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; continue;
} }
uint old_coll = block.collision; uint old_coll = block.collision();
uint old_elev = block.elevation; uint old_elev = block.elevation();
if (old_coll == collision && old_elev == elevation) { if (old_coll == collision && old_elev == elevation) {
continue; continue;
} }
block.collision = collision; block.setCollision(collision);
block.elevation = elevation; block.setElevation(elevation);
setBlock(x, y, block, true); 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)); 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)); 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)); 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)); 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) { void Map::floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation) {
Block block; 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); _floodFillCollisionElevation(x, y, collision, elevation);
} }
} }
void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t collision, uint16_t elevation) { void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t collision, uint16_t elevation) {
Block block; Block block;
if (getBlock(initialX, initialY, &block) && (block.collision != collision || block.elevation != elevation)) { if (getBlock(initialX, initialY, &block) && (block.collision() != collision || block.elevation() != elevation)) {
uint old_coll = block.collision; uint old_coll = block.collision();
uint old_elev = block.elevation; uint old_elev = block.elevation();
for (int y = 0; y < getHeight(); y++) { for (int y = 0; y < getHeight(); y++) {
for (int x = 0; x < getWidth(); x++) { for (int x = 0; x < getWidth(); x++) {
if (getBlock(x, y, &block) && block.collision == old_coll && block.elevation == old_elev) { if (getBlock(x, y, &block) && block.collision() == old_coll && block.elevation() == old_elev) {
block.collision = collision; block.setCollision(collision);
block.elevation = elevation; block.setElevation(elevation);
setBlock(x, y, block, true); setBlock(x, y, block, true);
} }
} }

View file

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

View file

@ -99,7 +99,7 @@ int MainWindow::getMetatileId(int x, int y) {
if (!this->editor->map->getBlock(x, y, &block)) { if (!this->editor->map->getBlock(x, y, &block)) {
return 0; return 0;
} }
return block.metatileId; return block.metatileId();
} }
void MainWindow::setMetatileId(int x, int y, int metatileId, bool forceRedraw, bool commitChanges) { 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)) { if (!this->editor->map->getBlock(x, y, &block)) {
return; 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->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw); this->tryRedrawMapArea(forceRedraw);
} }
@ -121,7 +121,7 @@ int MainWindow::getCollision(int x, int y) {
if (!this->editor->map->getBlock(x, y, &block)) { if (!this->editor->map->getBlock(x, y, &block)) {
return 0; return 0;
} }
return block.collision; return block.collision();
} }
void MainWindow::setCollision(int x, int y, int collision, bool forceRedraw, bool commitChanges) { 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)) { if (!this->editor->map->getBlock(x, y, &block)) {
return; 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->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw); this->tryRedrawMapArea(forceRedraw);
} }
@ -143,7 +143,7 @@ int MainWindow::getElevation(int x, int y) {
if (!this->editor->map->getBlock(x, y, &block)) { if (!this->editor->map->getBlock(x, y, &block)) {
return 0; return 0;
} }
return block.elevation; return block.elevation();
} }
void MainWindow::setElevation(int x, int y, int elevation, bool forceRedraw, bool commitChanges) { 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)) { if (!this->editor->map->getBlock(x, y, &block)) {
return; 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->tryCommitMapChanges(commitChanges);
this->tryRedrawMapArea(forceRedraw); this->tryRedrawMapArea(forceRedraw);
} }

View file

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

View file

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

View file

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