Added ShiftPosition Action and Layer.getLength.

This commit is contained in:
photonstorm 2017-06-16 19:26:26 +01:00
parent 730c6b5cbf
commit a7f46a7777
4 changed files with 102 additions and 1 deletions

View file

@ -0,0 +1,88 @@
// Iterate through items changing the position of each element to
// be that of the element that came before it in the array (or after it if direction = 1)
// The first items position is set to x/y.
var ShiftPosition = function (items, x, y, direction)
{
if (direction === undefined) { direction = 0; }
if (items.length > 1)
{
var i;
var cx;
var cy;
var px;
var py;
var cur;
if (direction === 0)
{
// Bottom to Top
var len = items.length - 1;
px = items[len].x;
py = items[len].y;
for (i = len - 1; i >= 0; i--)
{
// Current item
cur = items[i];
// Get current item x/y, to be passed to the next item in the list
cx = cur.x;
cy = cur.y;
// Set current item to the previous items x/y
cur.x = px;
cur.y = py;
// Set current as previous
px = cx;
py = cy;
}
// Update the head item to the new x/y coordinates
items[len].x = x;
items[len].y = y;
}
else
{
// Top to Bottom
px = items[0].x;
py = items[0].y;
for (i = 1; i < items.length; i++)
{
// Current item
cur = items[i];
// Get current item x/y, to be passed to the next item in the list
cx = cur.x;
cy = cur.y;
// Set current item to the previous items x/y
cur.x = px;
cur.y = py;
// Set current as previous
px = cx;
py = cy;
}
// Update the head item to the new x/y coordinates
items[0].x = x;
items[0].y = y;
}
}
else
{
items[0].x = x;
items[0].y = y;
}
return items;
};
module.exports = ShiftPosition;

View file

@ -35,6 +35,7 @@ module.exports = {
SetX: require('./SetX'),
SetXY: require('./SetXY'),
SetY: require('./SetY'),
ShiftPosition: require('./ShiftPosition'),
SmootherStep: require('./SmootherStep'),
SmoothStep: require('./SmoothStep'),
Spread: require('./Spread'),

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '531e9860-521e-11e7-914d-2dba089add27'
build: '8abd9c10-52c0-11e7-b265-8776d98a5edd'
};
module.exports = CHECKSUM;

View file

@ -170,6 +170,11 @@ var Layer = new Class({
return this.children.entries;
},
getLength: function ()
{
return this.children.size;
},
destroy: function ()
{
this.children.clear();
@ -404,6 +409,13 @@ var Layer = new Class({
return this;
},
shiftPosition: function (x, y, direction)
{
Actions.ShiftPosition(this.children.entries, x, y, direction);
return this;
},
smootherStep: function (property, min, max, inc)
{
Actions.SmootherStep(this.children.entries, property, min, max, inc);