2017-03-22 23:16:44 +00:00
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
2017-03-27 15:59:51 +00:00
|
|
|
var Set = require('../../structs/Set');
|
2017-03-27 23:05:08 +00:00
|
|
|
var Actions = require('./actions/');
|
2017-03-22 23:16:44 +00:00
|
|
|
|
|
|
|
var Layer = new Class({
|
|
|
|
|
2017-03-27 23:05:08 +00:00
|
|
|
Mixins: [
|
|
|
|
Actions.IncX,
|
|
|
|
Actions.IncY,
|
|
|
|
Actions.IncXY,
|
|
|
|
Actions.SetX,
|
|
|
|
Actions.SetY,
|
|
|
|
Actions.SetXY,
|
|
|
|
Actions.Rotate,
|
|
|
|
Actions.Angle,
|
|
|
|
Actions.SetRotation,
|
|
|
|
Actions.SetVisible,
|
|
|
|
Actions.ToggleVisible,
|
|
|
|
Actions.Align
|
|
|
|
],
|
|
|
|
|
2017-03-22 23:16:44 +00:00
|
|
|
initialize:
|
|
|
|
|
2017-03-27 23:05:08 +00:00
|
|
|
function Layer (state, children)
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
2017-03-27 23:05:08 +00:00
|
|
|
this.state = state;
|
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
this.children = new Set(children);
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
// Layer management methods:
|
2017-03-22 23:16:44 +00:00
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
add: function (child)
|
2017-03-23 00:07:41 +00:00
|
|
|
{
|
2017-03-27 15:59:51 +00:00
|
|
|
this.children.set(child);
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
addMultiple: function (children)
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
2017-03-27 15:59:51 +00:00
|
|
|
if (Array.isArray(children))
|
2017-03-22 23:16:44 +00:00
|
|
|
{
|
2017-03-27 15:59:51 +00:00
|
|
|
for (var i = 0; i < children.length; i++)
|
|
|
|
{
|
|
|
|
this.children.set(children[i]);
|
|
|
|
}
|
2017-03-22 23:16:44 +00:00
|
|
|
}
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
remove: function (child)
|
2017-03-23 00:07:41 +00:00
|
|
|
{
|
2017-03-27 15:59:51 +00:00
|
|
|
this.children.delete(child);
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-27 15:59:51 +00:00
|
|
|
clear: function ()
|
2017-03-23 00:07:41 +00:00
|
|
|
{
|
2017-03-27 15:59:51 +00:00
|
|
|
this.children.clear();
|
2017-03-23 00:07:41 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-22 23:16:44 +00:00
|
|
|
},
|
|
|
|
|
2017-03-27 23:05:08 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.children.clear();
|
2017-03-22 23:16:44 +00:00
|
|
|
|
2017-03-27 23:05:08 +00:00
|
|
|
this.state = undefined;
|
|
|
|
this.children = undefined;
|
|
|
|
}
|
2017-03-22 23:16:44 +00:00
|
|
|
});
|
|
|
|
|
2017-03-23 00:07:41 +00:00
|
|
|
module.exports = Layer;
|