-
Notifications
You must be signed in to change notification settings - Fork 1
/
porting_wizard.js
147 lines (129 loc) · 6.58 KB
/
porting_wizard.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
$(document).ready(function() {
VVVV.init('vvvv_js', 'full', function() {
$.ajax({
url: 'nodelist.xml',
async: false,
dataType: 'text',
success: function(response) {
var $nodeList = $(response);
$nodeList.find('node').each(function() {
var systemname = $(this).attr('systemname').replace(' Legacy', '');
$nodeLink = $('<a href="#'+systemname+'" class="nodelink">'+systemname+'</a>');
if (VVVV.NodeLibrary[systemname.toLowerCase()])
$nodeLink.addClass("implemented");
$('#nodelist').append($nodeLink);
});
var templateCode;
$.ajax({
url: 'template.tpl.js',
async: false,
dataType: 'text',
success: function(r) {
templateCode = r;
}
})
function getDefaultValue(subtype) {
var ret = '';
var match = /(Integer|Real|Boolean)/.exec(subtype);
if (match) {
ret = 0.0;
match = /Default is (.+)$/.exec(subtype);
if (match) {
ret = match[1];
}
}
else if (/Color/.test(subtype)) {
ret = "'1.0, 1.0, 1.0, 1.0'";
}
else if (/String/.test(subtype)) {
ret = "'text'";
}
return ret;
}
$(window).bind('hashchange', function() {
$('#nodeoptions').show();
$('.syntax-container').show();
var systemname = window.location.hash.substring(1);
if (VVVV.NodeLibrary[systemname.toLowerCase()])
$('#implemented_alert').show();
else
$('#implemented_alert').hide();
var $node = $nodeList.find('node[systemname="'+systemname+'"]').first();
$('#nodename').html(systemname);
if ($node.attr('autoevaluate')>0)
$('#auto_evaluate').attr('checked', 'checked');
else
$('#auto_evaluate').attr('checked', undefined);
$('#pins').find('div').empty();
$node.find('pin[direction="Input"]').each(function() {
if ($(this).attr('name')!="")
$('#pins #input').append('<input type="checkbox" class="pincheckbox code_option" name="'+$(this).attr('name')+'" checked="checked"/> '+$(this).attr('name')+'<br/>');
});
$node.find('pin[direction="Output"]').each(function() {
if ($(this).attr('name')!="ID" && $(this).attr('name')!="")
$('#pins #output').append('<input type="checkbox" class="pincheckbox code_option" name="'+$(this).attr('name')+'" checked="checked"/> '+$(this).attr('name')+'<br/>');
});
$node.find('pin[direction="Configuration"]').each(function() {
if ($(this).attr('name')!="Descriptive Name")
$('#pins #invisible').append('<input type="checkbox" class="pincheckbox code_option" name="'+$(this).attr('name')+'"/> '+$(this).attr('name')+'<br/>');
});
function buildTemplate() {
$('.syntax-container').remove();
$('body').append('<pre id="template" class="syntax javascript"></pre>')
var tpl = templateCode;
tpl = tpl.replace(/\{\{systemname\}\}/g, systemname);
tpl = tpl.replace(/\{\{objectname\}\}/g, systemname.replace(/[\s\(\)]/g, ''));
tpl = tpl.replace(/\{\{author\}\}/g, _($('#author').val().split(',')).map(function(a) { return "'"+a.trim()+"'" }).join(','));
tpl = tpl.replace(/\{\{original_author\}\}/g, _($('#original_author').val().split(',')).map(function(a) { return "'"+a.trim()+"'" }).join(','));
tpl = tpl.replace(/\{\{auto_evaluate\}\}/g, $('#auto_evaluate').is(':checked'));
var inpins = [];
var pinfetches = [];
$node.find('pin[direction="Input"]').each(function() {
if ($('.pincheckbox[name="'+$(this).attr('name')+'"]').is(':checked')) {
var objectName = $(this).attr('name').replace(/\s/g, '').toLowerCase();
var defaultValue = getDefaultValue($(this).attr('subtype'));
inpins.push(" var "+objectName+"In = this.addInputPin('"+$(this).attr('name')+"', ["+defaultValue+"], this);")
pinfetches.push(" var "+objectName+" = "+objectName+"In.getValue(i);");
}
});
tpl = tpl.replace(/\{\{input_pin_definitions\}\}/g, inpins.join('\n'));
tpl = tpl.replace(/\{\{pin_fetches\}\}/g, pinfetches.join('\n'));
var outpins = [];
var pinsets = [];
var misc = [];
$node.find('pin[direction="Output"]').each(function() {
if ($('.pincheckbox[name="'+$(this).attr('name')+'"]').is(':checked')) {
var objectName = $(this).attr('name').replace(/\s/g, '').toLowerCase();
var defaultValue = getDefaultValue($(this).attr('subtype'));
outpins.push(" var "+objectName+"Out = this.addOutputPin('"+$(this).attr('name')+"', ["+defaultValue+"], this);")
defaultValue = defaultValue.length == 0 ? "undefined" : defaultValue;
pinsets.push(" "+objectName+"Out.setValue(i, "+defaultValue+");");
misc.push(" "+objectName+"Out.setSliceCount(maxSize);");
}
});
tpl = tpl.replace(/\{\{output_pin_definitions\}\}/g, outpins.join('\n'));
tpl = tpl.replace(/\{\{pin_sets\}\}/g, pinsets.join('\n'));
tpl = tpl.replace(/\{\{misc\}\}/g, misc.join('\n'));
var invpins = [];
$node.find('pin[direction="Configuration"]').each(function() {
if ($('.pincheckbox[name="'+$(this).attr('name')+'"]').is(':checked')) {
var objectName = $(this).attr('name').replace(/\s/g, '').toLowerCase()+"In";
invpins.push(" var "+objectName+" = this.addInvisiblePin('"+$(this).attr('name')+"', [0.0], this);")
}
});
tpl = tpl.replace(/\{\{hidden_pin_definitions\}\}/g, invpins.join('\n'));
$('#template').text(tpl);
$.syntax({});
}
buildTemplate();
$('.code_option').unbind('change');
$('.code_option').change(function() { buildTemplate() });
$('.code_option').unbind('keyup');
$('.code_option').keyup(function() { buildTemplate() });
$('.code_option').unbind('click');
$('.code_option').click(function() { buildTemplate() });
});
}
})
});
})