Skip to content

Commit 279f01e

Browse files
StephenCWillsAJenbo
authored andcommittedApr 29, 2024
Fix edge case that causes infinite loop
1 parent c9a0101 commit 279f01e

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed
 

‎Tiled/extensions/diablo-dun.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ function findTransPolygon(trans, start) {
585585
}
586586

587587
var cornerShapes = [0x1, 0x2, 0x4, 0x6, 0x7, 0x8, 0x9, 0xB, 0xD, 0xE];
588-
var leftShapes = [0x8, 0x9, 0xC, 0xD, 0xF];
589-
var upShapes = [0x4, 0x5, 0x6, 0x7, 0xF];
590-
var rightShapes = [0x1, 0x3, 0x9, 0xB, 0xF];
591-
var downShapes = [0x2, 0x6, 0xA, 0xE, 0xF];
588+
var leftShapes = [0x8, 0xC, 0xD];
589+
var upShapes = [0x4, 0x5, 0x7];
590+
var rightShapes = [0x1, 0x3, 0xB];
591+
var downShapes = [0x2, 0xA, 0xE];
592592

593593
var points = [];
594594
while (points.length === 0 || points[0].x !== x || points[0].y !== y) {
@@ -597,14 +597,25 @@ function findTransPolygon(trans, start) {
597597
if (cornerShapes.includes(shape))
598598
points.push(Qt.point(x, y));
599599

600-
if (direction !== right && leftShapes.includes(shape))
600+
// Movements are determined by traversing the polygon clockwise
601+
if (leftShapes.includes(shape))
601602
goLeft();
602-
else if (direction !== down && upShapes.includes(shape))
603+
else if (upShapes.includes(shape))
603604
goUp();
604-
else if (direction !== left && rightShapes.includes(shape))
605+
else if (rightShapes.includes(shape))
605606
goRight();
606-
else if (direction !== up && downShapes.includes(shape))
607+
else if (downShapes.includes(shape))
607608
goDown();
609+
else if (direction === left && shape === 0x6)
610+
goUp();
611+
else if (direction === up && shape === 0x9)
612+
goRight();
613+
else if (direction === right && shape === 0x6)
614+
goDown();
615+
else if (direction === down && shape === 0x9)
616+
goLeft();
617+
else
618+
goRight();
608619
}
609620
points.push(Qt.point(x, y));
610621

0 commit comments

Comments
 (0)
Please sign in to comment.