var AlignIn = require('../display/align/in/QuickSet'); var CONST = require('../display/align/const'); var GetValue = require('../utils/object/GetValue'); var NOOP = require('../utils/NOOP'); var Zone = require('../gameobjects/zone/Zone'); var tempZone = new Zone({ sys: { queueDepthSort: NOOP} } , 0, 0, 1, 1); var GridAlign = function (items, options){ var width = GetValue(options, 'width', -1); var height = GetValue(options, 'height', -1); var cellWidth = GetValue(options, 'cellWidth', 1); var cellHeight = GetValue(options, 'cellHeight', cellWidth); var position = GetValue(options, 'position', CONST.TOP_LEFT); var x = GetValue(options, 'x', 0); var y = GetValue(options, 'y', 0); var cx = 0; var cy = 0; var w = (width * cellWidth); var h = (height * cellHeight); tempZone.setPosition(x, y); tempZone.setSize(cellWidth, cellHeight); for (var i = 0; i < _AN_Read_length('length', items); i++ ){ AlignIn(items[i], tempZone, position); if (width === -1) { cy += cellHeight; tempZone.y += cellHeight; if (cy === h) { cy = 0; tempZone.x += cellWidth; tempZone.y = y; } } else if (height === -1) { cx += cellWidth; tempZone.x += cellWidth; if (cx === w) { cx = 0; tempZone.x = x; tempZone.y += cellHeight; } } else { cx += cellWidth; tempZone.x += cellWidth; if (cx === w) { cx = 0; cy += cellHeight; tempZone.x = x; tempZone.y += cellHeight; if (cy === h) { break ; } } } } return items; } ; module.exports = GridAlign;