|
6 | 6 |
|
7 | 7 | var AlignIn = require('../display/align/in/QuickSet'); |
8 | 8 | var CONST = require('../display/align/const'); |
9 | | -var GetValue = require('../utils/object/GetValue'); |
| 9 | +var GetFastValue = require('../utils/object/GetFastValue'); |
10 | 10 | var NOOP = require('../utils/NOOP'); |
11 | 11 | var Zone = require('../gameobjects/zone/Zone'); |
12 | 12 |
|
13 | 13 | var tempZone = new Zone({ sys: { queueDepthSort: NOOP }}, 0, 0, 1, 1); |
14 | 14 |
|
15 | 15 | /** |
16 | | - * [description] |
| 16 | + * @typedef {object} GridAlignConfig |
| 17 | + * |
| 18 | + * @property {integer} [width=-1] - The width of the grid in items (not pixels). -1 means lay all items out horizontally, regardless of quantity. |
| 19 | + * If both this value and height are set to -1 then this value overrides it and the `height` value is ignored. |
| 20 | + * @property {integer} [height=-1] - The height of the grid in items (not pixels). -1 means lay all items out vertically, regardless of quantity. |
| 21 | + * If both this value and `width` are set to -1 then `width` overrides it and this value is ignored. |
| 22 | + * @property {boolean} [cellWidth=1] - The width of the cell, in pixels, in which the item is positioned. |
| 23 | + * @property {integer} [cellHeight=1] - The height of the cell, in pixels, in which the item is positioned. |
| 24 | + * @property {integer} [position=0] - The alignment position. One of the Phaser.Display.Align consts such as `TOP_LEFT` or `RIGHT_CENTER`. |
| 25 | + * @property {number} [x=0] - Optionally place the top-left of the final grid at this coordinate. |
| 26 | + * @property {number} [y=0] - Optionally place the top-left of the final grid at this coordinate. |
| 27 | + */ |
| 28 | + |
| 29 | +/** |
| 30 | + * Takes an array of Game Objects, or any objects that have public `x` and `y` properties, |
| 31 | + * and then aligns them based on the grid configuration given to this action. |
17 | 32 | * |
18 | 33 | * @function Phaser.Actions.GridAlign |
19 | 34 | * @since 3.0.0 |
20 | 35 | * |
21 | | - * @param {array} items - An array of Game Objects. The contents of this array are updated by this Action. |
22 | | - * @param {object} options - [description] |
| 36 | + * @param {array|Phaser.GameObjects.GameObject[]} items - The array of items to be updated by this action. |
| 37 | + * @param {GridAlignConfig} options - The GridAlign Configuration object. |
23 | 38 | * |
24 | | - * @return {array} The array of Game Objects that was passed to this Action. |
| 39 | + * @return {array} The array of objects that were passed to this Action. |
25 | 40 | */ |
26 | 41 | var GridAlign = function (items, options) |
27 | 42 | { |
28 | | - var width = GetValue(options, 'width', -1); |
29 | | - var height = GetValue(options, 'height', -1); |
30 | | - var cellWidth = GetValue(options, 'cellWidth', 1); |
31 | | - var cellHeight = GetValue(options, 'cellHeight', cellWidth); |
32 | | - var position = GetValue(options, 'position', CONST.TOP_LEFT); |
33 | | - var x = GetValue(options, 'x', 0); |
34 | | - var y = GetValue(options, 'y', 0); |
| 43 | + if (options === undefined) { options = {}; } |
35 | 44 |
|
36 | | - // var centerX = GetValue(options, 'centerX', null); |
37 | | - // var centerY = GetValue(options, 'centerY', null); |
| 45 | + var width = GetFastValue(options, 'width', -1); |
| 46 | + var height = GetFastValue(options, 'height', -1); |
| 47 | + var cellWidth = GetFastValue(options, 'cellWidth', 1); |
| 48 | + var cellHeight = GetFastValue(options, 'cellHeight', cellWidth); |
| 49 | + var position = GetFastValue(options, 'position', CONST.TOP_LEFT); |
| 50 | + var x = GetFastValue(options, 'x', 0); |
| 51 | + var y = GetFastValue(options, 'y', 0); |
38 | 52 |
|
39 | 53 | var cx = 0; |
40 | 54 | var cy = 0; |
41 | 55 | var w = (width * cellWidth); |
42 | 56 | var h = (height * cellHeight); |
43 | 57 |
|
44 | | - // If the Grid is centered on a position then we need to calculate it now |
45 | | - // if (centerX !== null && centerY !== null) |
46 | | - // { |
47 | | - // |
48 | | - // } |
49 | | - |
50 | 58 | tempZone.setPosition(x, y); |
51 | 59 | tempZone.setSize(cellWidth, cellHeight); |
52 | 60 |
|
|
0 commit comments