forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframework_link.dev.js
More file actions
111 lines (96 loc) · 3.65 KB
/
framework_link.dev.js
File metadata and controls
111 lines (96 loc) · 3.65 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
pc.extend(editor, function () {
var LinkInterface = function () {
this.exposed = {}; // dictionary of exposed variables by system type
this.added = {}; // dictionary of added variables, deprecated...
this.scripts = {}; // dictionary of exposed script variables, not used
this.systems = []; // list of registered system names
};
/**
* Expose a Component
* @param {Object} componentSystem
*/
LinkInterface.prototype.addComponentType = function(componentSystem) {
var name = componentSystem.id;
var i;
var systems = this.systems;
var length = systems.length;
var exists = false;
for( i=0; i<length; i++ ) {
if( systems[i].name === name ) {
exists = true;
break;
}
}
if (!exists) {
this.systems.push({"name" : name, "description" : componentSystem.description});
}
if (!this.exposed[name]) {
this.exposed[name] = {};
}
};
/**
* Expose a property of an object to the editor. This property will appear in the attribute editor control
* @param {Object} details
*/
LinkInterface.prototype.expose = function (system, details) {
if(!details.name) {
throw new Error("Missing option 'name'");
}
// Add default values
details.options = details.options || {};
if (details.type === 'vector') {
// indicate that this is an array type (and therefore is a reference type and needs copying)
details.array = true;
// Provide an RuntimeType which is instatiated after passing an object over livelink
if (details.defaultValue) {
switch(details.defaultValue.length) {
case 2:
details.RuntimeType = pc.Vec2;
break;
case 3:
details.RuntimeType = pc.Vec3;
break;
case 4:
details.RuntimeType = pc.Vec4;
break;
}
} else {
details.RuntimeType = pc.Vec3;
}
}
if (details.type === 'rgb' ||
details.type === 'rgba') {
// indicate that this is an array type (and therefore is a reference type and needs copying)
details.array = true;
// Provide an RuntimeType which is instatiated after passing an object over livelink
details.RuntimeType = pc.Color;
}
if (!this.exposed[system][details.name]) {
this.exposed[system][details.name] = {};
}
this.exposed[system][details.name] = details;
};
/**
* Add a property to the added list. Added properties are created in the viewmodels and can be used internally.
* They are never visible in the Designer
* @param {Object} details
*/
LinkInterface.prototype.add = function (details) {
logASSERT(details.system, "Missing option: 'system'");
logASSERT(details.variable, "Missing option: 'variable'");
if(!this.added[details.system]) {
this.added[details.system] = {};
}
if(!this.added[details.system][details.variable]) {
this.added[details.system][details.variable] = {};
}
this.added[details.system][details.variable] = details;
};
LinkInterface.prototype.scriptexpose = function (details) {
this.scripts[details.script] = details;
};
return {
LinkInterface: LinkInterface,
link: new LinkInterface()
};
}());