Skip to content

Commit 389669e

Browse files
committed
Updated jsdocs
1 parent ccbf399 commit 389669e

3 files changed

Lines changed: 46 additions & 38 deletions

File tree

src/actions/Call.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
*/
66

77
/**
8-
* [description]
8+
* Takes an array of objects and passes each of them to the given callback.
99
*
1010
* @function Phaser.Actions.Call
1111
* @since 3.0.0
1212
*
13-
* @param {array} items - An array of Game Objects. The contents of this array are updated by this Action.
14-
* @param {function} callback - [description]
15-
* @param {object} thisArg - [description]
13+
* @param {array|Phaser.GameObjects.GameObject[]} items - The array of items to be updated by this action.
14+
* @param {function} callback - The callback to be invoked. It will be passed just one argument: the item from the array.
15+
* @param {object} context - The scope in which the callback will be invoked.
1616
*
17-
* @return {array} The array of Game Objects that was passed to this Action.
17+
* @return {array} The array of objects that was passed to this Action.
1818
*/
19-
var Call = function (items, callback, thisArg)
19+
var Call = function (items, callback, context)
2020
{
2121
for (var i = 0; i < items.length; i++)
2222
{
2323
var item = items[i];
2424

25-
callback.call(thisArg, item);
25+
callback.call(context, item);
2626
}
2727

2828
return items;

src/actions/GetFirst.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7-
// compare = Object:
8-
// {
9-
// scaleX: 0.5,
10-
// scaleY: 1
11-
// }
12-
137
/**
14-
* [description]
8+
* Takes an array of objects and returns the first element in the array that has properties which match
9+
* all of those specified in the `compare` object. For example, if the compare object was: `{ scaleX: 0.5, alpha: 1 }`
10+
* then it would return the first item which had the property `scaleX` set to 0.5 and `alpha` set to 1.
11+
*
12+
* To use this with a Group: `GetFirst(group.getChildren(), compare, index)`
1513
*
1614
* @function Phaser.Actions.GetFirst
1715
* @since 3.0.0
1816
*
19-
* @param {array} items - An array of Game Objects. The contents of this array are updated by this Action.
20-
* @param {object} compare - [description]
21-
* @param {integer} index - [description]
17+
* @param {array|Phaser.GameObjects.GameObject[]} items - The array of items to be searched by this action.
18+
* @param {object} compare - The comparison object. Each property in this object will be checked against the items of the array.
19+
* @param {integer} [index=0] - An optional offset to start searching from within the items array.
2220
*
23-
* @return {array} The array of Game Objects that was passed to this Action.
21+
* @return {object} The first object in the array that matches the comparison object, or `null` if no match was found.
2422
*/
2523
var GetFirst = function (items, compare, index)
2624
{
25+
if (index === undefined) { index = 0; }
26+
2727
for (var i = index; i < items.length; i++)
2828
{
2929
var item = items[i];

src/actions/GridAlign.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,55 @@
66

77
var AlignIn = require('../display/align/in/QuickSet');
88
var CONST = require('../display/align/const');
9-
var GetValue = require('../utils/object/GetValue');
9+
var GetFastValue = require('../utils/object/GetFastValue');
1010
var NOOP = require('../utils/NOOP');
1111
var Zone = require('../gameobjects/zone/Zone');
1212

1313
var tempZone = new Zone({ sys: { queueDepthSort: NOOP }}, 0, 0, 1, 1);
1414

1515
/**
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.
1732
*
1833
* @function Phaser.Actions.GridAlign
1934
* @since 3.0.0
2035
*
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.
2338
*
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.
2540
*/
2641
var GridAlign = function (items, options)
2742
{
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 = {}; }
3544

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);
3852

3953
var cx = 0;
4054
var cy = 0;
4155
var w = (width * cellWidth);
4256
var h = (height * cellHeight);
4357

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-
5058
tempZone.setPosition(x, y);
5159
tempZone.setSize(cellWidth, cellHeight);
5260

0 commit comments

Comments
 (0)