Move map bounds checking to map.cpp
This commit is contained in:
parent
41b269f908
commit
9963e4c8aa
5 changed files with 10 additions and 12 deletions
|
@ -95,6 +95,7 @@ public:
|
|||
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true);
|
||||
void cacheBorder();
|
||||
bool hasUnsavedChanges();
|
||||
bool isWithinBounds(int x, int y);
|
||||
|
||||
// for memory management
|
||||
QVector<Event *> ownedEvents;
|
||||
|
|
|
@ -177,7 +177,6 @@ private:
|
|||
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
|
||||
QString getMetatileDisplayMessage(uint16_t metatileId);
|
||||
bool eventLimitReached(Map *, QString);
|
||||
bool isWithinMap(int x, int y);
|
||||
bool startDetachedProcess(const QString &command,
|
||||
const QString &workingDirectory = QString(),
|
||||
qint64 *pid = nullptr) const;
|
||||
|
|
|
@ -335,7 +335,7 @@ void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata)
|
|||
}
|
||||
|
||||
bool Map::getBlock(int x, int y, Block *out) {
|
||||
if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
|
||||
if (isWithinBounds(x, y)) {
|
||||
int i = y * getWidth() + x;
|
||||
*out = layout->blockdata.value(i);
|
||||
return true;
|
||||
|
@ -470,3 +470,7 @@ void Map::addEvent(Event *event) {
|
|||
bool Map::hasUnsavedChanges() {
|
||||
return !editHistory.isClean() || hasUnsavedDataChanges || !isPersistedToFile;
|
||||
}
|
||||
|
||||
bool Map::isWithinBounds(int x, int y) {
|
||||
return (x >= 0 && x < this->getWidth() && y >= 0 && y < this->getHeight());
|
||||
}
|
||||
|
|
|
@ -1004,14 +1004,10 @@ void Editor::setCursorRectVisible(bool visible) {
|
|||
ui->graphicsView_Map->scene()->update();
|
||||
}
|
||||
|
||||
bool Editor::isWithinMap(int x, int y) {
|
||||
return (x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight());
|
||||
}
|
||||
|
||||
void Editor::onHoveredMapMetatileChanged(const QPoint &pos) {
|
||||
int x = pos.x();
|
||||
int y = pos.y();
|
||||
if (!this->isWithinMap(x, y))
|
||||
if (!map->isWithinBounds(x, y))
|
||||
return;
|
||||
|
||||
this->updateCursorRectPos(x, y);
|
||||
|
@ -1043,7 +1039,7 @@ void Editor::onHoveredMapMetatileCleared() {
|
|||
}
|
||||
|
||||
void Editor::onHoveredMapMovementPermissionChanged(int x, int y) {
|
||||
if (!this->isWithinMap(x, y))
|
||||
if (!map->isWithinBounds(x, y))
|
||||
return;
|
||||
|
||||
this->updateCursorRectPos(x, y);
|
||||
|
|
|
@ -191,8 +191,7 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
// Fill the region with the open tile.
|
||||
for (int i = 0; i <= 1; i++)
|
||||
for (int j = 0; j <= 1; j++) {
|
||||
// Check if in map bounds.
|
||||
if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0))
|
||||
if (!map->isWithinBounds(x + i, y + j))
|
||||
continue;
|
||||
int actualX = i + x;
|
||||
int actualY = j + y;
|
||||
|
@ -210,8 +209,7 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
|
|||
// Go back and resolve the edge tiles
|
||||
for (int i = -1; i <= 2; i++)
|
||||
for (int j = -1; j <= 2; j++) {
|
||||
// Check if in map bounds.
|
||||
if (!(i + x < map->getWidth() && i + x >= 0 && j + y < map->getHeight() && j + y >= 0))
|
||||
if (!map->isWithinBounds(x + i, y + j))
|
||||
continue;
|
||||
// Ignore the corners, which can't possible be affected by the smart path.
|
||||
if ((i == -1 && j == -1) || (i == 2 && j == -1) ||
|
||||
|
|
Loading…
Reference in a new issue