<commit_before>E2.p = E2.plugins["delegate_expression_generator"] = function(core, node)
{
	this.desc = 'Emit a value delegate that resolves an integer parameter \'<b>x</b>\' to the value of an arbitrary javascript expression that can be contingent on an arbitrary number of dynamic input float slots.';
	
	this.input_slots = [];
	
	this.output_slots = [ 
		{ name: 'delegate', dt: core.datatypes.DELEGATE, desc: 'The resulting delegate.' } 
	];
	
	this.state = {
		expression: '',
		slot_ids: {} 
	};

	this.core = core;
	this.node = node;
	this.gl = core.renderer.context;
	this.slot_name = [];
	this.slot_data = {};
};

E2.p.prototype.delegate_func = function(self) { return function(x)
{
	if(self.state.expression === '')
		return 0;
	
	with(Math)
	{
		with(self.slot_data)
		{
			try
			{
				var r = eval(self.state.expression);
				
				return typeof(r) === 'number' ? r : 0;
			}
			catch(e)
			{
				msg('ERROR: Failed to evaluate expression: ' + e);
				return 0;
			}
		}
	}
}};

E2.p.prototype.reset = function()
{
};

E2.p.prototype.open_editor = function(self, done_func, dest) { return function(e)
{
	var diag = make('span');
	var src = $('<textarea></textarea>'); 
	
	diag.css('margin', '0px');
	diag.css('padding', '2px');

	src.css('margin', '0px');
	src.css('padding', '0px');
	src.css('margin-top', '2px');
	src.css('border', 'none');
	src.css('width', '455px');
	src.css('height', '400px');
	src.css('resize', 'none');
	src.css('font-size', '9pt');
	src.css('font-family', 'Monospace');
	src.css('overflow', 'scroll');
	src.css('word-wrap', 'normal');
	src.css('white-space', 'pre');
	src.css('background-color', '#ddd');
	
	src.val(self.state.expression);
	
	diag.append(src);
	
	var btn_span = make('span');
	var add_btn = $('<input id="add_btn" type="button" value="Add slot" title="Click to add new delegate input slot." />');
	var rem_btn = $('<input id="rem_btn" type="button" value="Remove slot" title="Click to remove the selected slot(s)." />');
	var slot_list = $('<select size="4" />');
	
	slot_list.css('border', 'none');
	slot_list.css('width', '457px');
	slot_list.css('margin-left', '2px');
	slot_list.css('background-color', '#ddd');

	btn_span.css('width', '455px');
	btn_span.append(add_btn);
	btn_span.append(rem_btn);
	
	diag.append(make('br'));
	diag.append(btn_span);
	diag.append(make('br'));
	diag.append(slot_list);

	// Rebuild slot list.
	for(var ident in self.state.slot_ids)
	{
		var sid = self.state.slot_ids[ident];

		slot_list.append($('<option>', { value: sid }).text(ident));
	}			
	
	add_btn.click(function(self) { return function(e)
	{
		var diag2 = make('div');
		var inp = $('<input type="input" />'); 

		var l1 = make('span');
		var lbl = $('<div>Identifier:</div>');
		
		inp.css('width', '220px');
		lbl.css('padding-top', '3px');
		lbl.css('float', 'left');
		lbl.css('width', '80px');
		
		l1.append(lbl);
		l1.append(inp);
		
		diag2.append(l1);
		
		var finish_func = function(self) { return function()
		{
			var sname = inp.val();
			var cid = sname.replace(' ', '_').toLowerCase();
			var sid = self.node.add_slot(E2.slot_type.input, { name: cid, dt: self.core.datatypes.FLOAT });

			self.state.slot_ids[cid] = sid;
			self.slot_name[sid] = cid;
			self.slot_data[cid] = null;
			slot_list.append($('<option>', { value: sid }).text(cid));
			
			diag2.dialog('close');
		}}(self);
		
		diag2.dialog({
			width: 360,
			height: 170,
			modal: true,
			title: 'Create new slot.',
			show: 'slide',
			hide: 'slide',
			buttons: {<commit_msg>Minimized the number of .css() calls in the delegate expression plugin.<commit_after>E2.p = E2.plugins["delegate_expression_generator"] = function(core, node)
{
	this.desc = 'Emit a value delegate that resolves an integer parameter \'<b>x</b>\' to the value of an arbitrary javascript expression that can be contingent on an arbitrary number of dynamic input float slots.';
	
	this.input_slots = [];
	
	this.output_slots = [ 
		{ name: 'delegate', dt: core.datatypes.DELEGATE, desc: 'The resulting delegate.' } 
	];
	
	this.state = {
		expression: '',
		slot_ids: {} 
	};

	this.core = core;
	this.node = node;
	this.gl = core.renderer.context;
	this.slot_name = [];
	this.slot_data = {};
};

E2.p.prototype.delegate_func = function(self) { return function(x)
{
	if(self.state.expression === '')
		return 0;
	
	with(Math)
	{
		with(self.slot_data)
		{
			try
			{
				var r = eval(self.state.expression);
				
				return typeof(r) === 'number' ? r : 0;
			}
			catch(e)
			{
				msg('ERROR: Failed to evaluate expression: ' + e);
				return 0;
			}
		}
	}
}};

E2.p.prototype.reset = function()
{
};

E2.p.prototype.open_editor = function(self, done_func, dest) { return function(e)
{
	var diag = make('span');
	var src = $('<textarea></textarea>'); 
	
	diag.css({
		'margin': '0px',
		'padding': '2px'
	});

	src.css({
		'margin': '0px',
		'padding': '0px',
		'margin-top': '2px',
		'border': 'none',
		'width': '455px',
		'height': '400px',
		'resize': 'none',
		'font-size': '9pt',
		'font-family': 'Monospace',
		'overflow': 'scroll',
		'word-wrap': 'normal',
		'white-space': 'pre',
		'background-color': '#ddd'
	});
	
	src.val(self.state.expression);
	
	diag.append(src);
	
	var btn_span = make('span');
	var add_btn = $('<input id="add_btn" type="button" value="Add slot" title="Click to add new delegate input slot." />');
	var rem_btn = $('<input id="rem_btn" type="button" value="Remove slot" title="Click to remove the selected slot(s)." />');
	var slot_list = $('<select size="4" />');
	
	slot_list.css({
		'border': 'none',
		'width': '457px',
		'margin-left': '2px',
		'background-color': '#ddd'
	});

	btn_span.css('width', '455px');
	btn_span.append(add_btn);
	btn_span.append(rem_btn);
	
	diag.append(make('br'));
	diag.append(btn_span);
	diag.append(make('br'));
	diag.append(slot_list);

	// Rebuild slot list.
	for(var ident in self.state.slot_ids)
	{
		var sid = self.state.slot_ids[ident];

		slot_list.append($('<option>', { value: sid }).text(ident));
	}			
	
	add_btn.click(function(self) { return function(e)
	{
		var diag2 = make('div');
		var inp = $('<input type="input" />'); 

		var l1 = make('span');
		var lbl = $('<div>Identifier:</div>');
		
		inp.css('width', '220px');
		
		lbl.css({
			'padding-top': '3px',
			'float': 'left',
			'width': '80px'
		});
		
		l1.append(lbl);
		l1.append(inp);
		
		diag2.append(l1);
		
		var finish_func = function(self) { return function()
		{
			var sname = inp.val();
			var cid = sname.replace(' ', '_').toLowerCase();
			var sid = self.node.add_slot(E2.slot_type.input, { name: cid, dt: self.core.datatypes.FLOAT });

			self.state.slot_ids[cid] = sid;
			self.slot_name[sid] = cid;
			self.slot_data[cid] = null;
			slot_list.append($('<option>', { value: sid }).text(cid));
			
			diag2.dialog('close');
		}}(self);
		
		diag2.dialog({
			width: 360,
			height: 170,
			modal: true,
			title: 'Create new slot.',
			show: 'slide',
			hide: 'slide',
			buttons: {
{'fraction_non_alphanumeric': 0.2037410071942446, 'fraction_numerical': 0.014100719424460431, 'mean_word_length': 3.7350136239782015, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4250971', 'n_tokens_mistral': 2924, 'n_tokens_neox': 2594, 'n_words': 550}