2017-03-22 23:16:44 +00:00
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
|
|
|
|
var Layer = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
function Layer ()
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
|
|
|
this.children = [];
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
Array.prototype.push.apply(this.children, arguments);
|
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
add: function (child)
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
|
|
|
var children = this.children;
|
|
|
|
var index = children.indexOf(child);
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
children.push(child);
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addArray: function (childrenArray)
|
|
|
|
{
|
|
|
|
var length = childrenArray.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
this.add(childrenArray[index]);
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
addX: function (value)
|
|
|
|
{
|
2017-03-22 23:16:44 +00:00
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].x += value;
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
addY: function (value)
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].y += value;
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
addPosition: function (x, y)
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].x += x;
|
|
|
|
children[index].y += y;
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
rotate: function (value)
|
|
|
|
{
|
2017-03-22 23:16:44 +00:00
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].rotation += value;
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
setX: function (value)
|
|
|
|
{
|
2017-03-22 23:16:44 +00:00
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].x = value;
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
setY: function (value)
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].y = value;
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
setRotation: function (value)
|
|
|
|
{
|
2017-03-22 23:16:44 +00:00
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].rotation = value;
|
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
setVisible: function (value)
|
|
|
|
{
|
2017-03-22 23:16:44 +00:00
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].visible = value;
|
2017-03-23 00:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleVisible: function ()
|
|
|
|
{
|
|
|
|
var children = this.children;
|
|
|
|
var length = children.length;
|
2017-03-23 00:07:41 +00:00
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
children[index].visible = !children[index].visible;
|
2017-03-23 00:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
module.exports = Layer;
|