diff --git a/dist/entry.js b/dist/entry.js index 6a64b905f5..402e7b06ca 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -17,7 +17,6 @@ var Entry = {block:{}, TEXT_ALIGN_CENTER:0, TEXT_ALIGN_LEFT:1, TEXT_ALIGN_RIGHT: Entry.engine.projectTimer || Entry.variableContainer.generateTimer(); 0 === Object.keys(Entry.container.inputValue).length && Entry.variableContainer.generateAnswer(); Entry.start(); - this.removeFuncRefs(); return b; }, exportProject:function(b) { b || (b = {}); @@ -13911,9 +13910,6 @@ Entry.VariableContainer.prototype.setVariables = function(b) { this.updateList(); }; Entry.VariableContainer.prototype.setFunctions = function(b) { - b && b.forEach(function(a) { - this.functions_[a.id] = !0; - }.bind(this)); for (var a in b) { var c = new Entry.Func(b[a]); c.generateBlock(); @@ -15884,6 +15880,7 @@ Entry.BlockMenuScroller.RADIUS = 7; }; })(Entry.BlockMenuScroller.prototype); Entry.BlockView = function(b, a, c) { + var d = this; Entry.Model(this, !1); this.block = b; this._lazyUpdatePos = _.debounce(b._updatePos.bind(b), 200); @@ -15892,39 +15889,42 @@ Entry.BlockView = function(b, a, c) { this.set(b); this.svgGroup = a.svgBlockGroup.elem("g"); this._schema = Entry.block[b.type]; - this._schema.changeEvent && (this._schemaChangeEvent = this._schema.changeEvent.attach(this, this._updateSchema)); - var d = this._skeleton = Entry.skeleton[this._schema.skeleton]; - this._contents = []; - this._statements = []; - this.magnet = {}; - this._paramMap = {}; - d.magnets && d.magnets(this).next && (this.svgGroup.nextMagnet = this.block, this._nextGroup = this.svgGroup.elem("g"), this._observers.push(this.observe(this, "_updateMagnet", ["contentHeight"]))); - this.isInBlockMenu = this.getBoard() instanceof Entry.BlockMenu; - var e = this; - this.mouseHandler = function() { - var a = e.block.events; - a && a.mousedown && a.mousedown.forEach(function(a) { - a(e); + if (void 0 === this._schema) { + this.block.destroy(!1, !1); + } else { + this._schema.changeEvent && (this._schemaChangeEvent = this._schema.changeEvent.attach(this, this._updateSchema)); + var e = this._skeleton = Entry.skeleton[this._schema.skeleton]; + this._contents = []; + this._statements = []; + this.magnet = {}; + this._paramMap = {}; + e.magnets && e.magnets(this).next && (this.svgGroup.nextMagnet = this.block, this._nextGroup = this.svgGroup.elem("g"), this._observers.push(this.observe(this, "_updateMagnet", ["contentHeight"]))); + this.isInBlockMenu = this.getBoard() instanceof Entry.BlockMenu; + this.mouseHandler = function() { + var a = d.block.events; + a && a.mousedown && a.mousedown.forEach(function(a) { + a(d); + }); + d.onMouseDown.apply(d, arguments); + }; + this._startRender(b, c); + this._observers.push(this.block.observe(this, "_setMovable", ["movable"])); + this._observers.push(this.block.observe(this, "_setReadOnly", ["movable"])); + this._observers.push(this.block.observe(this, "_setCopyable", ["copyable"])); + this._observers.push(this.block.observe(this, "_updateColor", ["deletable"], !1)); + this._observers.push(this.observe(this, "_updateBG", ["magneting"], !1)); + this._observers.push(this.observe(this, "_updateOpacity", ["visible"], !1)); + this._observers.push(this.observe(this, "_updateDisplay", ["display"], !1)); + this._observers.push(this.observe(this, "_updateShadow", ["shadow"])); + this._observers.push(this.observe(this, "_updateMagnet", ["offsetY"])); + this._observers.push(a.code.observe(this, "_setBoard", ["board"], !1)); + this.dragMode = Entry.DRAG_MODE_NONE; + Entry.Utils.disableContextmenu(this.svgGroup.node); + a = b.events.viewAdd; + "workspace" == Entry.type && a && !this.isInBlockMenu && a.forEach(function(a) { + Entry.Utils.isFunction(a) && a(b); }); - e.onMouseDown.apply(e, arguments); - }; - this._startRender(b, c); - this._observers.push(this.block.observe(this, "_setMovable", ["movable"])); - this._observers.push(this.block.observe(this, "_setReadOnly", ["movable"])); - this._observers.push(this.block.observe(this, "_setCopyable", ["copyable"])); - this._observers.push(this.block.observe(this, "_updateColor", ["deletable"], !1)); - this._observers.push(this.observe(this, "_updateBG", ["magneting"], !1)); - this._observers.push(this.observe(this, "_updateOpacity", ["visible"], !1)); - this._observers.push(this.observe(this, "_updateDisplay", ["display"], !1)); - this._observers.push(this.observe(this, "_updateShadow", ["shadow"])); - this._observers.push(this.observe(this, "_updateMagnet", ["offsetY"])); - this._observers.push(a.code.observe(this, "_setBoard", ["board"], !1)); - this.dragMode = Entry.DRAG_MODE_NONE; - Entry.Utils.disableContextmenu(this.svgGroup.node); - a = b.events.viewAdd; - "workspace" == Entry.type && a && !this.isInBlockMenu && a.forEach(function(a) { - Entry.Utils.isFunction(a) && a(b); - }); + } }; Entry.BlockView.PARAM_SPACE = 5; Entry.BlockView.DRAG_RADIUS = 5; @@ -16753,14 +16753,15 @@ Entry.Executor = function(b, a) { for (;;) { var a = null; try { - a = this.scope.block.getSchema().func.call(this.scope, this.entity, this.scope); - } catch (b) { - if ("AsyncError" === b.name) { + var b = this.scope.block.getSchema(); + b && (a = b.func.call(this.scope, this.entity, this.scope)); + } catch (e) { + if ("AsyncError" === e.name) { a = Entry.STATIC.BREAK; } else { - var c = !1; - "\ub7f0\ud0c0\uc784 \uc5d0\ub7ec" != b.message && (c = !0); - Entry.Utils.stopProjectWithToast(this.scope, "\ub7f0\ud0c0\uc784 \uc5d0\ub7ec", c); + var d = !1; + "\ub7f0\ud0c0\uc784 \uc5d0\ub7ec" != e.message && (d = !0); + Entry.Utils.stopProjectWithToast(this.scope, "\ub7f0\ud0c0\uc784 \uc5d0\ub7ec", d); } } if (this.isEnd()) { @@ -18902,12 +18903,7 @@ Entry.Thread = function(b, a, c) { } for (var d = 0;d < a.length;d++) { var e = a[d]; - if (e instanceof Entry.Block || e.isDummy) { - e.setThread(this), this._data.push(e); - } else { - var f = e.type, g = Entry.functions; - (Entry.block[f] || -1 < (g && g.indexOf(f.split("_")[1]))) && this._data.push(new Entry.Block(e, this)); - } + e instanceof Entry.Block || e.isDummy ? (e.setThread(this), this._data.push(e)) : this._data.push(new Entry.Block(e, this)); } (d = this._code.view) && this.createView(d.board, b); }; @@ -18920,7 +18916,7 @@ Entry.Thread = function(b, a, c) { }; b.createView = function(a, b) { this.view || (this.view = new Entry.ThreadView(this, a)); - this._data.map(function(d) { + this._data.getAll().forEach(function(d) { d.createView(a, b); }); }; @@ -19195,7 +19191,7 @@ Entry.Block.DELETABLE_FALSE_LIGHTEN = 3; f = this.getNextBlock(); this.getCode().unregisterBlock(this); e = this.getThread(); - this._schema.event && e.unregisterEvent(this, this._schema.event); + this._schema && this._schema.event && e.unregisterEvent(this, this._schema.event); f && (b ? f.destroy(a, b) : g ? f.view && f.view.bindPrev(g) : (g = this.getThread().view.getParent(), g.constructor === Entry.FieldStatement ? (f.view && f.view.bindPrev(g), g.insertTopBlock(f)) : g.constructor === Entry.FieldStatement ? f.replace(g._valueBlock) : f.view._toGlobalCoordinate())); !this.doNotSplice && e.spliceBlock ? e.spliceBlock(this) : delete this.doNotSplice; this.view && this.view.destroy(a); diff --git a/dist/entry.min.js b/dist/entry.min.js index 5e685dacc8..89b8dcb520 100644 --- a/dist/entry.min.js +++ b/dist/entry.min.js @@ -1,14 +1,14 @@ Entry={block:{},TEXT_ALIGN_CENTER:0,TEXT_ALIGN_LEFT:1,TEXT_ALIGN_RIGHT:2,TEXT_ALIGNS:["center","left","right"],clipboard:null,loadProject:function(b){b||(b=Entry.getStartProject(Entry.mediaFilePath));this.setFuncRefs(b.functions);"workspace"==this.type&&Entry.stateManager.startIgnore();Entry.projectId=b._id;Entry.variableContainer.setVariables(b.variables);Entry.variableContainer.setMessages(b.messages);Entry.scene.addScenes(b.scenes);Entry.stage.initObjectContainers();Entry.variableContainer.setFunctions(b.functions); -Entry.container.setObjects(b.objects);Entry.FPS=b.speed?b.speed:60;createjs.Ticker.setFPS(Entry.FPS);"workspace"==this.type&&setTimeout(function(){Entry.stateManager.endIgnore()},300);Entry.engine.projectTimer||Entry.variableContainer.generateTimer();0===Object.keys(Entry.container.inputValue).length&&Entry.variableContainer.generateAnswer();Entry.start();this.removeFuncRefs();return b},exportProject:function(b){b||(b={});Entry.engine.isState("stop")||Entry.engine.toggleStop();Entry.Func&&Entry.Func.workspace&& -Entry.Func.workspace.visible&&Entry.Func.cancelEdit();b.objects=Entry.container.toJSON();b.scenes=Entry.scene.toJSON();b.variables=Entry.variableContainer.getVariableJSON();b.messages=Entry.variableContainer.getMessageJSON();b.functions=Entry.variableContainer.getFunctionJSON();b.scenes=Entry.scene.toJSON();b.speed=Entry.FPS;return b},setBlockByText:function(b,a){for(var c=[],d=jQuery.parseXML(a).getElementsByTagName("category"),e=0;ea?a=325:720a?a=244:400svg").css({width:a- -64+"px"});Entry.playground.mainWorkspace.blockMenu.setWidth();$(".entryWorkspaceBoard").css({left:a+"px"});Entry.playground.resizeHandle_.style.left=a+"px";Entry.playground.variableViewWrapper_.style.width=a+"px";this.interfaceState=b}Entry.windowResized.notify()},getUpTime:function(){return(new Date).getTime()-this.startTime},addActivity:function(b){Entry.stateManager&&Entry.stateManager.addActivity(b)},startActivityLogging:function(){Entry.reporter&&Entry.reporter.start(Entry.projectId,window.user? -window.user._id:null,Entry.startTime)},getActivityLog:function(){var b={};Entry.stateManager&&(b.activityLog=Entry.stateManager.activityLog_);return b},DRAG_MODE_NONE:0,DRAG_MODE_MOUSEDOWN:1,DRAG_MODE_DRAG:2,cancelObjectEdit:function(b){var a=Entry.playground.object;if(a){var c=b.target;b=0!==$(a.view_).find(c).length;c=c.tagName.toUpperCase();!a.isEditing||"INPUT"===c&&b||a.editObjectValues(!1)}},generateFunctionSchema:function(b){b="func_"+b;if(!Entry.block[b]){var a=function(){};a.prototype=Entry.block.function_general; -a=new a;a.changeEvent=new Entry.Event;a.template=Lang.template.function_general;Entry.block[b]=a}},setFuncRefs:function(b){this.functions=b?b.map(function(a){return a.id}):[]},removeFuncRefs:function(){delete this.functions}};window.Entry=Entry;Entry.Albert={PORT_MAP:{leftWheel:0,rightWheel:0,buzzer:0,leftEye:0,rightEye:0,note:0,bodyLed:0,frontLed:0,padWidth:0,padHeight:0},setZero:function(){var b=Entry.Albert.PORT_MAP,a=Entry.hw.sendQueue,c;for(c in b)a[c]=b[c];Entry.hw.update();b=Entry.Albert;b.tempo=60;b.removeAllTimeouts()},monitorTemplate:{imgPath:"hw/albert.png",width:387,height:503,listPorts:{oid:{name:"OID",type:"input",pos:{x:0,y:0}},buzzer:{name:Lang.Hw.buzzer,type:"output",pos:{x:0,y:0}},note:{name:Lang.Hw.note,type:"output", +Entry.container.setObjects(b.objects);Entry.FPS=b.speed?b.speed:60;createjs.Ticker.setFPS(Entry.FPS);"workspace"==this.type&&setTimeout(function(){Entry.stateManager.endIgnore()},300);Entry.engine.projectTimer||Entry.variableContainer.generateTimer();0===Object.keys(Entry.container.inputValue).length&&Entry.variableContainer.generateAnswer();Entry.start();return b},exportProject:function(b){b||(b={});Entry.engine.isState("stop")||Entry.engine.toggleStop();Entry.Func&&Entry.Func.workspace&&Entry.Func.workspace.visible&& +Entry.Func.cancelEdit();b.objects=Entry.container.toJSON();b.scenes=Entry.scene.toJSON();b.variables=Entry.variableContainer.getVariableJSON();b.messages=Entry.variableContainer.getMessageJSON();b.functions=Entry.variableContainer.getFunctionJSON();b.scenes=Entry.scene.toJSON();b.speed=Entry.FPS;return b},setBlockByText:function(b,a){for(var c=[],d=jQuery.parseXML(a).getElementsByTagName("category"),e=0;ea?a=325:720a?a=244:400svg").css({width:a-64+"px"});Entry.playground.mainWorkspace.blockMenu.setWidth(); +$(".entryWorkspaceBoard").css({left:a+"px"});Entry.playground.resizeHandle_.style.left=a+"px";Entry.playground.variableViewWrapper_.style.width=a+"px";this.interfaceState=b}Entry.windowResized.notify()},getUpTime:function(){return(new Date).getTime()-this.startTime},addActivity:function(b){Entry.stateManager&&Entry.stateManager.addActivity(b)},startActivityLogging:function(){Entry.reporter&&Entry.reporter.start(Entry.projectId,window.user?window.user._id:null,Entry.startTime)},getActivityLog:function(){var b= +{};Entry.stateManager&&(b.activityLog=Entry.stateManager.activityLog_);return b},DRAG_MODE_NONE:0,DRAG_MODE_MOUSEDOWN:1,DRAG_MODE_DRAG:2,cancelObjectEdit:function(b){var a=Entry.playground.object;if(a){var c=b.target;b=0!==$(a.view_).find(c).length;c=c.tagName.toUpperCase();!a.isEditing||"INPUT"===c&&b||a.editObjectValues(!1)}},generateFunctionSchema:function(b){b="func_"+b;if(!Entry.block[b]){var a=function(){};a.prototype=Entry.block.function_general;a=new a;a.changeEvent=new Entry.Event;a.template= +Lang.template.function_general;Entry.block[b]=a}},setFuncRefs:function(b){this.functions=b?b.map(function(a){return a.id}):[]},removeFuncRefs:function(){delete this.functions}};window.Entry=Entry;Entry.Albert={PORT_MAP:{leftWheel:0,rightWheel:0,buzzer:0,leftEye:0,rightEye:0,note:0,bodyLed:0,frontLed:0,padWidth:0,padHeight:0},setZero:function(){var b=Entry.Albert.PORT_MAP,a=Entry.hw.sendQueue,c;for(c in b)a[c]=b[c];Entry.hw.update();b=Entry.Albert;b.tempo=60;b.removeAllTimeouts()},monitorTemplate:{imgPath:"hw/albert.png",width:387,height:503,listPorts:{oid:{name:"OID",type:"input",pos:{x:0,y:0}},buzzer:{name:Lang.Hw.buzzer,type:"output",pos:{x:0,y:0}},note:{name:Lang.Hw.note,type:"output", pos:{x:0,y:0}}},ports:{leftProximity:{name:Lang.Blocks.ALBERT_sensor_leftProximity,type:"input",pos:{x:178,y:401}},rightProximity:{name:Lang.Blocks.ALBERT_sensor_rightProximity,type:"input",pos:{x:66,y:359}},battery:{name:Lang.Blocks.ALBERT_sensor_battery,type:"input",pos:{x:88,y:368}},light:{name:Lang.Blocks.ALBERT_sensor_light,type:"input",pos:{x:127,y:391}},leftWheel:{name:Lang.Hw.leftWheel,type:"output",pos:{x:299,y:406}},rightWheel:{name:Lang.Hw.rightWheel,type:"output",pos:{x:22,y:325}},leftEye:{name:Lang.Hw.leftEye, type:"output",pos:{x:260,y:26}},rightEye:{name:Lang.Hw.rightEye,type:"output",pos:{x:164,y:13}},bodyLed:{name:Lang.Hw.body+" "+Lang.Hw.led,type:"output",pos:{x:367,y:308}},frontLed:{name:Lang.Hw.front+" "+Lang.Hw.led,pos:{x:117,y:410}}},mode:"both"},tempo:60,timeouts:[],removeTimeout:function(b){clearTimeout(b);var a=this.timeouts;b=a.indexOf(b);0<=b&&a.splice(b,1)},removeAllTimeouts:function(){var b=this.timeouts,a;for(a in b)clearTimeout(b[a]);this.timeouts=[]},name:"albert"}; Blockly.Blocks.albert_hand_found={init:function(){this.setColour("#00979D");this.appendDummyInput().appendField(Lang.Blocks.ALBERT_hand_found);this.setOutput(!0,"Boolean");this.setInputsInline(!0)}};Entry.block.albert_hand_found=function(b,a){var c=Entry.hw.portData;return 40b.x_&&a.xe?!0:!1}; Entry.VariableContainer.prototype.getListById=function(b){var a=this.lists_,c=[];if(0=b?this.setVisible(!1):this.setVisible(!0)};b._reset=function(){this.vY=0;this.vScrollbar.attr({y:this.vY});this.resizeScrollBar()};b.onMouseDown=function(a){function b(a){a.stopPropagation&&a.stopPropagation();a.preventDefault&&a.preventDefault();a=a.originalEvent&&a.originalEvent.touches?a.originalEvent.touches[0]:a;var c=e.dragInstance; e.scroll(a.pageY-c.offsetY);c.set({offsetY:a.pageY})}function d(a){$(document).unbind(".scroll");delete e.dragInstance}var e=this;a.stopPropagation&&a.stopPropagation();a.preventDefault&&a.preventDefault();if(0===a.button||a.originalEvent&&a.originalEvent.touches){Entry.documentMousedown&&Entry.documentMousedown.notify(a);var f;f=a.originalEvent&&a.originalEvent.touches?a.originalEvent.touches[0]:a;var g=$(document);g.bind("mousemove.scroll",b);g.bind("mouseup.scroll",d);g.bind("touchmove.scroll", -b);g.bind("touchend.scroll",d);e.dragInstance=new Entry.DragInstance({startY:f.pageY,offsetY:f.pageY})}a.stopPropagation()};b._addControl=function(){$(this.vScrollbar).bind("mousedown touchstart",this.mouseHandler)}})(Entry.BlockMenuScroller.prototype);Entry.BlockView=function(b,a,c){Entry.Model(this,!1);this.block=b;this._lazyUpdatePos=_.debounce(b._updatePos.bind(b),200);this._board=a;this._observers=[];this.set(b);this.svgGroup=a.svgBlockGroup.elem("g");this._schema=Entry.block[b.type];this._schema.changeEvent&&(this._schemaChangeEvent=this._schema.changeEvent.attach(this,this._updateSchema));var d=this._skeleton=Entry.skeleton[this._schema.skeleton];this._contents=[];this._statements=[];this.magnet={};this._paramMap={};d.magnets&&d.magnets(this).next&& -(this.svgGroup.nextMagnet=this.block,this._nextGroup=this.svgGroup.elem("g"),this._observers.push(this.observe(this,"_updateMagnet",["contentHeight"])));this.isInBlockMenu=this.getBoard()instanceof Entry.BlockMenu;var e=this;this.mouseHandler=function(){var a=e.block.events;a&&a.mousedown&&a.mousedown.forEach(function(a){a(e)});e.onMouseDown.apply(e,arguments)};this._startRender(b,c);this._observers.push(this.block.observe(this,"_setMovable",["movable"]));this._observers.push(this.block.observe(this, -"_setReadOnly",["movable"]));this._observers.push(this.block.observe(this,"_setCopyable",["copyable"]));this._observers.push(this.block.observe(this,"_updateColor",["deletable"],!1));this._observers.push(this.observe(this,"_updateBG",["magneting"],!1));this._observers.push(this.observe(this,"_updateOpacity",["visible"],!1));this._observers.push(this.observe(this,"_updateDisplay",["display"],!1));this._observers.push(this.observe(this,"_updateShadow",["shadow"]));this._observers.push(this.observe(this, -"_updateMagnet",["offsetY"]));this._observers.push(a.code.observe(this,"_setBoard",["board"],!1));this.dragMode=Entry.DRAG_MODE_NONE;Entry.Utils.disableContextmenu(this.svgGroup.node);a=b.events.viewAdd;"workspace"==Entry.type&&a&&!this.isInBlockMenu&&a.forEach(function(a){Entry.Utils.isFunction(a)&&a(b)})};Entry.BlockView.PARAM_SPACE=5;Entry.BlockView.DRAG_RADIUS=5;Entry.BlockView.pngMap={}; +b);g.bind("touchend.scroll",d);e.dragInstance=new Entry.DragInstance({startY:f.pageY,offsetY:f.pageY})}a.stopPropagation()};b._addControl=function(){$(this.vScrollbar).bind("mousedown touchstart",this.mouseHandler)}})(Entry.BlockMenuScroller.prototype);Entry.BlockView=function(b,a,c){var d=this;Entry.Model(this,!1);this.block=b;this._lazyUpdatePos=_.debounce(b._updatePos.bind(b),200);this._board=a;this._observers=[];this.set(b);this.svgGroup=a.svgBlockGroup.elem("g");this._schema=Entry.block[b.type];if(void 0===this._schema)this.block.destroy(!1,!1);else{this._schema.changeEvent&&(this._schemaChangeEvent=this._schema.changeEvent.attach(this,this._updateSchema));var e=this._skeleton=Entry.skeleton[this._schema.skeleton];this._contents=[];this._statements= +[];this.magnet={};this._paramMap={};e.magnets&&e.magnets(this).next&&(this.svgGroup.nextMagnet=this.block,this._nextGroup=this.svgGroup.elem("g"),this._observers.push(this.observe(this,"_updateMagnet",["contentHeight"])));this.isInBlockMenu=this.getBoard()instanceof Entry.BlockMenu;this.mouseHandler=function(){var a=d.block.events;a&&a.mousedown&&a.mousedown.forEach(function(a){a(d)});d.onMouseDown.apply(d,arguments)};this._startRender(b,c);this._observers.push(this.block.observe(this,"_setMovable", +["movable"]));this._observers.push(this.block.observe(this,"_setReadOnly",["movable"]));this._observers.push(this.block.observe(this,"_setCopyable",["copyable"]));this._observers.push(this.block.observe(this,"_updateColor",["deletable"],!1));this._observers.push(this.observe(this,"_updateBG",["magneting"],!1));this._observers.push(this.observe(this,"_updateOpacity",["visible"],!1));this._observers.push(this.observe(this,"_updateDisplay",["display"],!1));this._observers.push(this.observe(this,"_updateShadow", +["shadow"]));this._observers.push(this.observe(this,"_updateMagnet",["offsetY"]));this._observers.push(a.code.observe(this,"_setBoard",["board"],!1));this.dragMode=Entry.DRAG_MODE_NONE;Entry.Utils.disableContextmenu(this.svgGroup.node);a=b.events.viewAdd;"workspace"==Entry.type&&a&&!this.isInBlockMenu&&a.forEach(function(a){Entry.Utils.isFunction(a)&&a(b)})}};Entry.BlockView.PARAM_SPACE=5;Entry.BlockView.DRAG_RADIUS=5;Entry.BlockView.pngMap={}; (function(b){b.schema={id:0,type:Entry.STATIC.BLOCK_RENDER_MODEL,x:0,y:0,offsetX:0,offsetY:0,width:0,height:0,contentWidth:0,contentHeight:0,magneting:!1,visible:!0,animating:!1,shadow:!0,display:!0};b._startRender=function(a,b){var d=this,e=this._skeleton;this.svgGroup.attr({class:"block"});var f=e.classes;f&&0!==f.length&&f.forEach(function(a){d.svgGroup.addClass(a)});f=e.path(this);this.pathGroup=this.svgGroup.elem("g");this._updateMagnet();this._path=this.pathGroup.elem("path");this.getBoard().patternRect&& ($(this._path).mouseenter(function(a){d._mouseEnable&&d._changeFill(!0)}),$(this._path).mouseleave(function(a){d._mouseEnable&&d._changeFill(!1)}));var g=this._schema.color;this.block.deletable===Entry.Block.DELETABLE_FALSE_LIGHTEN&&(g=Entry.Utils.colorLighten(g));this._fillColor=g;f={d:f,fill:g,class:"blockPath"};if(this.magnet.next||this._skeleton.nextShadow)g=this.getBoard().suffix,this.pathGroup.attr({filter:"url(#entryBlockShadowFilter_"+g+")"});else if(this.magnet.string||this.magnet.boolean)f.stroke= e.outerLine;e.outerLine&&(f["stroke-width"]="0.6");this._path.attr(f);this._moveTo(this.x,this.y,!1);this._startContentRender(b);!0!==this._board.disableMouseEvent&&this._addControl();this.bindPrev()};b._startContentRender=function(a){a=void 0===a?Entry.Workspace.MODE_BOARD:a;this.contentSvgGroup&&this.contentSvgGroup.remove();var b=this._schema;b.statements&&b.statements.length&&this.statementSvgGroup&&this.statementSvgGroup.remove();this._contents=[];this.contentSvgGroup=this.svgGroup.elem("g"); @@ -1990,9 +1990,9 @@ b.getBlockList=function(a,b){for(var d=this.getThreads(),e=[],f=0;fthis.events[b].indexOf(f)&&this.events[b].push(f)}}this._schema.event&&this.thread.registerEvent(this,this._schema.event);a=this.params;b=this._schema.params;for(e=0;b&&e} variables */ Entry.VariableContainer.prototype.setFunctions = function(functions) { - if (functions) { - functions.forEach(function(f) { - this.functions_[f.id] = true; - }.bind(this)); - } - for (var i in functions) { var func = new Entry.Func(functions[i]); func.generateBlock(); diff --git a/src/workspace/block.js b/src/workspace/block.js index 284b9e0af8..52891bb3bd 100644 --- a/src/workspace/block.js +++ b/src/workspace/block.js @@ -235,7 +235,7 @@ Entry.Block.DELETABLE_FALSE_LIGHTEN = 3; this.getCode().unregisterBlock(this); var thread = this.getThread(); - if (this._schema.event) + if (this._schema && this._schema.event) thread.unregisterEvent(this, this._schema.event); if (nextBlock) { if (next) nextBlock.destroy(animate, next); diff --git a/src/workspace/block_view.js b/src/workspace/block_view.js index 1af01b1003..d7ddab4f14 100644 --- a/src/workspace/block_view.js +++ b/src/workspace/block_view.js @@ -9,6 +9,7 @@ goog.provide("Entry.BlockView"); * */ Entry.BlockView = function(block, board, mode) { + var that = this; Entry.Model(this, false); this.block = block; this._lazyUpdatePos = _.debounce(block._updatePos.bind(block), 200); @@ -18,6 +19,11 @@ Entry.BlockView = function(block, board, mode) { this.svgGroup = board.svgBlockGroup.elem("g"); this._schema = Entry.block[block.type]; + if (this._schema === undefined) { + this.block.destroy(false, false); + return; + } + if (this._schema.changeEvent) this._schemaChangeEvent = this._schema.changeEvent.attach( this, this._updateSchema); @@ -35,10 +41,6 @@ Entry.BlockView = function(block, board, mode) { this.isInBlockMenu = this.getBoard() instanceof Entry.BlockMenu; - //if (skeleton.morph) - //this._observers.push(this.block.observe(this, "_renderPath", skeleton.morph, false)); - - var that = this; this.mouseHandler = function() { var events = that.block.events; if (events && events.mousedown) diff --git a/src/workspace/executors.js b/src/workspace/executors.js index 7099a481a6..46da3069a6 100644 --- a/src/workspace/executors.js +++ b/src/workspace/executors.js @@ -19,7 +19,9 @@ Entry.Executor = function(block, entity) { while (true) { var returnVal = null; try { - returnVal = this.scope.block.getSchema().func.call(this.scope, this.entity, this.scope); + var schema = this.scope.block.getSchema(); + if (schema) + returnVal = schema.func.call(this.scope, this.entity, this.scope); } catch(e) { if(e.name === 'AsyncError') { returnVal = Entry.STATIC.BREAK; diff --git a/src/workspace/thread.js b/src/workspace/thread.js index fc8c2a1978..b7382fd4f1 100644 --- a/src/workspace/thread.js +++ b/src/workspace/thread.js @@ -35,13 +35,7 @@ Entry.Thread = function(thread, code, parent) { if (block instanceof Entry.Block || block.isDummy) { block.setThread(this); this._data.push(block); - } else { - var blockType = block.type; - var functions = Entry.functions; - if (Entry.block[blockType] || - (functions && functions.indexOf(blockType.split('_')[1])) > -1) - this._data.push(new Entry.Block(block, this)); - } + } else this._data.push(new Entry.Block(block, this)); } var codeView = this._code.view; @@ -61,7 +55,7 @@ Entry.Thread = function(thread, code, parent) { if (!this.view) this.view = new Entry.ThreadView(this, board); var prevBlock = null; - this._data.map(function(b) { + this._data.getAll().forEach(function(b) { b.createView(board, mode); }); };