Skip to content

Commit 7f72c7b

Browse files
committed
GridAlign now takes a config object, and works with optional x/y settings too.
1 parent 2cfa57e commit 7f72c7b

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

v3/src/actions/GridAlign.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var CONST = require('../utils/align/const');
22
var AlignIn = require('../utils/align/AlignIn');
33
var Zone = require('../gameobjects/zone/Zone');
4+
var GetObjectValue = require('../utils/object/GetObjectValue');
45

56
var tempZone = new Zone({}, 0, 0, 1, 1);
67

@@ -55,13 +56,21 @@ var tempZone = new Zone({}, 0, 0, 1, 1);
5556
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
5657
* @return {boolean} True if the Group children were aligned, otherwise false.
5758
*/
58-
var GridAlign = function (items, width, height, cellWidth, cellHeight, position)
59+
var GridAlign = function (items, options)
5960
{
60-
if (position === undefined) { position = CONST.TOP_LEFT; }
61+
var width = GetObjectValue(options, 'width', -1);
62+
var height = GetObjectValue(options, 'height', -1);
63+
var cellWidth = GetObjectValue(options, 'cellWidth', 1);
64+
var cellHeight = GetObjectValue(options, 'cellHeight', cellWidth);
65+
var position = GetObjectValue(options, 'position', CONST.TOP_LEFT);
66+
var x = GetObjectValue(options, 'x', 0);
67+
var y = GetObjectValue(options, 'y', 0);
6168

62-
tempZone.setPosition(0, 0);
69+
tempZone.setPosition(x, y);
6370
tempZone.setSize(cellWidth, cellHeight);
6471

72+
var cx = 0;
73+
var cy = 0;
6574
var w = (width * cellWidth);
6675
var h = (height * cellHeight);
6776

@@ -72,36 +81,43 @@ var GridAlign = function (items, width, height, cellWidth, cellHeight, position)
7281
if (width === -1)
7382
{
7483
// We keep laying them out horizontally until we've done them all
84+
cy += cellHeight;
7585
tempZone.y += cellHeight;
7686

77-
if (tempZone.y === h)
87+
if (cy === h)
7888
{
89+
cy = 0;
7990
tempZone.x += cellWidth;
80-
tempZone.y = 0;
91+
tempZone.y = y;
8192
}
8293
}
8394
else if (height === -1)
8495
{
8596
// We keep laying them out vertically until we've done them all
97+
cx += cellWidth;
8698
tempZone.x += cellWidth;
8799

88-
if (tempZone.x === w)
100+
if (cx === w)
89101
{
90-
tempZone.x = 0;
102+
cx = 0;
103+
tempZone.x = x;
91104
tempZone.y += cellHeight;
92105
}
93106
}
94107
else
95108
{
96109
// We keep laying them out until we hit the column limit
110+
cx += cellWidth;
97111
tempZone.x += cellWidth;
98112

99-
if (tempZone.x === w)
113+
if (cx === w)
100114
{
101-
tempZone.x = 0;
115+
cx = 0;
116+
cy += cellHeight;
117+
tempZone.x = x;
102118
tempZone.y += cellHeight;
103119

104-
if (tempZone.y === h)
120+
if (cy === h)
105121
{
106122
// We've hit the column limit, so return, even if there are items left
107123
break;

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '448d6cb0-1414-11e7-9400-83d0899b34cd'
2+
build: '5d589820-1417-11e7-a4fb-712e101ac5d8'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/layer/Layer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var Layer = new Class({
8686
var randomKey = GetObjectValue(options, 'randomKey', false);
8787
var randomFrame = GetObjectValue(options, 'randomFrame', false);
8888
var yoyo = GetObjectValue(options, 'yoyo', false);
89-
var quantity = GetObjectValue(options, 'quantity', 1);
89+
var quantity = GetObjectValue(options, 'frameQuantity', 1);
9090
var max = GetObjectValue(options, 'max', 0);
9191

9292
var range = Range(key, frame, {
@@ -182,9 +182,9 @@ var Layer = new Class({
182182
return this;
183183
},
184184

185-
gridAlign: function (width, height, cellWidth, cellHeight, position)
185+
gridAlign: function (options)
186186
{
187-
Actions.GridAlign(this.children.entries, width, height, cellWidth, cellHeight, position);
187+
Actions.GridAlign(this.children.entries, options);
188188

189189
return this;
190190
},

0 commit comments

Comments
 (0)