From 948ec94230e2e4301c18d15161b9c14ef2c50b46 Mon Sep 17 00:00:00 2001 From: vivid Date: Thu, 18 Aug 2016 18:18:37 +0900 Subject: [PATCH 1/3] function refs --- dist/entry.js | 18 ++++++++++++++---- dist/entry.min.js | 38 +++++++++++++++++++------------------- src/entry.js | 18 ++++++++++++++++++ src/variable_container.js | 6 ------ src/workspace/thread.js | 8 +++++++- 5 files changed, 58 insertions(+), 30 deletions(-) diff --git a/dist/entry.js b/dist/entry.js index 93907525f9..303de251d7 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -1,5 +1,6 @@ var 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); @@ -16,6 +17,7 @@ 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 = {}); @@ -123,6 +125,12 @@ var Entry = {block:{}, TEXT_ALIGN_CENTER:0, TEXT_ALIGN_LEFT:1, TEXT_ALIGN_RIGHT: 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() { @@ -13890,9 +13898,6 @@ Entry.VariableContainer.prototype.setVariables = function(b) { this.updateList(); }; Entry.VariableContainer.prototype.setFunctions = function(b) { - b && b.forEach(function(a) { - Entry.generateFunctionSchema(a.id); - }); for (var a in b) { var c = new Entry.Func(b[a]); c.generateBlock(); @@ -18881,7 +18886,12 @@ Entry.Thread = function(b, a, c) { } for (var d = 0;d < a.length;d++) { var e = a[d]; - e instanceof Entry.Block || e.isDummy ? (e.setThread(this), this._data.push(e)) : Entry.block[e.type] && this._data.push(new Entry.Block(e, this)); + if (e instanceof Entry.Block || e.isDummy) { + e.setThread(this), this._data.push(e); + } else { + var f = Entry.functions, g = e.type; + (Entry.block[g] || f && -1 < f.indexOf(g.split("_")[1])) && this._data.push(new Entry.Block(e, this)); + } } (d = this._code.view) && this.createView(d.board, b); }; diff --git a/dist/entry.min.js b/dist/entry.min.js index 47f09a61ba..cb14d88159 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));"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();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}}};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={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", 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(0this.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) { - Entry.generateFunctionSchema(f.id); - }); - } - for (var i in functions) { var func = new Entry.Func(functions[i]); func.generateBlock(); diff --git a/src/workspace/thread.js b/src/workspace/thread.js index eaab7b0f01..2699a8a76b 100644 --- a/src/workspace/thread.js +++ b/src/workspace/thread.js @@ -35,7 +35,13 @@ Entry.Thread = function(thread, code, parent) { if (block instanceof Entry.Block || block.isDummy) { block.setThread(this); this._data.push(block); - } else Entry.block[block.type] && this._data.push(new Entry.Block(block, this)); + } else { + var functions = Entry.functions; + var blockType = block.type; + if (Entry.block[blockType] || ( + functions && functions.indexOf(blockType.split('_')[1]) > -1)) + this._data.push(new Entry.Block(block, this)); + } } var codeView = this._code.view; From cef6996a7e175073f974fde926fd7cd3648e27a8 Mon Sep 17 00:00:00 2001 From: vivid Date: Fri, 19 Aug 2016 09:33:05 +0900 Subject: [PATCH 2/3] restore to origin --- dist/entry.js | 28 +++++----------------------- src/entry.js | 17 ----------------- src/variable_container.js | 6 +++--- src/workspace/thread.js | 9 ++------- 4 files changed, 10 insertions(+), 50 deletions(-) diff --git a/dist/entry.js b/dist/entry.js index 303de251d7..4e01bad7c8 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -1,6 +1,5 @@ var 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); @@ -17,7 +16,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 = {}); @@ -125,12 +123,6 @@ var Entry = {block:{}, TEXT_ALIGN_CENTER:0, TEXT_ALIGN_LEFT:1, TEXT_ALIGN_RIGHT: 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() { @@ -13928,15 +13920,10 @@ Entry.VariableContainer.prototype.createFunction = function() { Entry.VariableContainer.prototype.addFunction = function(b) { }; Entry.VariableContainer.prototype.removeFunction = function(b) { - var a = b.id; - b = this.functions_; - b[a].destroy(); - delete b[a]; - a = "func_" + a; - Entry.container.removeFuncBlocks(a); - for (var c in b) { - b[c].content.removeBlocksByType(a); - } + b = b.id; + var a = this.functions_; + a[b].destroy(); + delete a[b]; this.updateList(); }; Entry.VariableContainer.prototype.checkListPosition = function(b, a) { @@ -18886,12 +18873,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 = Entry.functions, g = e.type; - (Entry.block[g] || f && -1 < f.indexOf(g.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); }; diff --git a/src/entry.js b/src/entry.js index 39d32bdb04..d49ffe86b3 100644 --- a/src/entry.js +++ b/src/entry.js @@ -25,8 +25,6 @@ Entry.loadProject = function(project) { project = Entry.getStartProject(Entry.mediaFilePath); } - this.setFuncRefs(project.functions); - if (this.type == 'workspace') Entry.stateManager.startIgnore(); Entry.projectId = project._id; @@ -52,8 +50,6 @@ Entry.loadProject = function(project) { Entry.variableContainer.generateAnswer(); Entry.start(); - this.removeFuncRefs(); - return project; }; @@ -358,17 +354,4 @@ Entry.generateFunctionSchema = function(functionId) { Entry.block[functionId] = blockSchema; }; -Entry.setFuncRefs = function(functions) { - if (!functions) this.functions = []; - else { - this.functions = functions.map(function(f) { - return f.id; - }); - } -}; - -Entry.removeFuncRefs = function() { - delete this.functions; -}; - window.Entry = Entry; diff --git a/src/variable_container.js b/src/variable_container.js index 59a5b2cb7f..c728445c64 100644 --- a/src/variable_container.js +++ b/src/variable_container.js @@ -663,9 +663,9 @@ Entry.VariableContainer.prototype.removeFunction = function(func) { delete functions[functionId]; var functionType = 'func_' + functionId; - Entry.container.removeFuncBlocks(functionType); - for (var id in functions) - functions[id].content.removeBlocksByType(functionType); + //Entry.container.removeFuncBlocks(functionType); + //for (var id in functions) + //functions[id].content.removeBlocksByType(functionType); this.updateList(); }; diff --git a/src/workspace/thread.js b/src/workspace/thread.js index 2699a8a76b..c5272c3e2a 100644 --- a/src/workspace/thread.js +++ b/src/workspace/thread.js @@ -35,13 +35,8 @@ Entry.Thread = function(thread, code, parent) { if (block instanceof Entry.Block || block.isDummy) { block.setThread(this); this._data.push(block); - } else { - var functions = Entry.functions; - var blockType = block.type; - 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; From 738b6f40c3614fa00405ed1852f8f012664ae18f Mon Sep 17 00:00:00 2001 From: vivid Date: Fri, 19 Aug 2016 11:08:04 +0900 Subject: [PATCH 3/3] remove when schema is undefined --- dist/entry.js | 98 ++++++++++++++++++++----------------- dist/entry.min.js | 52 ++++++++++---------- src/variable_container.js | 6 +-- src/workspace/block.js | 2 +- src/workspace/block_view.js | 10 ++-- src/workspace/executors.js | 4 +- src/workspace/thread.js | 2 +- 7 files changed, 94 insertions(+), 80 deletions(-) diff --git a/dist/entry.js b/dist/entry.js index 4e01bad7c8..840c52161d 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -13920,10 +13920,15 @@ Entry.VariableContainer.prototype.createFunction = function() { Entry.VariableContainer.prototype.addFunction = function(b) { }; Entry.VariableContainer.prototype.removeFunction = function(b) { - b = b.id; - var a = this.functions_; - a[b].destroy(); - delete a[b]; + var a = b.id; + b = this.functions_; + b[a].destroy(); + delete b[a]; + a = "func_" + a; + Entry.container.removeFuncBlocks(a); + for (var c in b) { + b[c].content.removeBlocksByType(a); + } this.updateList(); }; Entry.VariableContainer.prototype.checkListPosition = function(b, a) { @@ -15855,6 +15860,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); @@ -15863,39 +15869,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; @@ -16724,14 +16733,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()) { @@ -18886,7 +18896,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); }); }; @@ -19161,7 +19171,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 cb14d88159..74f8e21f7d 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={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));"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();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}}};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 40=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"); @@ -1991,9 +1991,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