-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpickables.js
50 lines (38 loc) · 1.39 KB
/
pickables.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
pc.script.create('pickables', function (context) {
var Pickables = function (entity) {
this.entity = entity;
};
Pickables.prototype = {
initialize: function () {
this.templates = context.root.findByName('pickables-templates');
this.templates.enabled = false;
this.pickables = context.root.findByName('pickables');
this.pick = { };
var children = this.templates.getChildren();
for(var i = 0; i < children.length; i++) {
var name = children[i].name.slice(9);
this.pick[name] = children[i];
}
},
new: function(data) {
var tpl = this.pick[data.t] || this.pick['default'];
if (! tpl)
return;
var item = tpl.clone();
item.name = 'pickable_' + data.id;
item.type = data.t;
item.enabled = true;
item.setPosition(data.x, 0, data.y);
this.pickables.addChild(item);
},
delete: function(data) {
var item = this.pickables.findByName('pickable_' + data.id);
if (! item)
return;
item.destroy();
},
update: function (dt) {
}
};
return Pickables;
});