Skip to content

Commit

Permalink
Add getBounds
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Nov 30, 2024
1 parent c1774c4 commit 3742e63
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/board-miniboard/get-bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Demo extends Phaser.Scene {
line = map[i].split('');
for (var j = 0, jcnt = line.length; j < jcnt; j++) {
if (line[j] !== ' ') {
this.rexBoard.add.shape(miniBoard, j - 1, i - 1, 0, Random(0, 0xffffff));
this.rexBoard.add.shape(miniBoard, j - 1, i - 1, 0, 0x669966).setStrokeStyle(2, 0xffffff);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions plugins/board/board/boarddata/BoardData.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ class BoardData {
return this;
}

getBounds() {
var xMin = Infinity,
xMax = -Infinity,
yMin = Infinity,
yMax = -Infinity;

var UIDToXYZ = this.UIDToXYZ,
x, y;
for (var uid in UIDToXYZ) {
x = UIDToXYZ[uid].x;
if (xMin > x) { xMin = x; }
if (xMax < x) { xMax = x; }
if (yMin > x) { yMin = x; }
if (yMax < x) { yMax = x; }
}

return {
left: xMin, right: xMax,
top: yMin, bottom: yMax
}
}

addUID(uid, x, y, z) {
if (!this.XYZToUID.hasOwnProperty(x)) {
this.XYZToUID[x] = {};
Expand Down
9 changes: 5 additions & 4 deletions plugins/board/board/tileposition/ForEachTileXY.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ var ForEachTileXY = function (callback, scope, config) {

var top, bottom, left, right;
if (this.infinityMode && (this.width === undefined)) {
left = this.boardData.xMin;
right = this.boardData.xMax;
top = this.boardData.yMin;
bottom = this.boardData.yMax;
var bounds = this.boardData.getBounds();
left = bounds.left;
right = bounds.right;
top = bounds.top;
bottom = bounds.bottom;
} else {
var lastX = this.width - 1,
lastY = this.height - 1;
Expand Down

0 comments on commit 3742e63

Please sign in to comment.