(items, options)
| 38 | * @return {(array|Phaser.GameObjects.GameObject[])} The array of objects that were passed to this Action. |
| 39 | */ |
| 40 | var GridAlign = function (items, options) |
| 41 | { |
| 42 | if (options === undefined) { options = {}; } |
| 43 | |
| 44 | var widthSet = options.hasOwnProperty('width'); |
| 45 | var heightSet = options.hasOwnProperty('height'); |
| 46 | |
| 47 | var width = GetFastValue(options, 'width', -1); |
| 48 | var height = GetFastValue(options, 'height', -1); |
| 49 | |
| 50 | var cellWidth = GetFastValue(options, 'cellWidth', 1); |
| 51 | var cellHeight = GetFastValue(options, 'cellHeight', cellWidth); |
| 52 | |
| 53 | var position = GetFastValue(options, 'position', CONST.TOP_LEFT); |
| 54 | var x = GetFastValue(options, 'x', 0); |
| 55 | var y = GetFastValue(options, 'y', 0); |
| 56 | |
| 57 | var cx = 0; |
| 58 | var cy = 0; |
| 59 | var w = (width * cellWidth); |
| 60 | var h = (height * cellHeight); |
| 61 | |
| 62 | tempZone.setPosition(x, y); |
| 63 | tempZone.setSize(cellWidth, cellHeight); |
| 64 | |
| 65 | for (var i = 0; i < items.length; i++) |
| 66 | { |
| 67 | AlignIn(items[i], tempZone, position); |
| 68 | |
| 69 | if (widthSet && width === -1) |
| 70 | { |
| 71 | // We keep laying them out horizontally until we've done them all |
| 72 | tempZone.x += cellWidth; |
| 73 | } |
| 74 | else if (heightSet && height === -1) |
| 75 | { |
| 76 | // We keep laying them out vertically until we've done them all |
| 77 | tempZone.y += cellHeight; |
| 78 | } |
| 79 | else if (heightSet && !widthSet) |
| 80 | { |
| 81 | // We keep laying them out until we hit the column limit |
| 82 | cy += cellHeight; |
| 83 | tempZone.y += cellHeight; |
| 84 | |
| 85 | if (cy === h) |
| 86 | { |
| 87 | cy = 0; |
| 88 | cx += cellWidth; |
| 89 | tempZone.y = y; |
| 90 | tempZone.x += cellWidth; |
| 91 | |
| 92 | if (cx === w) |
| 93 | { |
| 94 | // We've hit the column limit, so return, even if there are items left |
| 95 | break; |
| 96 | } |
| 97 | } |
no test coverage detected
searching dependent graphs…