-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity-generator.js
29 lines (27 loc) · 1.26 KB
/
entity-generator.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
/* entity-generator aframe component by diekus */
/* ATTENTION:
The 'attributes' attribute of the entity-genertator uses a different type of delimiters since it is an CSS-like string notation inside CSS-like string notation. In order to be able to set attributes it uses '&' and '='. An 'attributes' subattribute looks like attributes:attribute1=value1&attribute2=value2
*/
AFRAME.registerComponent('entity-generator', {
schema: {
entity_name:{type: 'string', default: 'a-entity'},
attributes:{type:'string', default:''},
number_items:{type:'int', default:2},
id_generation:{type:'bool', default:false},
id_prefix:{type:'string', default:'gen_ent_'}
},
init: function(){
for (i = 0; i < this.data.number_items; i++){
let ne = document.createElement(this.data.entity_name);
atts = this.data.attributes.split('&');
for(a = 0; a < atts.length; a++){
att = atts[a].split('=');
att[1] != null?ne.setAttribute(att[0], att[1]):ne.setAttribute(att[0], '');
}
if(this.data.id_generation){
ne.setAttribute('id', this.data.id_prefix + i);
}
this.el.appendChild(ne);
}
}
});