mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Add workspace.newBlock, deprecate Blockly.Block.obtain.
This commit is contained in:
parent
dff95fc7b0
commit
6acaf35967
20 changed files with 136 additions and 307 deletions
|
@ -843,12 +843,13 @@ goog.ui.tree.TreeControl.prototype.handleMouseEvent_=function(a){goog.log.fine(t
|
|||
goog.ui.tree.TreeControl.prototype.handleKeyEvent=function(a){var b=!1;(b=this.typeAhead_.handleNavigation(a)||this.selectedItem_&&this.selectedItem_.onKeyDown(a)||this.typeAhead_.handleTypeAheadChar(a))&&a.preventDefault();return b};goog.ui.tree.TreeControl.prototype.getNodeFromEvent_=function(a){var b=null;for(a=a.target;null!=a;){if(b=goog.ui.tree.BaseNode.allNodes[a.id])return b;if(a==this.getElement())break;a=a.parentNode}return null};
|
||||
goog.ui.tree.TreeControl.prototype.createNode=function(a){return new goog.ui.tree.TreeNode(a||goog.html.SafeHtml.EMPTY,this.getConfig(),this.getDomHelper())};goog.ui.tree.TreeControl.prototype.setNode=function(a){this.typeAhead_.setNodeInMap(a)};goog.ui.tree.TreeControl.prototype.removeNode=function(a){this.typeAhead_.removeNodeFromMap(a)};goog.ui.tree.TreeControl.prototype.clearTypeAhead=function(){this.typeAhead_.clear()};goog.ui.tree.TreeControl.defaultConfig=goog.ui.tree.BaseNode.defaultConfig;
|
||||
// Copyright 2013 Google Inc. Apache License 2.0
|
||||
var Blockly={Blocks:{}};Blockly.Blocks.uidCounter_=0;Blockly.Blocks.genUid=function(){var a=(++Blockly.Blocks.uidCounter_).toString();return Blockly.Realtime.isEnabled()?Blockly.Realtime.genUid(a):a};
|
||||
var Blockly={Blocks:{}};
|
||||
// Copyright 2012 Google Inc. Apache License 2.0
|
||||
Blockly.Workspace=function(a){this.options=a||{};this.RTL=!!this.options.RTL;this.topBlocks_=[]};Blockly.Workspace.prototype.rendered=!1;Blockly.Workspace.prototype.dispose=function(){this.clear()};Blockly.Workspace.SCAN_ANGLE=3;Blockly.Workspace.prototype.addTopBlock=function(a){this.topBlocks_.push(a);this.fireChangeEvent()};
|
||||
Blockly.Workspace.prototype.removeTopBlock=function(a){for(var b=!1,c,d=0;c=this.topBlocks_[d];d++)if(c==a){this.topBlocks_.splice(d,1);b=!0;break}if(!b)throw"Block not present in workspace's list of top-most blocks.";this.fireChangeEvent()};
|
||||
Blockly.Workspace.prototype.getTopBlocks=function(a){var b=[].concat(this.topBlocks_);if(a&&1<b.length){var c=Math.sin(goog.math.toRadians(Blockly.Workspace.SCAN_ANGLE));this.RTL&&(c*=-1);b.sort(function(a,b){var f=a.getRelativeToSurfaceXY(),g=b.getRelativeToSurfaceXY();return f.y+c*f.x-(g.y+c*g.x)})}return b};Blockly.Workspace.prototype.getAllBlocks=function(){for(var a=this.getTopBlocks(!1),b=0;b<a.length;b++)a.push.apply(a,a[b].getChildren());return a};Blockly.Workspace.prototype.clear=function(){for(;this.topBlocks_.length;)this.topBlocks_[0].dispose()};
|
||||
Blockly.Workspace.prototype.getWidth=function(){return 0};Blockly.Workspace.prototype.getBlockById=function(a){for(var b=this.getAllBlocks(),c=0,d;d=b[c];c++)if(d.id==a)return d;return null};Blockly.Workspace.prototype.remainingCapacity=function(){return isNaN(this.options.maxBlocks)?Infinity:this.options.maxBlocks-this.getAllBlocks().length};Blockly.Workspace.prototype.fireChangeEvent=function(){};Blockly.Workspace.prototype.clear=Blockly.Workspace.prototype.clear;Blockly.Bubble=function(a,b,c,d,e,f,g){this.workspace_=a;this.content_=b;this.shape_=c;c=Blockly.Bubble.ARROW_ANGLE;this.workspace_.RTL&&(c=-c);this.arrow_radians_=goog.math.toRadians(c);a.getBubbleCanvas().appendChild(this.createDom_(b,!(!f||!g)));this.setAnchorLocation(d,e);f&&g||(b=this.content_.getBBox(),f=b.width+2*Blockly.Bubble.BORDER_WIDTH,g=b.height+2*Blockly.Bubble.BORDER_WIDTH);this.setBubbleSize(f,g);this.positionBubble_();this.renderArrow_();this.rendered_=!0;a.options.readOnly||(Blockly.bindEvent_(this.bubbleBack_,
|
||||
Blockly.Workspace.prototype.getWidth=function(){return 0};Blockly.Workspace.prototype.newBlock=function(a){return new Blockly.Block(this,a)};Blockly.Workspace.prototype.getBlockById=function(a){for(var b=this.getAllBlocks(),c=0,d;d=b[c];c++)if(d.id==a)return d;return null};Blockly.Workspace.prototype.remainingCapacity=function(){return isNaN(this.options.maxBlocks)?Infinity:this.options.maxBlocks-this.getAllBlocks().length};Blockly.Workspace.prototype.fireChangeEvent=function(){};
|
||||
Blockly.Workspace.prototype.clear=Blockly.Workspace.prototype.clear;Blockly.Bubble=function(a,b,c,d,e,f,g){this.workspace_=a;this.content_=b;this.shape_=c;c=Blockly.Bubble.ARROW_ANGLE;this.workspace_.RTL&&(c=-c);this.arrow_radians_=goog.math.toRadians(c);a.getBubbleCanvas().appendChild(this.createDom_(b,!(!f||!g)));this.setAnchorLocation(d,e);f&&g||(b=this.content_.getBBox(),f=b.width+2*Blockly.Bubble.BORDER_WIDTH,g=b.height+2*Blockly.Bubble.BORDER_WIDTH);this.setBubbleSize(f,g);this.positionBubble_();this.renderArrow_();this.rendered_=!0;a.options.readOnly||(Blockly.bindEvent_(this.bubbleBack_,
|
||||
"mousedown",this,this.bubbleMouseDown_),this.resizeGroup_&&Blockly.bindEvent_(this.resizeGroup_,"mousedown",this,this.resizeMouseDown_))};Blockly.Bubble.BORDER_WIDTH=6;Blockly.Bubble.ARROW_THICKNESS=10;Blockly.Bubble.ARROW_ANGLE=20;Blockly.Bubble.ARROW_BEND=4;Blockly.Bubble.ANCHOR_RADIUS=8;Blockly.Bubble.onMouseUpWrapper_=null;Blockly.Bubble.onMouseMoveWrapper_=null;
|
||||
Blockly.Bubble.unbindDragEvents_=function(){Blockly.Bubble.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseUpWrapper_),Blockly.Bubble.onMouseUpWrapper_=null);Blockly.Bubble.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseMoveWrapper_),Blockly.Bubble.onMouseMoveWrapper_=null)};Blockly.Bubble.prototype.rendered_=!1;Blockly.Bubble.prototype.anchorX_=0;Blockly.Bubble.prototype.anchorY_=0;Blockly.Bubble.prototype.relativeLeft_=0;Blockly.Bubble.prototype.relativeTop_=0;
|
||||
Blockly.Bubble.prototype.width_=0;Blockly.Bubble.prototype.height_=0;Blockly.Bubble.prototype.autoLayout_=!0;
|
||||
|
@ -974,8 +975,8 @@ Blockly.Xml.domToPrettyText=function(a){a=Blockly.Xml.domToText(a).split("<");fo
|
|||
Blockly.Xml.textToDom=function(a){a=(new DOMParser).parseFromString(a,"text/xml");if(!a||!a.firstChild||"xml"!=a.firstChild.nodeName.toLowerCase()||a.firstChild!==a.lastChild)throw"Blockly.Xml.textToDom did not obtain a valid XML tree.";return a.firstChild};
|
||||
Blockly.Xml.domToWorkspace=function(a,b){var c;a.RTL&&(c=a.getWidth());Blockly.Field.startCache();for(var d=b.childNodes.length,e=0;e<d;e++){var f=b.childNodes[e],g=f.nodeName.toLowerCase();if("block"==g||"shadow"==g){var g=Blockly.Xml.domToBlock(a,f),h=parseInt(f.getAttribute("x"),10),f=parseInt(f.getAttribute("y"),10);isNaN(h)||isNaN(f)||g.moveBy(a.RTL?c-h:h,f)}}Blockly.Field.stopCache()};
|
||||
Blockly.Xml.domToBlock=function(a,b,c){var d=Blockly.Xml.domToBlockHeadless_(a,b,c);if(a.rendered){d.setConnectionsHidden(!0);a=d.getDescendants();for(b=a.length-1;0<=b;b--)a[b].initSvg();for(b=a.length-1;0<=b;b--)a[b].render(!1);setTimeout(function(){d.workspace&&d.setConnectionsHidden(!1)},1);d.updateDisabled();Blockly.fireUiEvent(window,"resize")}return d};
|
||||
Blockly.Xml.domToBlockHeadless_=function(a,b,c){var d=null,e=b.getAttribute("type");if(!e)throw"Block type unspecified: \n"+b.outerHTML;var f=b.getAttribute("id");if(c&&f){d=Blockly.Block.getById(f,a);if(!d)throw"Couldn't get Block with id: "+f;f=d.getParent();d.workspace&&d.dispose(!0,!1,!0);d.fill(a,e);d.parent_=f}else d=Blockly.Block.obtain(a,e);for(var g=null,f=0,h;h=b.childNodes[f];f++)if(3!=h.nodeType){for(var k=g=null,l=0,p;p=h.childNodes[l];l++)1==p.nodeType&&("block"==p.nodeName.toLowerCase()?
|
||||
g=p:"shadow"==p.nodeName.toLowerCase()&&(k=p));!g&&k&&(g=k);l=h.getAttribute("name");switch(h.nodeName.toLowerCase()){case "mutation":d.domToMutation&&(d.domToMutation(h),d.initSvg&&d.initSvg());break;case "comment":d.setCommentText(h.textContent);var m=h.getAttribute("pinned");m&&setTimeout(function(){d.comment&&d.comment.setVisible&&d.comment.setVisible("true"==m)},1);g=parseInt(h.getAttribute("w"),10);h=parseInt(h.getAttribute("h"),10);!isNaN(g)&&!isNaN(h)&&d.comment&&d.comment.setVisible&&d.comment.setBubbleSize(g,
|
||||
Blockly.Xml.domToBlockHeadless_=function(a,b,c){var d=null,e=b.getAttribute("type");if(!e)throw"Block type unspecified: \n"+b.outerHTML;var f=b.getAttribute("id");if(c&&f){d=Blockly.Block.getById(f,a);if(!d)throw"Couldn't get Block with id: "+f;f=d.getParent();d.workspace&&d.dispose(!0,!1,!0);d.fill(a,e);d.parent_=f}else d=a.newBlock(e);for(var g=null,f=0,h;h=b.childNodes[f];f++)if(3!=h.nodeType){for(var k=g=null,l=0,p;p=h.childNodes[l];l++)1==p.nodeType&&("block"==p.nodeName.toLowerCase()?g=p:"shadow"==
|
||||
p.nodeName.toLowerCase()&&(k=p));!g&&k&&(g=k);l=h.getAttribute("name");switch(h.nodeName.toLowerCase()){case "mutation":d.domToMutation&&(d.domToMutation(h),d.initSvg&&d.initSvg());break;case "comment":d.setCommentText(h.textContent);var m=h.getAttribute("pinned");m&&setTimeout(function(){d.comment&&d.comment.setVisible&&d.comment.setVisible("true"==m)},1);g=parseInt(h.getAttribute("w"),10);h=parseInt(h.getAttribute("h"),10);!isNaN(g)&&!isNaN(h)&&d.comment&&d.comment.setVisible&&d.comment.setBubbleSize(g,
|
||||
h);break;case "data":d.data=h.textContent;break;case "title":case "field":g=d.getField(l);if(!g){console.warn("Ignoring non-existent field "+l+" in block "+e);break}g.setValue(h.textContent);break;case "value":case "statement":h=d.getInput(l);if(!h){console.warn("Ignoring non-existent input "+l+" in block "+e);break}k&&h.connection.setShadowDom(k);if(g)if(g=Blockly.Xml.domToBlockHeadless_(a,g,c),g.outputConnection)h.connection.connect(g.outputConnection);else if(g.previousConnection)h.connection.connect(g.previousConnection);
|
||||
else throw"Child block does not have output or previous statement.";break;case "next":k&&d.nextConnection&&d.nextConnection.setShadowDom(k);if(g){if(!d.nextConnection)throw"Next statement does not exist.";if(d.nextConnection.targetConnection)throw"Next statement is already connected.";g=Blockly.Xml.domToBlockHeadless_(a,g,c);if(!g.previousConnection)throw"Next block does not have previous statement.";d.nextConnection.connect(g.previousConnection)}break;default:console.warn("Ignoring unknown tag: "+
|
||||
h.nodeName)}}(a=b.getAttribute("inline"))&&d.setInputsInline("true"==a);(a=b.getAttribute("disabled"))&&d.setDisabled("true"==a);(a=b.getAttribute("deletable"))&&d.setDeletable("true"==a);(a=b.getAttribute("movable"))&&d.setMovable("true"==a);(a=b.getAttribute("editable"))&&d.setEditable("true"==a);(a=b.getAttribute("collapsed"))&&d.setCollapsed("true"==a);"shadow"==b.nodeName.toLowerCase()&&d.setShadow(!0);d.validate&&d.validate();return d};
|
||||
|
@ -987,7 +988,7 @@ Blockly.WorkspaceSvg.prototype.createDom=function(a){this.svgGroup_=Blockly.crea
|
|||
this.svgGroup_,this);a=Blockly.Scrollbar.scrollbarThickness;this.options.hasTrashcan&&(a=this.addTrashcan_(a));this.options.zoomOptions&&this.options.zoomOptions.controls&&(a=this.addZoomControls_(a));Blockly.bindEvent_(this.svgGroup_,"mousedown",this,this.onMouseDown_);var b=this;Blockly.bindEvent_(this.svgGroup_,"touchstart",null,function(a){Blockly.longStart_(a,b)});this.options.zoomOptions&&this.options.zoomOptions.wheel&&Blockly.bindEvent_(this.svgGroup_,"wheel",this,this.onMouseWheel_);this.options.hasCategories?
|
||||
this.toolbox_=new Blockly.Toolbox(this):this.options.languageTree&&this.addFlyout_();this.updateGridPattern_();return this.svgGroup_};
|
||||
Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;Blockly.unbindEvent_(this.eventWrappers_);Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(goog.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.svgBubbleCanvas_=this.svgBlockCanvas_=null;this.toolbox_&&(this.toolbox_.dispose(),this.toolbox_=null);this.flyout_&&(this.flyout_.dispose(),this.flyout_=null);this.trashcan&&(this.trashcan.dispose(),this.trashcan=null);this.scrollbar&&(this.scrollbar.dispose(),
|
||||
this.scrollbar=null);this.zoomControls_&&(this.zoomControls_.dispose(),this.zoomControls_=null);this.options.parentWorkspace||goog.dom.removeNode(this.options.svg)};Blockly.WorkspaceSvg.prototype.addTrashcan_=function(a){this.trashcan=new Blockly.Trashcan(this);var b=this.trashcan.createDom();this.svgGroup_.insertBefore(b,this.svgBlockCanvas_);return this.trashcan.init(a)};
|
||||
this.scrollbar=null);this.zoomControls_&&(this.zoomControls_.dispose(),this.zoomControls_=null);this.options.parentWorkspace||goog.dom.removeNode(this.options.svg)};Blockly.WorkspaceSvg.prototype.newBlock=function(a){return new Blockly.BlockSvg(this,a)};Blockly.WorkspaceSvg.prototype.addTrashcan_=function(a){this.trashcan=new Blockly.Trashcan(this);var b=this.trashcan.createDom();this.svgGroup_.insertBefore(b,this.svgBlockCanvas_);return this.trashcan.init(a)};
|
||||
Blockly.WorkspaceSvg.prototype.addZoomControls_=function(a){this.zoomControls_=new Blockly.ZoomControls(this);var b=this.zoomControls_.createDom();this.svgGroup_.appendChild(b);return this.zoomControls_.init(a)};Blockly.WorkspaceSvg.prototype.addFlyout_=function(){this.flyout_=new Blockly.Flyout({disabledPatternId:this.options.disabledPatternId,parentWorkspace:this,RTL:this.RTL});this.flyout_.autoClose=!1;var a=this.flyout_.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_)};
|
||||
Blockly.WorkspaceSvg.prototype.resize=function(){this.toolbox_&&this.toolbox_.position();this.flyout_&&this.flyout_.position();this.trashcan&&this.trashcan.position();this.zoomControls_&&this.zoomControls_.position();this.scrollbar&&this.scrollbar.resize()};Blockly.WorkspaceSvg.prototype.getCanvas=function(){return this.svgBlockCanvas_};Blockly.WorkspaceSvg.prototype.getBubbleCanvas=function(){return this.svgBubbleCanvas_};
|
||||
Blockly.WorkspaceSvg.prototype.translate=function(a,b){var c="translate("+a+","+b+") scale("+this.scale+")";this.svgBlockCanvas_.setAttribute("transform",c);this.svgBubbleCanvas_.setAttribute("transform",c)};Blockly.WorkspaceSvg.prototype.addTopBlock=function(a){Blockly.WorkspaceSvg.superClass_.addTopBlock.call(this,a);Blockly.Realtime.isEnabled()&&!this.options.parentWorkspace&&Blockly.Realtime.addTopBlock(a)};
|
||||
|
@ -1020,16 +1021,15 @@ Blockly.Mutator.prototype.createEditor_=function(){this.svgDialog_=Blockly.creat
|
|||
getMetrics:function(){return d.getFlyoutMetrics_()},setMetrics:null,svg:this.svgDialog_});this.svgDialog_.appendChild(this.workspace_.createDom("blocklyMutatorBackground"));return this.svgDialog_};Blockly.Mutator.prototype.updateEditable=function(){this.block_.isEditable()?Blockly.Icon.prototype.updateEditable.call(this):(this.setVisible(!1),this.iconGroup_&&Blockly.addClass_(this.iconGroup_,"blocklyIconGroupReadonly"))};
|
||||
Blockly.Mutator.prototype.resizeBubble_=function(){var a=2*Blockly.Bubble.BORDER_WIDTH,b=this.workspace_.getCanvas().getBBox(),c;c=this.block_.RTL?-b.x:b.width+b.x;b=b.height+3*a;if(this.workspace_.flyout_)var d=this.workspace_.flyout_.getMetrics_(),b=Math.max(b,d.contentHeight+20);c+=3*a;if(Math.abs(this.workspaceWidth_-c)>a||Math.abs(this.workspaceHeight_-b)>a)this.workspaceWidth_=c,this.workspaceHeight_=b,this.bubble_.setBubbleSize(c+a,b+a),this.svgDialog_.setAttribute("width",this.workspaceWidth_),
|
||||
this.svgDialog_.setAttribute("height",this.workspaceHeight_);this.block_.RTL&&(a="translate("+this.workspaceWidth_+",0)",this.workspace_.getCanvas().setAttribute("transform",a));this.workspace_.resize()};
|
||||
Blockly.Mutator.prototype.setVisible=function(a){if(a!=this.isVisible())if(a){this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconX_,this.iconY_,null,null);var b=this;if(a=this.workspace_.options.languageTree)this.workspace_.flyout_.init(this.workspace_),this.workspace_.flyout_.show(a.childNodes);this.rootBlock_=this.block_.decompose(this.workspace_);a=this.rootBlock_.getDescendants();for(var c=0,d;d=a[c];c++)d.render();this.rootBlock_.setMovable(!1);
|
||||
this.rootBlock_.setDeletable(!1);this.workspace_.flyout_?(a=2*this.workspace_.flyout_.CORNER_RADIUS,c=this.workspace_.flyout_.width_+a):c=a=16;this.block_.RTL&&(c=-c);this.rootBlock_.moveBy(c,a);this.block_.saveConnections&&(this.block_.saveConnections(this.rootBlock_),this.sourceListener_=Blockly.bindEvent_(this.block_.workspace.getCanvas(),"blocklyWorkspaceChange",this.block_,function(){b.block_.saveConnections(b.rootBlock_)}));this.resizeBubble_();Blockly.bindEvent_(this.workspace_.getCanvas(),
|
||||
"blocklyWorkspaceChange",this.block_,function(){b.workspaceChanged_()});this.updateColour()}else this.svgDialog_=null,this.workspace_.dispose(),this.rootBlock_=this.workspace_=null,this.bubble_.dispose(),this.bubble_=null,this.workspaceHeight_=this.workspaceWidth_=0,this.sourceListener_&&(Blockly.unbindEvent_(this.sourceListener_),this.sourceListener_=null)};
|
||||
Blockly.Mutator.prototype.setVisible=function(a){if(a!=this.isVisible())if(a){this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconX_,this.iconY_,null,null);if(a=this.workspace_.options.languageTree)this.workspace_.flyout_.init(this.workspace_),this.workspace_.flyout_.show(a.childNodes);this.rootBlock_=this.block_.decompose(this.workspace_);a=this.rootBlock_.getDescendants();for(var b=0,c;c=a[b];b++)c.render();this.rootBlock_.setMovable(!1);this.rootBlock_.setDeletable(!1);
|
||||
this.workspace_.flyout_?(a=2*this.workspace_.flyout_.CORNER_RADIUS,b=this.workspace_.flyout_.width_+a):b=a=16;this.block_.RTL&&(b=-b);this.rootBlock_.moveBy(b,a);if(this.block_.saveConnections){var d=this;this.block_.saveConnections(this.rootBlock_);this.sourceListener_=Blockly.bindEvent_(this.block_.workspace.getCanvas(),"blocklyWorkspaceChange",null,function(){d.block_.saveConnections(d.rootBlock_)})}this.resizeBubble_();Blockly.bindEvent_(this.workspace_.getCanvas(),"blocklyWorkspaceChange",this,
|
||||
this.workspaceChanged_);this.updateColour()}else this.svgDialog_=null,this.workspace_.dispose(),this.rootBlock_=this.workspace_=null,this.bubble_.dispose(),this.bubble_=null,this.workspaceHeight_=this.workspaceWidth_=0,this.sourceListener_&&(Blockly.unbindEvent_(this.sourceListener_),this.sourceListener_=null)};
|
||||
Blockly.Mutator.prototype.workspaceChanged_=function(){if(0==Blockly.dragMode_)for(var a=this.workspace_.getTopBlocks(!1),b=0,c;c=a[b];b++){var d=c.getRelativeToSurfaceXY(),e=c.getHeightWidth();20>d.y+e.height&&c.moveBy(0,20-e.height-d.y)}this.rootBlock_.workspace==this.workspace_&&(a=this.block_.rendered,this.block_.rendered=!1,this.block_.compose(this.rootBlock_),this.block_.rendered=a,this.block_.initSvg(),this.block_.rendered&&this.block_.render(),this.resizeBubble_(),this.block_.workspace.fireChangeEvent(),
|
||||
goog.Timer.callOnce(this.block_.bumpNeighbours_,Blockly.BUMP_DELAY,this.block_))};Blockly.Mutator.prototype.getFlyoutMetrics_=function(){return{viewHeight:this.workspaceHeight_,viewWidth:this.workspaceWidth_,absoluteTop:0,absoluteLeft:0}};Blockly.Mutator.prototype.dispose=function(){this.block_.mutator=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Warning=function(a){Blockly.Warning.superClass_.constructor.call(this,a);this.createIcon();this.text_={}};goog.inherits(Blockly.Warning,Blockly.Icon);Blockly.Warning.prototype.collapseHidden=!1;Blockly.Warning.prototype.png_="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAANyAAADcgBffIlqAAAAAd0SU1FB98DGgApDBpIGrEAAAGfSURBVDjLnZM9S2NREIbfc2P8AF27BXshpIzK5g9ssUj8C2tnYyUoiBGSyk4sbCLs1vkRgoW1jYWFICwsMV2Se3JPboLe+FhcNCZcjXFgOMzHeec9M2ekDwTIAEUgo68IsOQczdNTIudoAksTg/g+5+UyDxKUyzz4PueTsvhZr+NmZkCC6Wmo1QiAX58FmLKWf4VCDPCiGxtgLf+B9FiQXo+9y0ucBIUCnJ3B+noMdHGBC0P2xrH4HoYEmUx8qVQCgMPD2F5ehjDEjTbZe2s4p5NKRenb2+Qid3dSpaK0tTp+j8VKq0VncXHQh2IxZrK/P/AtLECjQQf4McQEMNbq786O5qwdANfr8Xl/P/AFgbS7qzlr9Qcwr4EoYvPmBud5wxPJ5+HqCtbWhv3GwPU1Lor4/fKMeedo5vPDiRKsrsLWFuRyybFOhxbwTd0upWqVcDQpaTqjWq0SdruU5PvUkiol/ZNRzeXA96mp3aaRzSYnjdNsFtptGiYI2PY8HaVSmu33xWf3K5WS6ffVe3rSgXnzT+YlpSfY00djjJOkZ/wpr41bQMIsAAAAAElFTkSuQmCC";
|
||||
Blockly.Warning.textToDom_=function(a){var b=Blockly.createSvgElement("text",{"class":"blocklyText blocklyBubbleText",y:Blockly.Bubble.BORDER_WIDTH},null);a=a.split("\n");for(var c=0;c<a.length;c++){var d=Blockly.createSvgElement("tspan",{dy:"1em",x:Blockly.Bubble.BORDER_WIDTH},b),e=document.createTextNode(a[c]);d.appendChild(e)}return b};
|
||||
Blockly.Warning.prototype.setVisible=function(a){if(a!=this.isVisible())if(a){a=Blockly.Warning.textToDom_(this.getText());this.bubble_=new Blockly.Bubble(this.block_.workspace,a,this.block_.svgPath_,this.iconX_,this.iconY_,null,null);if(this.block_.RTL)for(var b=a.getBBox().width,c=0,d;d=a.childNodes[c];c++)d.setAttribute("text-anchor","end"),d.setAttribute("x",b+Blockly.Bubble.BORDER_WIDTH);this.updateColour();a=this.bubble_.getBubbleSize();this.bubble_.setBubbleSize(a.width,a.height)}else this.bubble_.dispose(),
|
||||
this.body_=this.bubble_=null};Blockly.Warning.prototype.bodyFocus_=function(a){this.bubble_.promote_()};Blockly.Warning.prototype.setText=function(a,b){this.text_[b]!=a&&(a?this.text_[b]=a:delete this.text_[b],this.isVisible()&&(this.setVisible(!1),this.setVisible(!0)))};Blockly.Warning.prototype.getText=function(){var a=[],b;for(b in this.text_)a.push(this.text_[b]);return a.join("\n")};Blockly.Warning.prototype.dispose=function(){this.block_.warning=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Block=function(){goog.asserts.assert(0==arguments.length,"Please use Blockly.Block.obtain.")};Blockly.Block.obtain=function(a,b){if(Blockly.Realtime.isEnabled())return Blockly.Realtime.obtainBlock(a,b);var c=a.rendered?new Blockly.BlockSvg:new Blockly.Block;c.initialize(a,b);return c};Blockly.Block.prototype.data=null;Blockly.Block.prototype.initialize=function(a,b){this.id=Blockly.Blocks.genUid();a.addTopBlock(this);this.fill(a,b)};
|
||||
Blockly.Block.prototype.fill=function(a,b){this.previousConnection=this.nextConnection=this.outputConnection=null;this.inputList=[];this.inputsInline=void 0;this.disabled=this.rendered=!1;this.tooltip="";this.contextMenu=!0;this.parentBlock_=null;this.childBlocks_=[];this.editable_=this.movable_=this.deletable_=!0;this.collapsed_=this.isShadow_=!1;this.comment=null;this.xy_=new goog.math.Coordinate(0,0);this.workspace=a;this.isInFlyout=a.isFlyout;this.RTL=a.RTL;if(b){this.type=b;var c=Blockly.Blocks[b];
|
||||
goog.asserts.assertObject(c,'Error: "%s" is an unknown language block.',b);goog.mixin(this,c)}goog.isFunction(this.init)&&this.init();this.inputsInlineDefault=this.inputsInline};Blockly.Block.getById=function(a,b){return Blockly.Realtime.isEnabled()?Blockly.Realtime.getBlockById(a):b.getBlockById(a)};
|
||||
this.body_=this.bubble_=null};Blockly.Warning.prototype.bodyFocus_=function(a){this.bubble_.promote_()};Blockly.Warning.prototype.setText=function(a,b){this.text_[b]!=a&&(a?this.text_[b]=a:delete this.text_[b],this.isVisible()&&(this.setVisible(!1),this.setVisible(!0)))};Blockly.Warning.prototype.getText=function(){var a=[],b;for(b in this.text_)a.push(this.text_[b]);return a.join("\n")};Blockly.Warning.prototype.dispose=function(){this.block_.warning=null;Blockly.Icon.prototype.dispose.call(this)};Blockly.Block=function(a,b){this.id=Blockly.genUid();this.previousConnection=this.nextConnection=this.outputConnection=null;this.inputList=[];this.inputsInline=void 0;this.disabled=this.rendered=!1;this.tooltip="";this.contextMenu=!0;this.parentBlock_=null;this.childBlocks_=[];this.editable_=this.movable_=this.deletable_=!0;this.collapsed_=this.isShadow_=!1;this.comment=null;this.xy_=new goog.math.Coordinate(0,0);this.workspace=a;this.isInFlyout=a.isFlyout;this.RTL=a.RTL;if(b){this.type=b;var c=Blockly.Blocks[b];
|
||||
goog.asserts.assertObject(c,'Error: "%s" is an unknown language block.',b);goog.mixin(this,c)}a.addTopBlock(this);goog.isFunction(this.init)&&this.init();this.inputsInlineDefault=this.inputsInline};Blockly.Block.obtain=function(a,b){console.warn("Deprecated call to Blockly.Block.obtain, use workspace.newBlock instead.");return a.newBlock(b)};Blockly.Block.prototype.data=null;Blockly.Block.getById=function(a,b){return Blockly.Realtime.isEnabled()?Blockly.Realtime.getBlockById(a):b.getBlockById(a)};
|
||||
Blockly.Block.prototype.dispose=function(a,b,c){this.unplug(a,!1);this.workspace&&!c&&(this.workspace.removeTopBlock(this),this.workspace=null);Blockly.selected==this&&(Blockly.selected=null);for(a=this.childBlocks_.length-1;0<=a;a--)this.childBlocks_[a].dispose(!1);for(a=0;b=this.inputList[a];a++)b.dispose();this.inputList.length=0;b=this.getConnections_(!0);for(a=0;a<b.length;a++)c=b[a],c.targetConnection&&c.disconnect(),b[a].dispose();Blockly.Realtime.isEnabled()&&!Blockly.Realtime.withinSync&&
|
||||
Blockly.Realtime.removeBlock(this)};
|
||||
Blockly.Block.prototype.unplug=function(a,b){b=b&&!!this.getParent();if(this.outputConnection)this.outputConnection.targetConnection&&this.setParent(null);else{var c=null;this.previousConnection&&this.previousConnection.targetConnection&&(c=this.previousConnection.targetConnection,this.setParent(null));var d=this.getNextBlock();if(a&&d){var e=this.nextConnection.targetConnection;d.setParent(null);c&&c.checkType_(e)&&c.connect(e)}}b&&this.moveBy(Blockly.SNAP_RADIUS*(this.RTL?-1:1),2*Blockly.SNAP_RADIUS)};
|
||||
|
@ -1066,8 +1066,8 @@ Blockly.Block.prototype.getInputTargetBlock=function(a){return(a=this.getInput(a
|
|||
Blockly.Block.prototype.moveBy=function(a,b){this.xy_.translate(a,b)};Blockly.ContextMenu={};Blockly.ContextMenu.currentBlock=null;
|
||||
Blockly.ContextMenu.show=function(a,b,c){Blockly.WidgetDiv.show(Blockly.ContextMenu,c,null);if(b.length){var d=new goog.ui.Menu;d.setRightToLeft(c);for(var e=0,f;f=b[e];e++){var g=new goog.ui.MenuItem(f.text);g.setRightToLeft(c);d.addChild(g,!0);g.setEnabled(f.enabled);f.enabled&&goog.events.listen(g,goog.ui.Component.EventType.ACTION,function(a){return function(){Blockly.doCommand(a)}}(f.callback))}goog.events.listen(d,goog.ui.Component.EventType.ACTION,Blockly.ContextMenu.hide);b=goog.dom.getViewportSize();
|
||||
f=goog.style.getViewportPageOffset(document);d.render(Blockly.WidgetDiv.DIV);var h=d.getElement();Blockly.addClass_(h,"blocklyContextMenu");var g=goog.style.getSize(h),e=a.clientX+f.x,k=a.clientY+f.y;a.clientY+g.height>=b.height&&(k-=g.height);c?g.width>=a.clientX&&(e+=g.width):a.clientX+g.width>=b.width&&(e-=g.width);Blockly.WidgetDiv.position(e,k,b,f,c);d.setAllowAutoFocus(!0);setTimeout(function(){h.focus()},1);Blockly.ContextMenu.currentBlock=null}else Blockly.ContextMenu.hide()};
|
||||
Blockly.ContextMenu.hide=function(){Blockly.WidgetDiv.hideIfOwner(Blockly.ContextMenu);Blockly.ContextMenu.currentBlock=null};Blockly.ContextMenu.callbackFactory=function(a,b){return function(){var c=Blockly.Xml.domToBlock(a.workspace,b),d=a.getRelativeToSurfaceXY();d.x=a.RTL?d.x-Blockly.SNAP_RADIUS:d.x+Blockly.SNAP_RADIUS;d.y+=2*Blockly.SNAP_RADIUS;c.moveBy(d.x,d.y);c.select()}};Blockly.BlockSvg=function(){this.svgGroup_=Blockly.createSvgElement("g",{},null);this.svgPathDark_=Blockly.createSvgElement("path",{"class":"blocklyPathDark",transform:"translate(1,1)"},this.svgGroup_);this.svgPath_=Blockly.createSvgElement("path",{"class":"blocklyPath"},this.svgGroup_);this.svgPathLight_=Blockly.createSvgElement("path",{"class":"blocklyPathLight"},this.svgGroup_);this.svgPath_.tooltip=this;Blockly.Tooltip.bindMouseEvents(this.svgPath_)};goog.inherits(Blockly.BlockSvg,Blockly.Block);
|
||||
Blockly.BlockSvg.prototype.height=0;Blockly.BlockSvg.prototype.width=0;Blockly.BlockSvg.prototype.dragStartXY_=null;Blockly.BlockSvg.INLINE=-1;
|
||||
Blockly.ContextMenu.hide=function(){Blockly.WidgetDiv.hideIfOwner(Blockly.ContextMenu);Blockly.ContextMenu.currentBlock=null};Blockly.ContextMenu.callbackFactory=function(a,b){return function(){var c=Blockly.Xml.domToBlock(a.workspace,b),d=a.getRelativeToSurfaceXY();d.x=a.RTL?d.x-Blockly.SNAP_RADIUS:d.x+Blockly.SNAP_RADIUS;d.y+=2*Blockly.SNAP_RADIUS;c.moveBy(d.x,d.y);c.select()}};Blockly.BlockSvg=function(a,b){Blockly.BlockSvg.superClass_.constructor.call(this,a,b);this.svgGroup_=Blockly.createSvgElement("g",{},null);this.svgPathDark_=Blockly.createSvgElement("path",{"class":"blocklyPathDark",transform:"translate(1,1)"},this.svgGroup_);this.svgPath_=Blockly.createSvgElement("path",{"class":"blocklyPath"},this.svgGroup_);this.svgPathLight_=Blockly.createSvgElement("path",{"class":"blocklyPathLight"},this.svgGroup_);this.svgPath_.tooltip=this;Blockly.Tooltip.bindMouseEvents(this.svgPath_)};
|
||||
goog.inherits(Blockly.BlockSvg,Blockly.Block);Blockly.BlockSvg.prototype.height=0;Blockly.BlockSvg.prototype.width=0;Blockly.BlockSvg.prototype.dragStartXY_=null;Blockly.BlockSvg.INLINE=-1;
|
||||
Blockly.BlockSvg.prototype.initSvg=function(){goog.asserts.assert(this.workspace.rendered,"Workspace is headless.");for(var a=0,b;b=this.inputList[a];a++)b.init();this.mutator&&this.mutator.createIcon();this.updateColour();this.updateMovable();if(!this.workspace.options.readOnly&&!this.eventsInit_){Blockly.bindEvent_(this.getSvgRoot(),"mousedown",this,this.onMouseDown_);var c=this;Blockly.bindEvent_(this.getSvgRoot(),"touchstart",null,function(a){Blockly.longStart_(a,c)})}goog.isFunction(this.onchange)&&
|
||||
!this.eventsInit_&&(this.onchangeWrapper_=Blockly.bindEvent_(this.workspace.getCanvas(),"blocklyWorkspaceChange",this,this.onchange));this.eventsInit_=!0;this.getSvgRoot().parentNode||this.workspace.getCanvas().appendChild(this.getSvgRoot())};Blockly.BlockSvg.prototype.select=function(){Blockly.selected&&Blockly.selected.unselect();Blockly.selected=this;this.addSelect();Blockly.fireUiEvent(this.workspace.getCanvas(),"blocklySelectChange")};
|
||||
Blockly.BlockSvg.prototype.unselect=function(){Blockly.selected=null;this.removeSelect();Blockly.fireUiEvent(this.workspace.getCanvas(),"blocklySelectChange")};Blockly.BlockSvg.prototype.mutator=null;Blockly.BlockSvg.prototype.comment=null;Blockly.BlockSvg.prototype.warning=null;Blockly.BlockSvg.prototype.getIcons=function(){var a=[];this.mutator&&a.push(this.mutator);this.comment&&a.push(this.comment);this.warning&&a.push(this.warning);return a};Blockly.BlockSvg.onMouseUpWrapper_=null;
|
||||
|
|
|
@ -94,12 +94,11 @@ Blockly.Blocks['lists_create_with'] = {
|
|||
* @this Blockly.Block
|
||||
*/
|
||||
decompose: function(workspace) {
|
||||
var containerBlock =
|
||||
Blockly.Block.obtain(workspace, 'lists_create_with_container');
|
||||
var containerBlock = workspace.newBlock('lists_create_with_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = Blockly.Block.obtain(workspace, 'lists_create_with_item');
|
||||
var itemBlock = workspace.newBlock('lists_create_with_item');
|
||||
itemBlock.initSvg();
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
|
|
|
@ -113,17 +113,17 @@ Blockly.Blocks['controls_if'] = {
|
|||
* @this Blockly.Block
|
||||
*/
|
||||
decompose: function(workspace) {
|
||||
var containerBlock = Blockly.Block.obtain(workspace, 'controls_if_if');
|
||||
var containerBlock = workspace.newBlock('controls_if_if');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 1; i <= this.elseifCount_; i++) {
|
||||
var elseifBlock = Blockly.Block.obtain(workspace, 'controls_if_elseif');
|
||||
var elseifBlock = workspace.newBlock('controls_if_elseif');
|
||||
elseifBlock.initSvg();
|
||||
connection.connect(elseifBlock.previousConnection);
|
||||
connection = elseifBlock.nextConnection;
|
||||
}
|
||||
if (this.elseCount_) {
|
||||
var elseBlock = Blockly.Block.obtain(workspace, 'controls_if_else');
|
||||
var elseBlock = workspace.newBlock('controls_if_else');
|
||||
elseBlock.initSvg();
|
||||
connection.connect(elseBlock.previousConnection);
|
||||
}
|
||||
|
|
|
@ -159,8 +159,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
|||
* @this Blockly.Block
|
||||
*/
|
||||
decompose: function(workspace) {
|
||||
var containerBlock = Blockly.Block.obtain(workspace,
|
||||
'procedures_mutatorcontainer');
|
||||
var containerBlock = workspace.newBlock('procedures_mutatorcontainer');
|
||||
containerBlock.initSvg();
|
||||
|
||||
// Check/uncheck the allow statement box.
|
||||
|
@ -174,7 +173,7 @@ Blockly.Blocks['procedures_defnoreturn'] = {
|
|||
// Parameter list.
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.arguments_.length; i++) {
|
||||
var paramBlock = Blockly.Block.obtain(workspace, 'procedures_mutatorarg');
|
||||
var paramBlock = workspace.newBlock('procedures_mutatorarg');
|
||||
paramBlock.initSvg();
|
||||
paramBlock.setFieldValue(this.arguments_[i], 'NAME');
|
||||
// Store the old location.
|
||||
|
|
|
@ -106,12 +106,11 @@ Blockly.Blocks['text_join'] = {
|
|||
* @this Blockly.Block
|
||||
*/
|
||||
decompose: function(workspace) {
|
||||
var containerBlock = Blockly.Block.obtain(workspace,
|
||||
'text_create_join_container');
|
||||
var containerBlock = workspace.newBlock('text_create_join_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = Blockly.Block.obtain(workspace, 'text_create_join_item');
|
||||
var itemBlock = workspace.newBlock('text_create_join_item');
|
||||
itemBlock.initSvg();
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
|
|
|
@ -10,8 +10,8 @@ this.setOutput(!0,"Colour");this.setTooltip(Blockly.Msg.COLOUR_RGB_TOOLTIP)}};
|
|||
Blockly.Blocks.colour_blend={init:function(){this.setHelpUrl(Blockly.Msg.COLOUR_BLEND_HELPURL);this.setColour(Blockly.Blocks.colour.HUE);this.appendValueInput("COLOUR1").setCheck("Colour").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_BLEND_TITLE).appendField(Blockly.Msg.COLOUR_BLEND_COLOUR1);this.appendValueInput("COLOUR2").setCheck("Colour").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_BLEND_COLOUR2);this.appendValueInput("RATIO").setCheck("Number").setAlign(Blockly.ALIGN_RIGHT).appendField(Blockly.Msg.COLOUR_BLEND_RATIO);
|
||||
this.setOutput(!0,"Colour");this.setTooltip(Blockly.Msg.COLOUR_BLEND_TOOLTIP)}};Blockly.Blocks.lists={};Blockly.Blocks.lists.HUE=260;Blockly.Blocks.lists_create_empty={init:function(){this.jsonInit({message0:Blockly.Msg.LISTS_CREATE_EMPTY_TITLE,output:"Array",colour:Blockly.Blocks.lists.HUE,tooltip:Blockly.Msg.LISTS_CREATE_EMPTY_TOOLTIP,helpUrl:Blockly.Msg.LISTS_CREATE_EMPTY_HELPURL})}};
|
||||
Blockly.Blocks.lists_create_with={init:function(){this.setHelpUrl(Blockly.Msg.LISTS_CREATE_WITH_HELPURL);this.setColour(Blockly.Blocks.lists.HUE);this.itemCount_=3;this.updateShape_();this.setOutput(!0,"Array");this.setMutator(new Blockly.Mutator(["lists_create_with_item"]));this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_TOOLTIP)},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("items",this.itemCount_);return a},domToMutation:function(a){this.itemCount_=parseInt(a.getAttribute("items"),
|
||||
10);this.updateShape_()},decompose:function(a){var b=Blockly.Block.obtain(a,"lists_create_with_container");b.initSvg();for(var c=b.getInput("STACK").connection,d=0;d<this.itemCount_;d++){var e=Blockly.Block.obtain(a,"lists_create_with_item");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();this.itemCount_=a.length;this.updateShape_();
|
||||
for(b=0;b<this.itemCount_;b++)a[b]&&this.getInput("ADD"+b).connection.connect(a[b])},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=0;a;){var c=this.getInput("ADD"+b);a.valueConnection_=c&&c.connection.targetConnection;b++;a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){if(this.getInput("EMPTY"))this.removeInput("EMPTY");else for(var a=0;this.getInput("ADD"+a);)this.removeInput("ADD"+a),a++;if(0==this.itemCount_)this.appendDummyInput("EMPTY").appendField(Blockly.Msg.LISTS_CREATE_EMPTY_TITLE);
|
||||
10);this.updateShape_()},decompose:function(a){var b=a.newBlock("lists_create_with_container");b.initSvg();for(var c=b.getInput("STACK").connection,d=0;d<this.itemCount_;d++){var e=a.newBlock("lists_create_with_item");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();this.itemCount_=a.length;this.updateShape_();for(b=0;b<this.itemCount_;b++)a[b]&&
|
||||
this.getInput("ADD"+b).connection.connect(a[b])},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=0;a;){var c=this.getInput("ADD"+b);a.valueConnection_=c&&c.connection.targetConnection;b++;a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){if(this.getInput("EMPTY"))this.removeInput("EMPTY");else for(var a=0;this.getInput("ADD"+a);)this.removeInput("ADD"+a),a++;if(0==this.itemCount_)this.appendDummyInput("EMPTY").appendField(Blockly.Msg.LISTS_CREATE_EMPTY_TITLE);
|
||||
else for(a=0;a<this.itemCount_;a++){var b=this.appendValueInput("ADD"+a);0==a&&b.appendField(Blockly.Msg.LISTS_CREATE_WITH_INPUT_WITH)}}};Blockly.Blocks.lists_create_with_container={init:function(){this.setColour(Blockly.Blocks.lists.HUE);this.appendDummyInput().appendField(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD);this.appendStatementInput("STACK");this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_CONTAINER_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.lists_create_with_item={init:function(){this.setColour(Blockly.Blocks.lists.HUE);this.appendDummyInput().appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.lists_repeat={init:function(){this.jsonInit({message0:Blockly.Msg.LISTS_REPEAT_TITLE,args0:[{type:"input_value",name:"ITEM"},{type:"input_value",name:"NUM",check:"Number"}],output:"Array",colour:Blockly.Blocks.lists.HUE,tooltip:Blockly.Msg.LISTS_REPEAT_TOOLTIP,helpUrl:Blockly.Msg.LISTS_REPEAT_HELPURL})}};
|
||||
|
@ -36,11 +36,11 @@ this.setOutput(!0,"Array");this.setTooltip(function(){var b=a.getFieldValue("MOD
|
|||
this.getFieldValue("MODE"));return a},domToMutation:function(a){this.updateType_(a.getAttribute("mode"))}};Blockly.Blocks.logic={};Blockly.Blocks.logic.HUE=210;
|
||||
Blockly.Blocks.controls_if={init:function(){this.setHelpUrl(Blockly.Msg.CONTROLS_IF_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.appendValueInput("IF0").setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_IF);this.appendStatementInput("DO0").appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setMutator(new Blockly.Mutator(["controls_if_elseif","controls_if_else"]));var a=this;this.setTooltip(function(){if(a.elseifCount_||a.elseCount_){if(!a.elseifCount_&&
|
||||
a.elseCount_)return Blockly.Msg.CONTROLS_IF_TOOLTIP_2;if(a.elseifCount_&&!a.elseCount_)return Blockly.Msg.CONTROLS_IF_TOOLTIP_3;if(a.elseifCount_&&a.elseCount_)return Blockly.Msg.CONTROLS_IF_TOOLTIP_4}else return Blockly.Msg.CONTROLS_IF_TOOLTIP_1;return""});this.elseCount_=this.elseifCount_=0},mutationToDom:function(){if(!this.elseifCount_&&!this.elseCount_)return null;var a=document.createElement("mutation");this.elseifCount_&&a.setAttribute("elseif",this.elseifCount_);this.elseCount_&&a.setAttribute("else",
|
||||
1);return a},domToMutation:function(a){this.elseifCount_=parseInt(a.getAttribute("elseif"),10)||0;this.elseCount_=parseInt(a.getAttribute("else"),10)||0;for(a=1;a<=this.elseifCount_;a++)this.appendValueInput("IF"+a).setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF),this.appendStatementInput("DO"+a).appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);this.elseCount_&&this.appendStatementInput("ELSE").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE)},decompose:function(a){var b=Blockly.Block.obtain(a,
|
||||
"controls_if_if");b.initSvg();for(var c=b.getInput("STACK").connection,d=1;d<=this.elseifCount_;d++){var e=Blockly.Block.obtain(a,"controls_if_elseif");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}this.elseCount_&&(a=Blockly.Block.obtain(a,"controls_if_else"),a.initSvg(),c.connect(a.previousConnection));return b},compose:function(a){this.elseCount_&&this.removeInput("ELSE");this.elseCount_=0;for(var b=this.elseifCount_;0<b;b--)this.removeInput("IF"+b),this.removeInput("DO"+b);this.elseifCount_=
|
||||
0;for(a=a.getInputTargetBlock("STACK");a;){switch(a.type){case "controls_if_elseif":this.elseifCount_++;var b=this.appendValueInput("IF"+this.elseifCount_).setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF),c=this.appendStatementInput("DO"+this.elseifCount_);c.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);a.valueConnection_&&b.connection.connect(a.valueConnection_);a.statementConnection_&&c.connection.connect(a.statementConnection_);break;case "controls_if_else":this.elseCount_++;
|
||||
b=this.appendStatementInput("ELSE");b.appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE);a.statementConnection_&&b.connection.connect(a.statementConnection_);break;default:throw"Unknown block type.";}a=a.nextConnection&&a.nextConnection.targetBlock()}},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=1;a;){switch(a.type){case "controls_if_elseif":var c=this.getInput("IF"+b),d=this.getInput("DO"+b);a.valueConnection_=c&&c.connection.targetConnection;a.statementConnection_=d&&d.connection.targetConnection;
|
||||
b++;break;case "controls_if_else":d=this.getInput("ELSE");a.statementConnection_=d&&d.connection.targetConnection;break;default:throw"Unknown block type.";}a=a.nextConnection&&a.nextConnection.targetBlock()}}};Blockly.Blocks.controls_if_if={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_IF_TITLE_IF);this.appendStatementInput("STACK");this.setTooltip(Blockly.Msg.CONTROLS_IF_IF_TOOLTIP);this.contextMenu=!1}};
|
||||
1);return a},domToMutation:function(a){this.elseifCount_=parseInt(a.getAttribute("elseif"),10)||0;this.elseCount_=parseInt(a.getAttribute("else"),10)||0;for(a=1;a<=this.elseifCount_;a++)this.appendValueInput("IF"+a).setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF),this.appendStatementInput("DO"+a).appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);this.elseCount_&&this.appendStatementInput("ELSE").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE)},decompose:function(a){var b=a.newBlock("controls_if_if");
|
||||
b.initSvg();for(var c=b.getInput("STACK").connection,d=1;d<=this.elseifCount_;d++){var e=a.newBlock("controls_if_elseif");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}this.elseCount_&&(a=a.newBlock("controls_if_else"),a.initSvg(),c.connect(a.previousConnection));return b},compose:function(a){this.elseCount_&&this.removeInput("ELSE");this.elseCount_=0;for(var b=this.elseifCount_;0<b;b--)this.removeInput("IF"+b),this.removeInput("DO"+b);this.elseifCount_=0;for(a=a.getInputTargetBlock("STACK");a;){switch(a.type){case "controls_if_elseif":this.elseifCount_++;
|
||||
var b=this.appendValueInput("IF"+this.elseifCount_).setCheck("Boolean").appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSEIF),c=this.appendStatementInput("DO"+this.elseifCount_);c.appendField(Blockly.Msg.CONTROLS_IF_MSG_THEN);a.valueConnection_&&b.connection.connect(a.valueConnection_);a.statementConnection_&&c.connection.connect(a.statementConnection_);break;case "controls_if_else":this.elseCount_++;b=this.appendStatementInput("ELSE");b.appendField(Blockly.Msg.CONTROLS_IF_MSG_ELSE);a.statementConnection_&&
|
||||
b.connection.connect(a.statementConnection_);break;default:throw"Unknown block type.";}a=a.nextConnection&&a.nextConnection.targetBlock()}},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=1;a;){switch(a.type){case "controls_if_elseif":var c=this.getInput("IF"+b),d=this.getInput("DO"+b);a.valueConnection_=c&&c.connection.targetConnection;a.statementConnection_=d&&d.connection.targetConnection;b++;break;case "controls_if_else":d=this.getInput("ELSE");a.statementConnection_=d&&
|
||||
d.connection.targetConnection;break;default:throw"Unknown block type.";}a=a.nextConnection&&a.nextConnection.targetBlock()}}};Blockly.Blocks.controls_if_if={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_IF_TITLE_IF);this.appendStatementInput("STACK");this.setTooltip(Blockly.Msg.CONTROLS_IF_IF_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.controls_if_elseif={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSEIF_TITLE_ELSEIF);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.controls_if_else={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE);this.setPreviousStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.logic_compare={init:function(){var a=this.RTL?[["=","EQ"],["\u2260","NEQ"],[">","LT"],["\u2265","LTE"],["<","GT"],["\u2264","GTE"]]:[["=","EQ"],["\u2260","NEQ"],["<","LT"],["\u2264","LTE"],[">","GT"],["\u2265","GTE"]];this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendValueInput("A");this.appendValueInput("B").appendField(new Blockly.FieldDropdown(a),"OP");this.setInputsInline(!0);var b=this;this.setTooltip(function(){var a=
|
||||
|
@ -85,8 +85,8 @@ Blockly.Blocks.math_random_float={init:function(){this.setHelpUrl(Blockly.Msg.MA
|
|||
Blockly.Blocks.procedures_defnoreturn={init:function(){this.setHelpUrl(Blockly.Msg.PROCEDURES_DEFNORETURN_HELPURL);this.setColour(Blockly.Blocks.procedures.HUE);var a=new Blockly.FieldTextInput(Blockly.Msg.PROCEDURES_DEFNORETURN_PROCEDURE,Blockly.Procedures.rename);a.setSpellcheck(!1);this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_TITLE).appendField(a,"NAME").appendField("","PARAMS");this.setMutator(new Blockly.Mutator(["procedures_mutatorarg"]));this.setTooltip(Blockly.Msg.PROCEDURES_DEFNORETURN_TOOLTIP);
|
||||
this.arguments_=[];this.setStatements_(!0);this.statementConnection_=null},validate:function(){var a=Blockly.Procedures.findLegalName(this.getFieldValue("NAME"),this);this.setFieldValue(a,"NAME")},setStatements_:function(a){this.hasStatements_!==a&&(a?(this.appendStatementInput("STACK").appendField(Blockly.Msg.PROCEDURES_DEFNORETURN_DO),this.getInput("RETURN")&&this.moveInputBefore("STACK","RETURN")):this.removeInput("STACK",!0),this.hasStatements_=a)},updateParams_:function(){for(var a=!1,b={},c=
|
||||
0;c<this.arguments_.length;c++){if(b["arg_"+this.arguments_[c].toLowerCase()]){a=!0;break}b["arg_"+this.arguments_[c].toLowerCase()]=!0}a?this.setWarningText(Blockly.Msg.PROCEDURES_DEF_DUPLICATE_WARNING):this.setWarningText(null);a="";this.arguments_.length&&(a=Blockly.Msg.PROCEDURES_BEFORE_PARAMS+" "+this.arguments_.join(", "));this.setFieldValue(a,"PARAMS")},mutationToDom:function(){for(var a=document.createElement("mutation"),b=0;b<this.arguments_.length;b++){var c=document.createElement("arg");
|
||||
c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}this.hasStatements_||a.setAttribute("statements","false");return a},domToMutation:function(a){this.arguments_=[];for(var b=0,c;c=a.childNodes[b];b++)"arg"==c.nodeName.toLowerCase()&&this.arguments_.push(c.getAttribute("name"));this.updateParams_();this.setStatements_("false"!==a.getAttribute("statements"))},decompose:function(a){var b=Blockly.Block.obtain(a,"procedures_mutatorcontainer");b.initSvg();this.getInput("RETURN")?b.setFieldValue(this.hasStatements_?
|
||||
"TRUE":"FALSE","STATEMENTS"):b.getInput("STATEMENT_INPUT").setVisible(!1);for(var c=b.getInput("STACK").connection,d=0;d<this.arguments_.length;d++){var e=Blockly.Block.obtain(a,"procedures_mutatorarg");e.initSvg();e.setFieldValue(this.arguments_[d],"NAME");e.oldLocation=d;c.connect(e.previousConnection);c=e.nextConnection}Blockly.Procedures.mutateCallers(this.getFieldValue("NAME"),this.workspace,this.arguments_,null);return b},compose:function(a){this.arguments_=[];this.paramIds_=[];for(var b=a.getInputTargetBlock("STACK");b;)this.arguments_.push(b.getFieldValue("NAME")),
|
||||
c.setAttribute("name",this.arguments_[b]);a.appendChild(c)}this.hasStatements_||a.setAttribute("statements","false");return a},domToMutation:function(a){this.arguments_=[];for(var b=0,c;c=a.childNodes[b];b++)"arg"==c.nodeName.toLowerCase()&&this.arguments_.push(c.getAttribute("name"));this.updateParams_();this.setStatements_("false"!==a.getAttribute("statements"))},decompose:function(a){var b=a.newBlock("procedures_mutatorcontainer");b.initSvg();this.getInput("RETURN")?b.setFieldValue(this.hasStatements_?
|
||||
"TRUE":"FALSE","STATEMENTS"):b.getInput("STATEMENT_INPUT").setVisible(!1);for(var c=b.getInput("STACK").connection,d=0;d<this.arguments_.length;d++){var e=a.newBlock("procedures_mutatorarg");e.initSvg();e.setFieldValue(this.arguments_[d],"NAME");e.oldLocation=d;c.connect(e.previousConnection);c=e.nextConnection}Blockly.Procedures.mutateCallers(this.getFieldValue("NAME"),this.workspace,this.arguments_,null);return b},compose:function(a){this.arguments_=[];this.paramIds_=[];for(var b=a.getInputTargetBlock("STACK");b;)this.arguments_.push(b.getFieldValue("NAME")),
|
||||
this.paramIds_.push(b.id),b=b.nextConnection&&b.nextConnection.targetBlock();this.updateParams_();Blockly.Procedures.mutateCallers(this.getFieldValue("NAME"),this.workspace,this.arguments_,this.paramIds_);a=a.getFieldValue("STATEMENTS");if(null!==a&&(a="TRUE"==a,this.hasStatements_!=a))if(a)this.setStatements_(!0),a=this.getInput("STACK").connection,a.targetConnection||!this.statementConnection_||this.statementConnection_.targetConnection||this.statementConnection_.sourceBlock_.workspace!=this.workspace?
|
||||
this.statementConnection_=null:a.connect(this.statementConnection_);else{a=this.getInput("STACK").connection;if(this.statementConnection_=a.targetConnection)a=a.targetBlock(),a.setParent(null),a.bumpNeighbours_();this.setStatements_(!1)}},dispose:function(){var a=this.getFieldValue("NAME");Blockly.Procedures.disposeCallers(a,this.workspace);this.constructor.prototype.dispose.apply(this,arguments)},getProcedureDef:function(){return[this.getFieldValue("NAME"),this.arguments_,!1]},getVars:function(){return this.arguments_},
|
||||
renameVar:function(a,b){for(var c=!1,d=0;d<this.arguments_.length;d++)Blockly.Names.equals(a,this.arguments_[d])&&(this.arguments_[d]=b,c=!0);if(c&&(this.updateParams_(),this.mutator.isVisible()))for(var c=this.mutator.workspace_.getAllBlocks(),d=0,e;e=c[d];d++)"procedures_mutatorarg"==e.type&&Blockly.Names.equals(a,e.getFieldValue("NAME"))&&e.setFieldValue(b,"NAME")},customContextMenu:function(a){var b={enabled:!0},c=this.getFieldValue("NAME");b.text=Blockly.Msg.PROCEDURES_CREATE_DO.replace("%1",
|
||||
|
@ -112,8 +112,8 @@ document.createElement("mutation");a.setAttribute("value",Number(this.hasReturnV
|
|||
Blockly.Blocks.text={init:function(){this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);this.setColour(Blockly.Blocks.texts.HUE);this.appendDummyInput().appendField(this.newQuote_(!0)).appendField(new Blockly.FieldTextInput(""),"TEXT").appendField(this.newQuote_(!1));this.setOutput(!0,"String");this.setTooltip(Blockly.Msg.TEXT_TEXT_TOOLTIP)},newQuote_:function(a){return new Blockly.FieldImage(a==this.RTL?"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC",
|
||||
12,12,'"')}};
|
||||
Blockly.Blocks.text_join={init:function(){this.setHelpUrl(Blockly.Msg.TEXT_JOIN_HELPURL);this.setColour(Blockly.Blocks.texts.HUE);this.itemCount_=2;this.updateShape_();this.setOutput(!0,"String");this.setMutator(new Blockly.Mutator(["text_create_join_item"]));this.setTooltip(Blockly.Msg.TEXT_JOIN_TOOLTIP)},mutationToDom:function(){var a=document.createElement("mutation");a.setAttribute("items",this.itemCount_);return a},domToMutation:function(a){this.itemCount_=parseInt(a.getAttribute("items"),10);
|
||||
this.updateShape_()},decompose:function(a){var b=Blockly.Block.obtain(a,"text_create_join_container");b.initSvg();for(var c=b.getInput("STACK").connection,d=0;d<this.itemCount_;d++){var e=Blockly.Block.obtain(a,"text_create_join_item");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();this.itemCount_=a.length;this.updateShape_();
|
||||
for(b=0;b<this.itemCount_;b++)a[b]&&this.getInput("ADD"+b).connection.connect(a[b])},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=0;a;){var c=this.getInput("ADD"+b);a.valueConnection_=c&&c.connection.targetConnection;b++;a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){if(this.getInput("EMPTY"))this.removeInput("EMPTY");else for(var a=0;this.getInput("ADD"+a);)this.removeInput("ADD"+a),a++;if(0==this.itemCount_)this.appendDummyInput("EMPTY").appendField(this.newQuote_(!0)).appendField(this.newQuote_(!1));
|
||||
this.updateShape_()},decompose:function(a){var b=a.newBlock("text_create_join_container");b.initSvg();for(var c=b.getInput("STACK").connection,d=0;d<this.itemCount_;d++){var e=a.newBlock("text_create_join_item");e.initSvg();c.connect(e.previousConnection);c=e.nextConnection}return b},compose:function(a){var b=a.getInputTargetBlock("STACK");for(a=[];b;)a.push(b.valueConnection_),b=b.nextConnection&&b.nextConnection.targetBlock();this.itemCount_=a.length;this.updateShape_();for(b=0;b<this.itemCount_;b++)a[b]&&
|
||||
this.getInput("ADD"+b).connection.connect(a[b])},saveConnections:function(a){a=a.getInputTargetBlock("STACK");for(var b=0;a;){var c=this.getInput("ADD"+b);a.valueConnection_=c&&c.connection.targetConnection;b++;a=a.nextConnection&&a.nextConnection.targetBlock()}},updateShape_:function(){if(this.getInput("EMPTY"))this.removeInput("EMPTY");else for(var a=0;this.getInput("ADD"+a);)this.removeInput("ADD"+a),a++;if(0==this.itemCount_)this.appendDummyInput("EMPTY").appendField(this.newQuote_(!0)).appendField(this.newQuote_(!1));
|
||||
else for(a=0;a<this.itemCount_;a++){var b=this.appendValueInput("ADD"+a);0==a&&b.appendField(Blockly.Msg.TEXT_JOIN_TITLE_CREATEWITH)}},newQuote_:Blockly.Blocks.text.newQuote_};Blockly.Blocks.text_create_join_container={init:function(){this.setColour(Blockly.Blocks.texts.HUE);this.appendDummyInput().appendField(Blockly.Msg.TEXT_CREATE_JOIN_TITLE_JOIN);this.appendStatementInput("STACK");this.setTooltip(Blockly.Msg.TEXT_CREATE_JOIN_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.text_create_join_item={init:function(){this.setColour(Blockly.Blocks.texts.HUE);this.appendDummyInput().appendField(Blockly.Msg.TEXT_CREATE_JOIN_ITEM_TITLE_ITEM);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.TEXT_CREATE_JOIN_ITEM_TOOLTIP);this.contextMenu=!1}};
|
||||
Blockly.Blocks.text_append={init:function(){this.setHelpUrl(Blockly.Msg.TEXT_APPEND_HELPURL);this.setColour(Blockly.Blocks.texts.HUE);this.appendValueInput("TEXT").appendField(Blockly.Msg.TEXT_APPEND_TO).appendField(new Blockly.FieldVariable(Blockly.Msg.TEXT_APPEND_VARIABLE),"VAR").appendField(Blockly.Msg.TEXT_APPEND_APPENDTEXT);this.setPreviousStatement(!0);this.setNextStatement(!0);var a=this;this.setTooltip(function(){return Blockly.Msg.TEXT_APPEND_TOOLTIP.replace("%1",a.getFieldValue("VAR"))})},
|
||||
|
|
|
@ -41,63 +41,16 @@ goog.require('goog.string');
|
|||
|
||||
|
||||
/**
|
||||
* Class for one block.
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Block = function() {
|
||||
// We assert this here because there may be users of the previous form of
|
||||
// this constructor, which took arguments.
|
||||
goog.asserts.assert(arguments.length == 0,
|
||||
'Please use Blockly.Block.obtain.');
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtain a newly created block.
|
||||
* Class for one block.
|
||||
* Not normally called directly, workspace.newBlock() is preferred.
|
||||
* @param {!Blockly.Workspace} workspace The block's workspace.
|
||||
* @param {?string} prototypeName Name of the language object containing
|
||||
* type-specific functions for this block.
|
||||
* @return {!Blockly.Block} The created block
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.Block.obtain = function(workspace, prototypeName) {
|
||||
if (Blockly.Realtime.isEnabled()) {
|
||||
return Blockly.Realtime.obtainBlock(workspace, prototypeName);
|
||||
} else {
|
||||
if (workspace.rendered) {
|
||||
var newBlock = new Blockly.BlockSvg();
|
||||
} else {
|
||||
var newBlock = new Blockly.Block();
|
||||
}
|
||||
newBlock.initialize(workspace, prototypeName);
|
||||
return newBlock;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Optional text data that round-trips beween blocks and XML.
|
||||
* Has no effect. May be used by 3rd parties for meta information.
|
||||
* @type {?string}
|
||||
*/
|
||||
Blockly.Block.prototype.data = null;
|
||||
|
||||
/**
|
||||
* Initialization for one block.
|
||||
* @param {!Blockly.Workspace} workspace The new block's workspace.
|
||||
* @param {?string} prototypeName Name of the language object containing
|
||||
* type-specific functions for this block.
|
||||
*/
|
||||
Blockly.Block.prototype.initialize = function(workspace, prototypeName) {
|
||||
Blockly.Block = function(workspace, prototypeName) {
|
||||
/** @type {string} */
|
||||
this.id = Blockly.Blocks.genUid();
|
||||
workspace.addTopBlock(this);
|
||||
this.fill(workspace, prototypeName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fill a block with initial values.
|
||||
* @param {!Blockly.Workspace} workspace The workspace to use.
|
||||
* @param {string} prototypeName The typename of the block.
|
||||
*/
|
||||
Blockly.Block.prototype.fill = function(workspace, prototypeName) {
|
||||
this.id = Blockly.genUid();
|
||||
/** @type {Blockly.Connection} */
|
||||
this.outputConnection = null;
|
||||
/** @type {Blockly.Connection} */
|
||||
|
@ -154,6 +107,9 @@ Blockly.Block.prototype.fill = function(workspace, prototypeName) {
|
|||
'Error: "%s" is an unknown language block.', prototypeName);
|
||||
goog.mixin(this, prototype);
|
||||
}
|
||||
|
||||
workspace.addTopBlock(this);
|
||||
|
||||
// Call an initialization function, if it exists.
|
||||
if (goog.isFunction(this.init)) {
|
||||
this.init();
|
||||
|
@ -163,6 +119,27 @@ Blockly.Block.prototype.fill = function(workspace, prototypeName) {
|
|||
this.inputsInlineDefault = this.inputsInline;
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtain a newly created block.
|
||||
* @param {!Blockly.Workspace} workspace The block's workspace.
|
||||
* @param {?string} prototypeName Name of the language object containing
|
||||
* type-specific functions for this block.
|
||||
* @return {!Blockly.Block} The created block.
|
||||
* @deprecated December 2015
|
||||
*/
|
||||
Blockly.Block.obtain = function(workspace, prototypeName) {
|
||||
console.warn('Deprecated call to Blockly.Block.obtain, ' +
|
||||
'use workspace.newBlock instead.');
|
||||
return workspace.newBlock(prototypeName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Optional text data that round-trips beween blocks and XML.
|
||||
* Has no effect. May be used by 3rd parties for meta information.
|
||||
* @type {?string}
|
||||
*/
|
||||
Blockly.Block.prototype.data = null;
|
||||
|
||||
/**
|
||||
* Get an existing block.
|
||||
* @param {string} id The block's id.
|
||||
|
|
|
@ -36,10 +36,15 @@ goog.require('goog.math.Coordinate');
|
|||
|
||||
/**
|
||||
* Class for a block's SVG representation.
|
||||
* Not normally called directly, workspace.newBlock() is preferred.
|
||||
* @param {!Blockly.Workspace} workspace The block's workspace.
|
||||
* @param {?string} prototypeName Name of the language object containing
|
||||
* type-specific functions for this block.
|
||||
* @extends {Blockly.Block}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.BlockSvg = function() {
|
||||
Blockly.BlockSvg = function(workspace, prototypeName) {
|
||||
Blockly.BlockSvg.superClass_.constructor.call(this, workspace, prototypeName);
|
||||
// Create core elements for the block.
|
||||
/** @type {SVGElement} */
|
||||
this.svgGroup_ = Blockly.createSvgElement('g', {}, null);
|
||||
|
|
|
@ -19,30 +19,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Name space for the Blocks singleton.
|
||||
* @fileoverview Empty name space for the Blocks singleton.
|
||||
* @author spertus@google.com (Ellen Spertus)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.Blocks');
|
||||
|
||||
|
||||
/**
|
||||
* Unique ID counter for created blocks.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Blocks.uidCounter_ = 0;
|
||||
|
||||
/**
|
||||
* Generate a unique ID. This will be locally or globally unique, depending on
|
||||
* whether we are in single user or realtime collaborative mode.
|
||||
* @return {string}
|
||||
*/
|
||||
Blockly.Blocks.genUid = function() {
|
||||
var uid = (++Blockly.Blocks.uidCounter_).toString();
|
||||
if (Blockly.Realtime.isEnabled()) {
|
||||
return Blockly.Realtime.genUid(uid);
|
||||
} else {
|
||||
return uid;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -202,8 +202,6 @@ Blockly.Generator.prototype.valueToCode = function(block, name, order) {
|
|||
}
|
||||
// Value blocks must return code and order of operations info.
|
||||
// Statement blocks must only return code.
|
||||
goog.asserts.assertArray(tuple,
|
||||
'Expecting tuple from value block "%s".', targetBlock.type);
|
||||
var code = tuple[0];
|
||||
var innerOrder = tuple[1];
|
||||
if (isNaN(innerOrder)) {
|
||||
|
@ -239,8 +237,6 @@ Blockly.Generator.prototype.statementToCode = function(block, name) {
|
|||
var code = this.blockToCode(targetBlock);
|
||||
// Value blocks must return code and order of operations info.
|
||||
// Statement blocks must only return code.
|
||||
goog.asserts.assertString(code,
|
||||
'Expecting code from statement block "%s".',
|
||||
targetBlock && targetBlock.type);
|
||||
if (code) {
|
||||
code = this.prefixLines(/** @type {string} */ (code), this.INDENT);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Core JavaScript library for Blockly.
|
||||
* @fileoverview Empty name space for the Message singleton.
|
||||
* @author scr@google.com (Sheridan Rawlins)
|
||||
*/
|
||||
'use strict';
|
||||
|
|
|
@ -189,7 +189,6 @@ Blockly.Mutator.prototype.setVisible = function(visible) {
|
|||
this.bubble_ = new Blockly.Bubble(this.block_.workspace,
|
||||
this.createEditor_(), this.block_.svgPath_,
|
||||
this.iconX_, this.iconY_, null, null);
|
||||
var thisObj = this;
|
||||
var tree = this.workspace_.options.languageTree;
|
||||
if (tree) {
|
||||
this.workspace_.flyout_.init(this.workspace_);
|
||||
|
@ -217,16 +216,19 @@ Blockly.Mutator.prototype.setVisible = function(visible) {
|
|||
this.rootBlock_.moveBy(x, margin);
|
||||
// Save the initial connections, then listen for further changes.
|
||||
if (this.block_.saveConnections) {
|
||||
var thisMutator = this;
|
||||
this.block_.saveConnections(this.rootBlock_);
|
||||
this.sourceListener_ = Blockly.bindEvent_(
|
||||
this.block_.workspace.getCanvas(),
|
||||
'blocklyWorkspaceChange', this.block_,
|
||||
function() {thisObj.block_.saveConnections(thisObj.rootBlock_)});
|
||||
'blocklyWorkspaceChange', null,
|
||||
function() {
|
||||
thisMutator.block_.saveConnections(thisMutator.rootBlock_)
|
||||
});
|
||||
}
|
||||
this.resizeBubble_();
|
||||
// When the mutator's workspace changes, update the source block.
|
||||
Blockly.bindEvent_(this.workspace_.getCanvas(), 'blocklyWorkspaceChange',
|
||||
this.block_, function() {thisObj.workspaceChanged_();});
|
||||
this, this.workspaceChanged_);
|
||||
this.updateColour();
|
||||
} else {
|
||||
// Dispose of the bubble.
|
||||
|
|
|
@ -148,6 +148,16 @@ Blockly.Workspace.prototype.getWidth = function() {
|
|||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtain a newly created block.
|
||||
* @param {?string} prototypeName Name of the language object containing
|
||||
* type-specific functions for this block.
|
||||
* @return {!Blockly.Block} The created block.
|
||||
*/
|
||||
Blockly.Workspace.prototype.newBlock = function(prototypeName) {
|
||||
return new Blockly.Block(this, prototypeName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds the block with the specified ID in this workspace.
|
||||
* @param {string} id ID of block to find.
|
||||
|
|
|
@ -246,6 +246,16 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Obtain a newly created block.
|
||||
* @param {?string} prototypeName Name of the language object containing
|
||||
* type-specific functions for this block.
|
||||
* @return {!Blockly.BlockSvg} The created block.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.newBlock = function(prototypeName) {
|
||||
return new Blockly.BlockSvg(this, prototypeName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a trashcan.
|
||||
* @param {number} bottom Distance from workspace bottom to bottom of trashcan.
|
||||
|
|
|
@ -363,7 +363,7 @@ Blockly.Xml.domToBlockHeadless_ =
|
|||
block.fill(workspace, prototypeName);
|
||||
block.parent_ = parentBlock;
|
||||
} else {
|
||||
block = Blockly.Block.obtain(workspace, prototypeName);
|
||||
block = workspace.newBlock(prototypeName);
|
||||
}
|
||||
|
||||
var blockChild = null;
|
||||
|
|
|
@ -296,13 +296,11 @@ Blockly.Blocks['field_dropdown'] = {
|
|||
}
|
||||
},
|
||||
decompose: function(workspace) {
|
||||
var containerBlock =
|
||||
Blockly.Block.obtain(workspace, 'field_dropdown_container');
|
||||
var containerBlock = workspace.newBlock('field_dropdown_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var x = 0; x < this.optionCount_; x++) {
|
||||
var optionBlock =
|
||||
Blockly.Block.obtain(workspace, 'field_dropdown_option');
|
||||
var optionBlock = workspace.newBlock('field_dropdown_option');
|
||||
optionBlock.initSvg();
|
||||
connection.connect(optionBlock.previousConnection);
|
||||
connection = optionBlock.nextConnection;
|
||||
|
@ -533,12 +531,11 @@ Blockly.Blocks['type_group'] = {
|
|||
}
|
||||
},
|
||||
decompose: function(workspace) {
|
||||
var containerBlock =
|
||||
Blockly.Block.obtain(workspace, 'type_group_container');
|
||||
var containerBlock = workspace.newBlock('type_group_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var x = 0; x < this.typeCount_; x++) {
|
||||
var typeBlock = Blockly.Block.obtain(workspace, 'type_group_item');
|
||||
var typeBlock = workspace.newBlock('type_group_item');
|
||||
typeBlock.initSvg();
|
||||
connection.connect(typeBlock.previousConnection);
|
||||
connection = typeBlock.nextConnection;
|
||||
|
|
|
@ -669,7 +669,7 @@ function updatePreview() {
|
|||
}
|
||||
|
||||
// Create the preview block.
|
||||
var previewBlock = Blockly.Block.obtain(previewWorkspace, blockType);
|
||||
var previewBlock = previewWorkspace.newBlock(blockType);
|
||||
previewBlock.initSvg();
|
||||
previewBlock.render();
|
||||
previewBlock.setMovable(false);
|
||||
|
|
|
@ -186,13 +186,13 @@ h1 {
|
|||
<div id="blocklyDiv"></div>
|
||||
|
||||
<xml id="toolbox" style="display: none">
|
||||
<category name="Unit test">
|
||||
<category name="Unit test" colour="65">
|
||||
<block type="unittest_main"></block>
|
||||
<block type="unittest_assertequals"></block>
|
||||
<block type="unittest_assertvalue"></block>
|
||||
<block type="unittest_fail"></block>
|
||||
</category>
|
||||
<category name="Logic">
|
||||
<category name="Logic" colour="210">
|
||||
<block type="controls_if"></block>
|
||||
<block type="logic_compare"></block>
|
||||
<block type="logic_operation"></block>
|
||||
|
@ -201,207 +201,63 @@ h1 {
|
|||
<block type="logic_null"></block>
|
||||
<block type="logic_ternary"></block>
|
||||
</category>
|
||||
<category name="Loops">
|
||||
<block type="controls_repeat_ext">
|
||||
<value name="TIMES">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<category name="Loops" colour="120">
|
||||
<block type="controls_repeat_ext"></block>
|
||||
<block type="controls_whileUntil"></block>
|
||||
<block type="controls_for">
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="controls_for"></block>
|
||||
<block type="controls_forEach"></block>
|
||||
<block type="controls_flow_statements"></block>
|
||||
</category>
|
||||
<category name="Math">
|
||||
<category name="Math" colour="230">
|
||||
<block type="math_number"></block>
|
||||
<block type="math_arithmetic"></block>
|
||||
<block type="math_single"></block>
|
||||
<block type="math_trig"></block>
|
||||
<block type="math_constant"></block>
|
||||
<block type="math_number_property"></block>
|
||||
<block type="math_change">
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_change"></block>
|
||||
<block type="math_round"></block>
|
||||
<block type="math_on_list"></block>
|
||||
<block type="math_modulo"></block>
|
||||
<block type="math_constrain">
|
||||
<value name="LOW">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="HIGH">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_random_int">
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_constrain"></block>
|
||||
<block type="math_random_int"></block>
|
||||
<block type="math_random_float"></block>
|
||||
</category>
|
||||
<category name="Text">
|
||||
<category name="Text" colour="160">
|
||||
<block type="text"></block>
|
||||
<block type="text_join"></block>
|
||||
<block type="text_append">
|
||||
<value name="TEXT">
|
||||
<block type="text"></block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_append"></block>
|
||||
<block type="text_length"></block>
|
||||
<block type="text_isEmpty"></block>
|
||||
<block type="text_indexOf">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_charAt">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_getSubstring">
|
||||
<value name="STRING">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_indexOf"></block>
|
||||
<block type="text_charAt"></block>
|
||||
<block type="text_getSubstring"></block>
|
||||
<block type="text_changeCase"></block>
|
||||
<block type="text_trim"></block>
|
||||
<block type="text_print"></block>
|
||||
<block type="text_prompt_ext">
|
||||
<value name="TEXT">
|
||||
<block type="text"></block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_prompt_ext"></block>
|
||||
</category>
|
||||
<category name="Lists">
|
||||
<category name="Lists" colour="260">
|
||||
<block type="lists_create_empty"></block>
|
||||
<block type="lists_create_with"></block>
|
||||
<block type="lists_repeat">
|
||||
<value name="NUM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_repeat"></block>
|
||||
<block type="lists_length"></block>
|
||||
<block type="lists_isEmpty"></block>
|
||||
<block type="lists_indexOf">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getIndex">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_setIndex">
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getSublist">
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_split">
|
||||
<value name="DELIM">
|
||||
<block type="text">
|
||||
<field name="TEXT">,</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_indexOf"></block>
|
||||
<block type="lists_getIndex"></block>
|
||||
<block type="lists_setIndex"></block>
|
||||
<block type="lists_getSublist"></block>
|
||||
<block type="lists_split"></block>
|
||||
</category>
|
||||
<category name="Colour">
|
||||
<category name="Colour" colour="20">
|
||||
<block type="colour_picker"></block>
|
||||
<block type="colour_random"></block>
|
||||
<block type="colour_rgb">
|
||||
<value name="RED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="GREEN">
|
||||
<block type="math_number">
|
||||
<field name="NUM">50</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BLUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="colour_blend">
|
||||
<value name="COLOUR1">
|
||||
<block type="colour_picker">
|
||||
<field name="COLOUR">#ff0000</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="COLOUR2">
|
||||
<block type="colour_picker">
|
||||
<field name="COLOUR">#3333ff</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="RATIO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0.5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="colour_rgb"></block>
|
||||
<block type="colour_blend"></block>
|
||||
</category>
|
||||
<sep></sep>
|
||||
<category name="Variables" custom="VARIABLE"></category>
|
||||
<category name="Functions" custom="PROCEDURE"></category>
|
||||
<category name="Variables" colour="330" custom="VARIABLE"></category>
|
||||
<category name="Functions" colour="290" custom="PROCEDURE"></category>
|
||||
</xml>
|
||||
|
||||
<table height="95%" width="30%"><tr><td valign="top">
|
||||
|
|
|
@ -32,11 +32,11 @@ function test_emptyWorkspace() {
|
|||
|
||||
function test_flatWorkspace() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var blockA = Blockly.Block.obtain(workspace, '');
|
||||
var blockA = workspace.newBlock('');
|
||||
assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length);
|
||||
assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length);
|
||||
assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length);
|
||||
var blockB = Blockly.Block.obtain(workspace, '');
|
||||
var blockB = workspace.newBlock('');
|
||||
assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length);
|
||||
|
@ -52,8 +52,8 @@ function test_flatWorkspace() {
|
|||
|
||||
function test_maxBlocksWorkspace() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var blockA = Blockly.Block.obtain(workspace, '');
|
||||
var blockB = Blockly.Block.obtain(workspace, '');
|
||||
var blockA = workspace.newBlock('');
|
||||
var blockB = workspace.newBlock('');
|
||||
assertEquals('Infinite capacity.', Infinity, workspace.remainingCapacity());
|
||||
workspace.options.maxBlocks = 3;
|
||||
assertEquals('Three capacity.', 1, workspace.remainingCapacity());
|
||||
|
@ -69,8 +69,8 @@ function test_maxBlocksWorkspace() {
|
|||
|
||||
function test_getByIdWorkspace() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var blockA = Blockly.Block.obtain(workspace, '');
|
||||
var blockB = Blockly.Block.obtain(workspace, '');
|
||||
var blockA = workspace.newBlock('');
|
||||
var blockB = workspace.newBlock('');
|
||||
assertEquals('Find blockA.', blockA, workspace.getBlockById(blockA.id));
|
||||
assertEquals('Find blockB.', blockB, workspace.getBlockById(blockB.id));
|
||||
assertEquals('No block found.', null, workspace.getBlockById('I do not exist.'));
|
||||
|
|
|
@ -124,7 +124,7 @@ function airstrike(n) {
|
|||
}
|
||||
for (var i = 0; i < n; i++) {
|
||||
var prototype = prototypes[Math.floor(Math.random() * prototypes.length)];
|
||||
var block = Blockly.Block.obtain(workspace, prototype);
|
||||
var block = workspace.newBlock(prototype);
|
||||
block.initSvg();
|
||||
block.getSvgRoot().setAttribute('transform', 'translate(' +
|
||||
Math.round(Math.random() * 450 + 40) + ', ' +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue