2017-10-20 17:34:48 -07:00
<!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" / >
< title > Custom Procedure Playground< / title >
< script src = "../blockly_uncompressed_vertical.js" > < / script >
< script src = "../msg/messages.js" > < / script >
< script src = "../blocks_vertical/vertical_extensions.js" > < / script >
< script src = "../blocks_common/math.js" > < / script >
< script src = "../blocks_common/text.js" > < / script >
< script src = "../blocks_common/colour.js" > < / script >
< script src = "../blocks_vertical/control.js" > < / script >
< script src = "../blocks_vertical/event.js" > < / script >
< script src = "../blocks_vertical/motion.js" > < / script >
< script src = "../blocks_vertical/looks.js" > < / script >
< script src = "../blocks_vertical/procedures.js" > < / script >
< script src = "../blocks_vertical/operators.js" > < / script >
< script src = "../blocks_vertical/pen.js" > < / script >
< script src = "../blocks_vertical/sound.js" > < / script >
< script src = "../blocks_vertical/sensing.js" > < / script >
< script src = "../blocks_vertical/data.js" > < / script >
< style >
body {
background-color: #fff;
font-family: sans-serif;
}
h1 {
font-weight: normal;
font-size: 140%;
}
< / style >
< / head >
< body >
< table width = "100%" >
< tr >
< td >
2017-11-22 14:29:12 -05:00
< div id = "secondaryDiv" style = "height: 480px; width: 600px;" > < / div >
2017-10-20 17:34:48 -07:00
< / td >
< td >
2017-11-22 14:29:12 -05:00
< div id = "primaryDiv" style = "height: 480px; width: 600px;" > < / div >
2017-10-20 17:34:48 -07:00
< / td >
< / tr >
2017-10-23 17:04:44 -07:00
< tr >
2017-11-22 14:29:12 -05:00
< td > < / td >
< td id = "editor-actions" >
2017-11-08 15:24:01 -08:00
< button id = "text_number" onclick = "addTextNumber()" > Add text/number input< / button >
< button id = "boolean" onclick = "addBoolean()" > Add boolean input< / button >
< button id = "label" onclick = "addLabel()" > Add label< / button >
2017-11-22 14:29:12 -05:00
< button id = "cancelButton" onclick = "cancel()" > cancel< / button >
2017-10-27 11:12:40 -07:00
< button id = "okButton" onclick = "applyMutation()" > ok< / button >
2017-11-09 12:55:07 -08:00
< button id = "rndButton" onclick = "removeRandomInput()" > remove random input< / button >
< button id = "addRndButton" onclick = "addRandomInput()" > add random input< / button >
2017-10-23 17:04:44 -07:00
< / td >
< / tr >
2017-10-20 17:34:48 -07:00
< / table >
2017-10-23 17:04:44 -07:00
< xml id = "mutator_blocks" style = "display:none" >
2017-11-15 14:16:34 -08:00
< block type = "procedures_declaration" x = "25" y = "25" deletable = "false" >
2017-10-31 18:28:17 -07:00
< mutation proccode = "say %s %n times if %b" argumentnames = "["something","this many","this is true"]" argumentdefaults = "["",1,false]" warp = "false" argumentids = "["a42", "b23", "c99"]" / >
2017-10-24 12:57:56 -07:00
< / block >
2017-10-23 17:04:44 -07:00
< / xml >
< xml id = "main_ws_blocks" style = "display:none" >
2017-11-15 14:16:34 -08:00
< block id = "]){{Y!7N9ezN+j@Vr`8p" type = "procedures_definition" x = "25" y = "25" >
2017-10-24 12:57:56 -07:00
< statement name = "custom_block" >
2017-11-15 14:16:34 -08:00
< shadow type = "procedures_prototype" id = "caller_internal" >
2017-10-31 18:28:17 -07:00
< mutation proccode = "say %s %n times if %b" argumentnames = "["something","this many","this is true"]" argumentdefaults = "["",1,false]" warp = "false" argumentids = "["a42", "b23", "c99"]" / >
2017-10-24 12:57:56 -07:00
< / shadow >
< / statement >
< next >
2017-11-15 14:16:34 -08:00
< block id = "caller_external" type = "procedures_call" >
2017-11-01 14:14:11 -07:00
< mutation proccode = "say %s %n times if %b" argumentnames = "["something","this many","this is true"]" argumentdefaults = "["",1,false]" warp = "false" argumentids = "["a42", "b23", "c99"]" / >
2017-10-24 12:57:56 -07:00
< value name = "input0" >
< shadow id = "V0~M:TxRk0Ua%osjGzh," type = "text" >
2017-11-02 16:50:03 -07:00
< field name = "TEXT" / > < / field >
2017-10-24 12:57:56 -07:00
< / shadow >
< / value >
< value name = "input1" >
< shadow id = "uPx3si(KkbL1)-XpbXoQ" type = "math_number" >
< field name = "NUM" > 1< / field >
< / shadow >
< / value >
< / block >
< / next >
< / block >
2017-10-23 17:04:44 -07:00
< / xml >
2017-10-27 11:12:40 -07:00
< xml id = "main_ws_blocks_simpler" style = "display:none" >
2017-11-15 14:16:34 -08:00
< block id = "]){{Y!7N9ezN+j@Vr`8p" type = "procedures_definition" x = "25" y = "25" >
2017-10-27 11:12:40 -07:00
< statement name = "custom_block" >
2017-11-15 14:16:34 -08:00
< shadow type = "procedures_prototype" id = "caller_internal" >
2017-10-31 18:28:17 -07:00
< mutation proccode = "say %s %n times if %b" argumentnames = "["something","this many","this is true"]" argumentdefaults = "["",1,false]" warp = "false" argumentids = "["a42", "b23", "c99"]" / >
2017-10-27 11:12:40 -07:00
< / shadow >
< / statement >
< next >
2017-11-15 14:16:34 -08:00
< block id = "caller_external" type = "procedures_call" >
2017-10-27 11:12:40 -07:00
< / block >
< / next >
< / block >
< / xml >
2017-11-08 15:24:01 -08:00
< xml id = "main_ws_blocks_simplest" style = "display:none" >
2017-11-15 14:16:34 -08:00
< block id = "]){{Y!7N9ezN+j@Vr`8p" type = "procedures_definition" x = "25" y = "25" >
2017-11-08 15:24:01 -08:00
< statement name = "custom_block" >
2017-11-15 14:16:34 -08:00
< shadow type = "procedures_prototype" id = "caller_internal" >
2017-11-08 15:24:01 -08:00
< mutation proccode = "my first function" argumentnames = "[]" argumentdefaults = "[]" warp = "false" argumentids = "[]" / >
< / shadow >
< / statement >
< next >
2017-11-15 14:16:34 -08:00
< block id = "caller_external" type = "procedures_call" >
2017-11-08 15:24:01 -08:00
< mutation proccode = "my first function" argumentnames = "[]" argumentdefaults = "[]" warp = "false" argumentids = "[]" / >
< / block >
< / next >
< / block >
< / xml >
< xml id = "mutator_blocks_simplest" style = "display:none" >
2017-11-15 14:16:34 -08:00
< block type = "procedures_declaration" x = "25" y = "25" deletable = "false" >
2017-11-08 15:24:01 -08:00
< mutation proccode = "my first function" argumentnames = "[]" argumentdefaults = "[]" warp = "false" argumentids = "[]" / >
< / block >
< / xml >
2017-11-22 14:29:12 -05:00
< xml id = "toolbox" style = "display:none" >
< category name = "More" colour = "#FF6680" secondaryColour = "#FF4D6A" custom = "PROCEDURE" >
< / category >
2018-04-11 11:54:51 -07:00
< category name = "Values" >
< block type = "operator_round" >
< value name = "NUM" >
< shadow type = "math_number" >
< field name = "NUM" > < / field >
< / shadow >
< / value >
< / block >
< / category >
2018-10-24 13:49:30 -07:00
< category name = "Statements" >
< block type = "control_forever" > < / block >
< block type = "sound_stopallsounds" > < / block >
< block type = "control_start_as_clone" > < / block >
< block type = "control_stop" >
< mutation hasnext = "false" > < / mutation >
< field name = "STOP_OPTION" > all< / field >
< / block >
< / category >
2017-11-22 14:29:12 -05:00
< / xml >
2017-10-24 12:57:56 -07:00
2017-10-20 17:34:48 -07:00
< script >
2017-11-22 14:29:12 -05:00
var editorActions = document.getElementById('editor-actions');
editorActions.style.visibility = 'hidden';
2017-10-24 12:57:56 -07:00
2017-11-22 14:29:12 -05:00
var callback = null;
var mutationRoot = null;
2017-10-24 12:57:56 -07:00
2017-11-22 14:29:12 -05:00
var declarationWorkspace = Blockly.inject('primaryDiv',
2017-10-27 11:12:40 -07:00
{media: '../media/'});
2017-10-24 12:57:56 -07:00
2017-11-22 14:29:12 -05:00
declarationWorkspace.addChangeListener(function() {
if (mutationRoot) {
mutationRoot.onChangeFn();
}
});
var definitionWorkspace = Blockly.inject('secondaryDiv', {
media: '../media/',
toolbox: document.getElementById('toolbox'),
zoom: {
startScale: 0.75
}
});
Blockly.Xml.clearWorkspaceAndLoadFromXml(document.getElementById('main_ws_blocks_simplest'),
definitionWorkspace);
2017-11-29 09:28:41 -05:00
Blockly.Procedures.externalProcedureDefCallback = function (mutation, cb) {
2017-11-22 14:29:12 -05:00
editorActions.style.visibility = 'visible';
callback = cb;
declarationWorkspace.clear();
mutationRoot = declarationWorkspace.newBlock('procedures_declaration');
mutationRoot.domToMutation(mutation);
mutationRoot.initSvg();
mutationRoot.render(false);
}
2017-10-27 11:12:40 -07:00
function applyMutation() {
2018-04-09 15:39:11 -07:00
var mutation = mutationRoot.mutationToDom(/* opt_generateShadows */ true)
console.log(mutation);
callback(mutation);
2017-11-22 14:29:12 -05:00
callback = null;
mutationRoot = null;
declarationWorkspace.clear();
definitionWorkspace.refreshToolboxSelection_()
editorActions.style.visibility = 'hidden';
2017-10-27 11:12:40 -07:00
}
2017-11-08 15:24:01 -08:00
function addLabel() {
mutationRoot.addLabelExternal();
}
function addBoolean() {
mutationRoot.addBooleanExternal();
}
function addTextNumber() {
mutationRoot.addStringNumberExternal();
}
2017-11-09 12:55:07 -08:00
function removeRandomInput() {
var rnd = Math.floor(Math.random() * mutationRoot.inputList.length);
mutationRoot.removeInput(mutationRoot.inputList[rnd].name);
mutationRoot.onChangeFn();
mutationRoot.updateDisplay_();
}
function addRandomInput() {
var rnd = Math.floor(Math.random() * 3);
switch (rnd) {
case 0:
addTextNumber();
break;
case 1:
addLabel();
break;
case 2:
addBoolean();
break;
}
2017-11-22 14:29:12 -05:00
}
2017-11-09 12:55:07 -08:00
2017-11-22 14:29:12 -05:00
function cancel() {
callback = null;
mutationRoot = null;
declarationWorkspace.clear();
definitionWorkspace.refreshToolboxSelection_()
editorActions.style.visibility = 'hidden';
2017-11-09 12:55:07 -08:00
}
2017-10-20 17:34:48 -07:00
< / script >
< / body >
< / html >