Commit 7f4e8dd5 authored by Jennie Yoder's avatar Jennie Yoder

Okay, I forgot about procedure aruments.

Now, all loop variables as typed as numbers and all procedure arguments
are typed as "null", meaning they'll fit anywhere.  It isn't perfect, but
it is a start.
parent 8925f37f
......@@ -84,16 +84,21 @@ Blockly.Blocks['variables_get'] = {
var found_it = 0;
for (var i = 0; i < all_of_them.length; i++) {
if (all_of_them[i].type == 'variables_set') {
this.outputConnection.check_ = all_of_them[i].myType_;
this.outputConnection.setCheck(all_of_them[i].myType_);
console.log("vars_get " + this.id + " was initialized to " + all_of_them[i].myType_);
found_it = 1;
break;
}
if (all_of_them[i].type == 'controls_for' || all_of_them[i].type == 'controls_for_chainhull') {
this.outputConnection.setCheck("Number");
found_it = 1;
}
}
if (!found_it) {
// this has no variables_set block... Must be from a loop Make it a number.
console.log("is there a variable instance from a loop here?");
this.outputConnection.setCheck("Number");
// this has no variables_set block... Could be from a procedure.
// since I don't know it's type, set it to null.
console.log("is there a variable instance from a procedure here?");
this.outputConnection.setCheck(null);
}
}
},
......
......@@ -228,9 +228,9 @@ updateType_:function(a){"NUMBER"==a?this.outputConnection.setCheck("Number"):thi
Blockly.Blocks.text_prompt={init:function(){var a=[[Blockly.Msg.TEXT_PROMPT_TYPE_TEXT,"TEXT"],[Blockly.Msg.TEXT_PROMPT_TYPE_NUMBER,"NUMBER"]],b=this;this.setHelpUrl(Blockly.Msg.TEXT_PROMPT_HELPURL);this.setColourHex(Blockly.Blocks.texts.HUE);a=new Blockly.FieldDropdown(a,function(a){b.updateType_(a)});this.appendDummyInput().appendField(a,"TYPE").appendField(this.newQuote_(!0)).appendField(new Blockly.FieldTextInput(""),"TEXT").appendField(this.newQuote_(!1));this.setOutput(!0,"String");b=this;this.setTooltip(function(){return"TEXT"==
b.getFieldValue("TYPE")?Blockly.Msg.TEXT_PROMPT_TOOLTIP_TEXT:Blockly.Msg.TEXT_PROMPT_TOOLTIP_NUMBER})},newQuote_:Blockly.Blocks.text.newQuote_,updateType_:Blockly.Blocks.text_prompt_ext.updateType_,mutationToDom:Blockly.Blocks.text_prompt_ext.mutationToDom,domToMutation:Blockly.Blocks.text_prompt_ext.domToMutation};Blockly.Blocks.variables={};
Blockly.Blocks.variables_get={init:function(){this.initialized_type=0;this.setHelpUrl(Blockly.Msg.VARIABLES_GET_HELPURL);this.setColourHex(Blockscad.Toolbox.HEX_VARIABLE);this.appendDummyInput().appendField(Blockly.Msg.VARIABLES_GET_TITLE).appendField(new Blockly.FieldVariable(Blockly.Msg.VARIABLES_GET_ITEM),"VAR").appendField(Blockly.Msg.VARIABLES_GET_TAIL);this.setOutput(!0);this.setTooltip(Blockly.Msg.VARIABLES_GET_TOOLTIP);this.contextMenuMsg_=Blockly.Msg.VARIABLES_GET_CREATE_SET;this.contextMenuType_=
"variables_set"},getVars:function(){return[this.getFieldValue("VAR")]},renameVar:function(a,b){Blockly.Names.equals(a,this.getFieldValue("VAR"))&&this.setFieldValue(b,"VAR")},onchange:function(){if(0==this.initialized_type){this.initialized_type=1;for(var a=Blockly.Variables.getInstances(this.getFieldValue("VAR"),this.workspace),b=0,c=0;c<a.length;c++)if("variables_set"==a[c].type){this.outputConnection.check_=a[c].myType_;console.log("vars_get "+this.id+" was initialized to "+a[c].myType_);b=1;break}b||
(console.log("is there a variable instance from a loop here?"),this.outputConnection.setCheck("Number"))}},customContextMenu:function(a){var b={enabled:!0},c=this.getFieldValue("VAR");b.text=this.contextMenuMsg_.replace("%1",c);var d=goog.dom.createDom("field",null,c);d.setAttribute("name","VAR");d=goog.dom.createDom("block",null,d);d.setAttribute("type",this.contextMenuType_);b.callback=Blockly.ContextMenu.callbackFactory(this,d);a.push(b);b={enabled:!0};b.text="Highlight "+c+" Instances";var e=
this.workspace,f=this;b.callback=function(){var a=Blockly.Variables.getInstances(c,e);e.clearBacklight();f.unselect();for(var b=0;a&&b<a.length;b++){a[b]&&a[b].backlight();var d=a[b].collapsedParents();if(d)for(var k=0;k<d.length;k++)d[k].backlight()}};a.push(b)}};
"variables_set"},getVars:function(){return[this.getFieldValue("VAR")]},renameVar:function(a,b){Blockly.Names.equals(a,this.getFieldValue("VAR"))&&this.setFieldValue(b,"VAR")},onchange:function(){if(0==this.initialized_type){this.initialized_type=1;for(var a=Blockly.Variables.getInstances(this.getFieldValue("VAR"),this.workspace),b=0,c=0;c<a.length;c++){if("variables_set"==a[c].type){this.outputConnection.setCheck(a[c].myType_);console.log("vars_get "+this.id+" was initialized to "+a[c].myType_);b=
1;break}if("controls_for"==a[c].type||"controls_for_chainhull"==a[c].type)this.outputConnection.setCheck("Number"),b=1}b||(console.log("is there a variable instance from a procedure here?"),this.outputConnection.setCheck(null))}},customContextMenu:function(a){var b={enabled:!0},c=this.getFieldValue("VAR");b.text=this.contextMenuMsg_.replace("%1",c);var d=goog.dom.createDom("field",null,c);d.setAttribute("name","VAR");d=goog.dom.createDom("block",null,d);d.setAttribute("type",this.contextMenuType_);
b.callback=Blockly.ContextMenu.callbackFactory(this,d);a.push(b);b={enabled:!0};b.text="Highlight "+c+" Instances";var e=this.workspace,f=this;b.callback=function(){var a=Blockly.Variables.getInstances(c,e);e.clearBacklight();f.unselect();for(var b=0;a&&b<a.length;b++){a[b]&&a[b].backlight();var d=a[b].collapsedParents();if(d)for(var k=0;k<d.length;k++)d[k].backlight()}};a.push(b)}};
Blockly.Blocks.variables_set={init:function(){this.myType_=null;this.backlightBlocks=[];this.setHelpUrl(Blockly.Msg.VARIABLES_SET_HELPURL);this.setColourHex(Blockscad.Toolbox.HEX_VARIABLE);this.interpolateMsg(Blockly.Msg.VARIABLES_SET_TITLE+" %1 "+Blockly.Msg.VARIABLES_SET_TAIL+" %2",["VAR",new Blockly.FieldVariable(Blockly.Msg.VARIABLES_SET_ITEM)],["VALUE",null,Blockly.ALIGN_RIGHT],Blockly.ALIGN_RIGHT);this.setPreviousStatement(!0,["VariableSet"]);this.setNextStatement(!0,["VariableSet","CAG","CSG"]);
this.setTooltip(Blockly.Msg.VARIABLES_SET_TOOLTIP);this.contextMenuMsg_=Blockly.Msg.VARIABLES_SET_CREATE_GET;this.contextMenuType_="variables_get"},getVars:function(){return[this.getFieldValue("VAR")]},setType:function(a){console.log("in variable_set setType with: ",a);if(this.workspace)if(this.myType_==a)console.log("type didn't actually change. Returning without doing work.");else{var b=Blockly.Variables.getInstances(this.getFieldValue("VAR"),this.workspace),c=[],d;if(0<b.length)for(var e=0;e<
b.length;e++)if(console.log("found an instance: ",b[e].id," ",b[e].type),"variables_get"==b[e].type){var f=b[e].getParent();if(null!=a&&f&&(console.log("found instance with parent: ",f.type),d=b[e].outputConnection.targetConnection.check_,null!=d&&(d=d[0]),console.log("types parent accepts: ",d),null!=d&&d!=a[0])){console.log("block "+b[e].id+" will be kicked out.");c.push(b[e]);b[e].backlight();this.backlightBlocks.push(b[e].id);var g=b[e].collapsedParents();if(g)for(var h=0;h<g.length;h++)g[h].setCollapsed(!1)}b[e].outputConnection.setCheck(a);
......
......@@ -1357,11 +1357,17 @@ Blockscad.assignVarTypes = function(blk) {
found_it = 1;
break;
}
if (instances[i].type == "controls_for" || instances[i].type == "controls_for_chainhull") {
blk.outputConnection.setCheck("Number");
found_it = 1;
break;
}
}
if (!found_it) {
// this came out of a loop - no set_variable block to go with it. Set type to number.
console.log("setting a variables_get block to type number");
blk.outputConnection.setCheck("Number");
// this came out of a procedure - no set_variable block to go with it.
// a procedure could have any type associated, so set type to null.
console.log("setting a variables_get block to type null");
blk.outputConnection.setCheck(null);
}
// now, if this variables_get was inside a variables_set, that variables_set needs to be retyped.
var parent = blk.getParent();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment