Last active
July 12, 2025 20:47
-
-
Save arpruss/0437aff7954272ce27bd8ff71c9a48d6 to your computer and use it in GitHub Desktop.
Long-click green flag in Cozmo Code Lab to do turbo mode and no block highlighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -raubB com.digitaldreamlabs.cozmo2-orig/files/cozmo/Scratch/js/common.js com.digitaldreamlabs.cozmo2/files/cozmo/Scratch/js/common.js | |
--- com.digitaldreamlabs.cozmo2-orig/files/cozmo/Scratch/js/common.js 2025-07-12 12:41:59.997230300 -0500 | |
+++ com.digitaldreamlabs.cozmo2/files/cozmo/Scratch/js/common.js 2025-07-12 15:39:45.336174300 -0500 | |
@@ -390,13 +390,14 @@ | |
e.preventDefault(); | |
}); | |
- greenFlag.addEventListener('click', function () { | |
+ var greenflag_press = function(turbo) { | |
Scratch.workspace.playAudio('click'); | |
if (window.programIsRunning) { | |
return; | |
} | |
+ vm.setTurboMode(turbo); | |
vm.greenFlag(); | |
// If no threads were triggered, either because there were no | |
@@ -406,7 +407,56 @@ | |
if (vm.runtime.threads.length < 1) { | |
vm.stopAll(); | |
} | |
- }); | |
+ }; | |
+ | |
+ var greenflag_longpress = false; | |
+ var greenflag_presstimer = null; | |
+ | |
+ var greenflag_cancel = function(e) { | |
+ if (greenflag_presstimer !== null) { | |
+ clearTimeout(greenflag_presstimer); | |
+ greenflag_presstimer = null; | |
+ } | |
+ }; | |
+ | |
+ var greenflag_click = function(e) { | |
+ if (greenflag_presstimer !== null) { | |
+ clearTimeout(greenflag_presstimer); | |
+ greenflag_presstimer = null; | |
+ } | |
+ | |
+ if (greenflag_longpress) { | |
+ return false; | |
+ } | |
+ | |
+ greenflag_press(false); | |
+ }; | |
+ | |
+ var greenflag_start = function(e) { | |
+ if (e.type === "click" && e.button !== 0) { | |
+ return; | |
+ } | |
+ | |
+ greenflag_longpress = false; | |
+ | |
+ if (greenflag_presstimer === null) { | |
+ greenflag_presstimer = setTimeout(function() { | |
+ greenflag_longpress = true; | |
+ greenflag_press(true); | |
+ }, 750); | |
+ } | |
+ | |
+ return false; | |
+ }; | |
+ | |
+ greenFlag.addEventListener("mousedown", greenflag_start); | |
+ greenFlag.addEventListener("touchstart", greenflag_start); | |
+ greenFlag.addEventListener("click", greenflag_click); | |
+ greenFlag.addEventListener("mouseout", greenflag_cancel); | |
+ greenFlag.addEventListener("touchend", greenflag_cancel); | |
+ greenFlag.addEventListener("touchleave", greenflag_cancel); | |
+ greenFlag.addEventListener("touchcancel", greenflag_cancel); | |
+ | |
greenFlag.addEventListener('touchmove', function (e) { | |
e.preventDefault(); | |
}); | |
diff -raubB com.digitaldreamlabs.cozmo2-orig/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.js com.digitaldreamlabs.cozmo2/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.js | |
--- com.digitaldreamlabs.cozmo2-orig/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.js 2025-07-12 12:41:49.924797600 -0500 | |
+++ com.digitaldreamlabs.cozmo2/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.js 2025-07-12 14:16:56.280456200 -0500 | |
@@ -59814,6 +59814,7 @@ | |
}, { | |
key: '_updateGlows', | |
value: function _updateGlows(optExtraThreads) { | |
+ if (this.turboMode) return; | |
var searchThreads = []; | |
searchThreads.push.apply(searchThreads, this.threads); | |
if (optExtraThreads) { | |
diff -raubB com.digitaldreamlabs.cozmo2-orig/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.min.js com.digitaldreamlabs.cozmo2/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.min.js | |
--- com.digitaldreamlabs.cozmo2-orig/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.min.js 2025-07-12 12:41:49.623806100 -0500 | |
+++ com.digitaldreamlabs.cozmo2/files/cozmo/Scratch/lib/vm/dist/web/scratch-vm.min.js 2025-07-12 14:16:26.978196900 -0500 | |
@@ -1087,7 +1087,7 @@ | |
/*!*******************************!*\ | |
!*** ./src/engine/runtime.js ***! | |
\*******************************/ | |
-/*! no static exports found */function(e,n,t){"use strict";var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,n){for(var t=0;t<n.length;t++){var l=n[t];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(e,l.key,l)}}return function(n,t,l){return t&&e(n.prototype,t),l&&e(n,l),n}}();function i(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}var a=t(/*! events */"./node_modules/events/events.js"),o=t(/*! immutable */"./node_modules/immutable/dist/immutable.js").OrderedMap,u=t(/*! escape-html */"./node_modules/escape-html/index.js"),s=t(/*! ../extension-support/argument-type */"./src/extension-support/argument-type.js"),c=t(/*! ./blocks */"./src/engine/blocks.js"),d=t(/*! ../extension-support/block-type */"./src/extension-support/block-type.js"),h=t(/*! ./profiler */"./src/engine/profiler.js"),m=t(/*! ./sequencer */"./src/engine/sequencer.js"),f=t(/*! ./scratch-blocks-constants */"./src/engine/scratch-blocks-constants.js"),p=t(/*! ../extension-support/target-type */"./src/extension-support/target-type.js"),g=t(/*! ./thread */"./src/engine/thread.js"),v=t(/*! ../util/log */"./src/util/log.js"),y=t(/*! ../util/maybe-format-message */"./src/util/maybe-format-message.js"),_=t(/*! ./stage-layering */"./src/engine/stage-layering.js"),b=t(/*! ./variable */"./src/engine/variable.js"),k=t(/*! ../io/clock */"./src/io/clock.js"),w=t(/*! ../io/deviceManager */"./src/io/deviceManager.js"),A=t(/*! ../io/keyboard */"./src/io/keyboard.js"),S=t(/*! ../io/mouse */"./src/io/mouse.js"),T=t(/*! ../io/mouseWheel */"./src/io/mouseWheel.js"),j=t(/*! ../io/userData */"./src/io/userData.js"),E=t(/*! ../io/video */"./src/io/video.js"),I=t(/*! ../util/string-util */"./src/util/string-util.js"),M=t(/*! ../util/uid */"./src/util/uid.js"),x={scratch3_control:t(/*! ../blocks/scratch3_control */"./src/blocks/scratch3_control.js"),scratch3_event:t(/*! ../blocks/scratch3_event */"./src/blocks/scratch3_event.js"),scratch3_looks:t(/*! ../blocks/scratch3_looks */"./src/blocks/scratch3_looks.js"),scratch3_motion:t(/*! ../blocks/scratch3_motion */"./src/blocks/scratch3_motion.js"),scratch3_operators:t(/*! ../blocks/scratch3_operators */"./src/blocks/scratch3_operators.js"),scratch3_sound:t(/*! ../blocks/scratch3_sound */"./src/blocks/scratch3_sound.js"),scratch3_sensing:t(/*! ../blocks/scratch3_sensing */"./src/blocks/scratch3_sensing.js"),scratch3_data:t(/*! ../blocks/scratch3_data */"./src/blocks/scratch3_data.js"),scratch3_procedures:t(/*! ../blocks/scratch3_procedures */"./src/blocks/scratch3_procedures.js"),scratch3_cozmo:t(/*! ../blocks/scratch3_cozmo */"./src/blocks/scratch3_cozmo.js")},N=function(){var e={};return e[s.ANGLE]={shadowType:"math_angle",fieldType:"NUM"},e[s.COLOR]={shadowType:"colour_picker"},e[s.NUMBER]={shadowType:"math_number",fieldType:"NUM"},e[s.STRING]={shadowType:"text",fieldType:"TEXT"},e[s.BOOLEAN]={check:"Boolean"},e[s.MATRIX]={shadowType:"matrix",fieldType:"MATRIX"},e}(),O={info:{},json:null,xml:'<sep gap="36"/>'},C=-1,P=-1,D=-1,z=function(e){function n(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n);var e=function(e,n){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?e:n}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));return e.targets=[],e.threads=[],e.sequencer=new m(e),e.flyoutBlocks=new c,e.monitorBlocks=new c,e._editingTarget=null,e._primitives={},e._blockInfo=[],e._hats={},e._edgeActivatedHatValues={},e._scriptGlowsPreviousFrame=[],e._nonMonitorThreadCount=0,e._cloneCounter=0,e._refreshTargets=!1,e.monitorBlockInfo={},e._monitorState=o({}),e._prevMonitorState=o({}),e.turboMode=!1,e.compatibilityMode=!1,e._steppingInterval=null,e.currentStepTime=null,e.redrawRequested=!1,e._ankiAreThreadsRunning=!1,e._lastBlockGlowed=null,e._registerBlockPackages(),e.ioDevices={clock:new k,deviceManager:new w,keyboard:new A(e),mouse:new S(e),mouseWheel:new T(e),userData:new j,video:new E(e)},e.extensionDevices={},e.profiler=null,e}return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(e,n):e.__proto__=n)}(n,a),r(n,[{key:"_registerBlockPackages",value:function(){for(var e in x)if(x.hasOwnProperty(e)){var n=new x[e](this);if(n.getPrimitives){var t=n.getPrimitives();for(var l in t)t.hasOwnProperty(l)&&(this._primitives[l]=t[l].bind(n))}if(n.getHats){var r=n.getHats();for(var i in r)r.hasOwnProperty(i)&&(this._hats[i]=r[i])}n.getMonitored&&(this.monitorBlockInfo=Object.assign({},this.monitorBlockInfo,n.getMonitored()))}}},{key:"_makeExtensionMenuId",value:function(e,n){return n+"_menu_"+u(e)}},{key:"makeMessageContextForTarget",value:function(e){(e=e||this.getEditingTarget()||this.getTargetForStage())&&(e.isStage?p.STAGE:p.SPRITE)}},{key:"_registerExtensionPrimitives",value:function(e){var t={id:e.id,name:y(e.name),showStatusButton:e.showStatusButton,blockIconURI:e.blockIconURI,menuIconURI:e.menuIconURI,color1:e.colour||"#0FBD8C",color2:e.colourSecondary||"#0DA57A",color3:e.colourTertiary||"#0B8E69",blocks:[],menus:[]};this._blockInfo.push(t),this._fillExtensionCategory(t,e),this.emit(n.EXTENSION_ADDED,t.blocks.concat(t.menus))}},{key:"_refreshExtensionPrimitives",value:function(e){var t=[],l=!0,r=!1,i=void 0;try{for(var a,o=this._blockInfo[Symbol.iterator]();!(l=(a=o.next()).done);l=!0){var u=a.value;e.id===u.id&&(u.name=y(e.name),u.blocks=[],u.menus=[],this._fillExtensionCategory(u,e),t=t.concat(u.blocks,u.menus))}}catch(e){r=!0,i=e}finally{try{!l&&o.return&&o.return()}finally{if(r)throw i}}this.emit(n.BLOCKSINFO_UPDATE,t)}},{key:"_fillExtensionCategory",value:function(e,n){for(var t in n.menus)if(n.menus.hasOwnProperty(t)){var l=n.menus[t],r=this._buildMenuForScratchBlocks(t,l,e);e.menus.push(r)}var i=!0,a=!1,o=void 0;try{for(var u,s=n.blocks[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value;if("---"!==c)try{var h=this._convertForScratchBlocks(c,e),m=h.json.type;e.blocks.push(h),c.blockType!==d.EVENT&&(this._primitives[m]=h.info.func),c.blockType!==d.EVENT&&c.blockType!==d.HAT||(this._hats[m]={edgeActivated:c.isEdgeActivated,restartExistingThreads:c.shouldRestartExistingThreads})}catch(e){v.error("Error parsing block: ",{block:c,error:e})}else e.blocks.push(O)}}catch(e){a=!0,o=e}finally{try{!i&&s.return&&s.return()}finally{if(a)throw o}}}},{key:"_buildMenuForScratchBlocks",value:function(e,n,t){var r=this._makeExtensionMenuId(e,t.id),i=null;if("function"==typeof n)i=n;else{var a=this.makeMessageContextForTarget();i=n.map(function(e){var n=y(e,a);switch(void 0===n?"undefined":l(n)){case"string":return[n,n];case"object":return[y(e.text,a),e.value];default:throw new Error("Can't interpret menu item: "+JSON.stringify(e))}})}return{json:{message0:"%1",type:r,inputsInline:!0,output:"String",colour:t.color1,colourSecondary:t.color2,colourTertiary:t.color3,outputShape:f.OUTPUT_SHAPE_ROUND,args0:[{type:"field_dropdown",name:e,options:i}]}}}},{key:"_convertForScratchBlocks",value:function(e,n){var t=n.id+"_"+e.opcode,l={type:t,inputsInline:!0,category:n.name,colour:n.color1,colourSecondary:n.color2,colourTertiary:n.color3,extensions:["scratch_extension"]},r={argsMap:{},blockJSON:l,categoryInfo:n,blockInfo:e,inputList:[]},i=e.blockIconURI||n.blockIconURI;if(i){l.message0="%1 %2";var a={type:"field_image",src:i,width:40,height:40};l.args0=[a,{type:"field_vertical_separator"}]}switch(e.blockType){case d.COMMAND:l.outputShape=f.OUTPUT_SHAPE_SQUARE,l.previousStatement=null,e.isTerminal||(l.nextStatement=null);break;case d.REPORTER:l.output="String",l.outputShape=f.OUTPUT_SHAPE_ROUND;break;case d.BOOLEAN:l.output="Boolean",l.outputShape=f.OUTPUT_SHAPE_HEXAGONAL;break;case d.HAT:case d.EVENT:e.hasOwnProperty("isEdgeActivated")||(e.isEdgeActivated=!0),l.outputShape=f.OUTPUT_SHAPE_SQUARE,l.nextStatement=null;break;case d.CONDITIONAL:case d.LOOP:e.branchCount=e.branchCount||1,l.outputShape=f.OUTPUT_SHAPE_SQUARE,l.previousStatement=null,e.isTerminal||(l.nextStatement=null)}for(var o=Array.isArray(e.text)?e.text:[e.text],u=0,s=0,c=0,h=this._convertPlaceholders.bind(this,r),m=this.makeMessageContextForTarget();u<o.length||s<e.branchCount;){if(u<o.length){r.outLineNum=c;var p=y(o[u],m).replace(/\[(.+?)]/g,h);l["message"+c]?l["message"+c]+=p:l["message"+c]=p,++u,++c}s<e.branchCount&&(l["message"+c]="%1",l["args"+c]=[{type:"input_statement",name:"SUBSTACK"+(s>0?s+1:"")}],++s,++c)}e.blockType===d.LOOP&&(l["lastDummyAlign"+c]="RIGHT",l["message"+c]="%1",l["args"+c]=[{type:"field_image",src:"./static/blocks-media/repeat.svg",width:24,height:24,alt:"*",flip_rtl:!0}],++c);var g='<block type="'+t+'">'+r.inputList.join("")+"</block>";return{info:r.blockInfo,json:r.blockJSON,xml:g}}},{key:"_convertPlaceholders",value:function(e,n,t){var l={type:"input_value",name:t=t.replace(/[<"&]/,"_")},r=e.blockInfo.arguments[t]||{},i=N[r.type]||{},a=void 0===r.defaultValue?"":u(y(r.defaultValue,this.makeMessageContextForTarget()).toString());i.check&&(l.check=i.check);var o=r.menu?this._makeExtensionMenuId(r.menu,e.categoryInfo.id):i.shadowType,s=r.menu||i.fieldType;e.inputList.push('<value name="'+t+'">'),o&&(e.inputList.push('<shadow type="'+o+'">'),s&&e.inputList.push('<field name="'+s+'">'+a+"</field>"),e.inputList.push("</shadow>")),e.inputList.push("</value>");var c="args"+e.outLineNum,d=e.blockJSON[c]=e.blockJSON[c]||[];d.push(l);var h=d.length;return e.argsMap[t]=h,"%"+h}},{key:"getBlocksXML",value:function(){var e=[],n=!0,t=!1,l=void 0;try{for(var r,i=this._blockInfo[Symbol.iterator]();!(n=(r=i.next()).done);n=!0){var a=r.value,o=a.name,u=a.color1,s=a.color2,c=a.blocks.filter(function(e){return!e.info.hideFromPalette}),d='colour="'+u+'" secondaryColour="'+s+'"',h="";a.menuIconURI?h=a.menuIconURI:a.blockIconURI&&(h=a.blockIconURI);var m=h?'iconURI="'+h+'"':"",f="";a.showStatusButton&&(f='showStatusButton="true"'),e.push('<category name="'+o+'" id="'+a.id+'"\n '+f+" "+d+" "+m+">"),e.push.apply(e,c.map(function(e){return e.xml})),e.push("</category>")}}catch(e){t=!0,l=e}finally{try{!n&&i.return&&i.return()}finally{if(t)throw l}}return e.join("\n")}},{key:"getBlocksJSON",value:function(){return this._blockInfo.reduce(function(e,n){return e.concat(n.blocks.map(function(e){return e.json}))},[])}},{key:"registerExtensionDevice",value:function(e,n){this.extensionDevices[e]=n}},{key:"startDeviceScan",value:function(e){this.extensionDevices[e]&&this.extensionDevices[e].startDeviceScan()}},{key:"connectToPeripheral",value:function(e,n){this.extensionDevices[e]&&this.extensionDevices[e].connectDevice(n)}},{key:"disconnectExtensionSession",value:function(e){this.extensionDevices[e]&&this.extensionDevices[e].disconnectSession()}},{key:"getPeripheralIsConnected",value:function(e){var n=!1;return this.extensionDevices[e]&&(n=this.extensionDevices[e].getPeripheralIsConnected()),n}},{key:"getOpcodeFunction",value:function(e){return this._primitives[e]}},{key:"getIsHat",value:function(e){return this._hats.hasOwnProperty(e)}},{key:"getIsEdgeActivatedHat",value:function(e){return this._hats.hasOwnProperty(e)&&this._hats[e].edgeActivated}},{key:"updateEdgeActivatedValue",value:function(e,n){var t=this._edgeActivatedHatValues[e];return this._edgeActivatedHatValues[e]=n,t}},{key:"clearEdgeActivatedValues",value:function(){this._edgeActivatedHatValues={}}},{key:"attachAudioEngine",value:function(e){this.audioEngine=e}},{key:"attachRenderer",value:function(e){this.renderer=e,this.renderer.setLayerGroupOrdering(_.LAYER_GROUPS)}},{key:"attachV2SVGAdapter",value:function(e){this.v2SvgAdapter=e}},{key:"attachV2BitmapAdapter",value:function(e){this.v2BitmapAdapter=e}},{key:"attachStorage",value:function(e){this.storage=e}},{key:"_ankiUpdateIsRunning",value:function(){this._ankiAreThreadsRunning?0==this.threads.length&&(this._ankiAreThreadsRunning=!1,window.Unity.call({command:"cozmoScriptStopped"}),window.onScriptsStopped()):0!=this.threads.length&&(this._ankiAreThreadsRunning=!0,window.Unity.call({command:"cozmoScriptStarted"}),window.onScriptsStarted())}},{key:"_pushThread",value:function(e,n,t){t=Object.assign({stackClick:!1,updateMonitor:!1},t);var l=new g(e);return l.target=n,l.stackClick=t.stackClick,l.updateMonitor=t.updateMonitor,l.blockContainer=t.updateMonitor?this.monitorBlocks:n.blocks,l.pushStack(e),this.threads.push(l),this._ankiUpdateIsRunning(),l}},{key:"_stopThread",value:function(e){e.isKilled=!0,this.sequencer.retireThread(e),this._ankiUpdateIsRunning()}},{key:"_restartThread",value:function(e){var n=new g(e.topBlock);n.target=e.target,n.stackClick=e.stackClick,n.updateMonitor=e.updateMonitor,n.blockContainer=e.blockContainer,n.pushStack(e.topBlock);var t=this.threads.indexOf(e);return t>-1?(this.threads[t]=n,n):(this.threads.push(e),e)}},{key:"isActiveThread",value:function(e){return e.stack.length>0&&e.status!==g.STATUS_DONE&&this.threads.indexOf(e)>-1}},{key:"isWaitingThread",value:function(e){return e.status===g.STATUS_PROMISE_WAIT||e.status===g.STATUS_YIELD_TICK||!this.isActiveThread(e)}},{key:"toggleScript",value:function(e,n){n=Object.assign({target:this._editingTarget,stackClick:!1},n);for(var t=0;t<this.threads.length;t++)if(this.threads[t].topBlock===e&&this.threads[t].status!==g.STATUS_DONE){var l=n.target.blocks,r=l.getOpcode(l.getBlock(e));if(this.getIsEdgeActivatedHat(r)&&this.threads[t].stackClick!==n.stackClick)continue;return void this._stopThread(this.threads[t])}this._pushThread(e,n.target,n)}},{key:"addMonitorScript",value:function(e,n){n||(n=this._editingTarget);for(var t=0;t<this.threads.length;t++)if(this.threads[t].topBlock===e&&this.threads[t].status!==g.STATUS_DONE&&this.threads[t].updateMonitor)return;this._pushThread(e,n,{updateMonitor:!0})}},{key:"allScriptsDo",value:function(e,n){var t=this.targets;n&&(t=[n]);for(var l=t.length-1;l>=0;l--)for(var r=t[l],i=r.blocks.getScripts(),a=0;a<i.length;a++){e(i[a],r)}}},{key:"startHats",value:function(e,n,t){if(this._hats.hasOwnProperty(e)){var l=this,r=[];for(var i in n)n.hasOwnProperty(i)&&(n[i]=n[i].toUpperCase());return this.allScriptsDo(function(t,i){var a=i.blocks,o=a.getBlock(t);if(o.opcode===e){var u=a.getFields(o);if(0===Object.keys(u).length){u={};var s=a.getInputs(o);for(var c in s)if(s.hasOwnProperty(c)){var d=s[c].block,h=a.getBlock(d),m=a.getFields(h);Object.assign(u,m)}}if(n)for(var f in n)if(u[f].value.toUpperCase()!==n[f])return;if(l._hats[e].restartExistingThreads){for(var p=0;p<l.threads.length;p++)if(l.threads[p].topBlock===t&&!l.threads[p].stackClick&&l.threads[p].target===i)return void r.push(l._restartThread(l.threads[p]))}else for(var v=0;v<l.threads.length;v++)if(l.threads[v].topBlock===t&&l.threads[v].target===i&&!l.threads[v].stackClick&&l.threads[v].status!==g.STATUS_DONE)return;r.push(l._pushThread(t,i))}},t),r}}},{key:"dispose",value:function(){this.stopAll(),this.targets.map(this.disposeTarget,this),this._monitorState=o({})}},{key:"disposeTarget",value:function(e){this.targets=this.targets.filter(function(n){return e!==n||(n.dispose(),!1)})}},{key:"stopForTarget",value:function(e,n){for(var t=0;t<this.threads.length;t++)this.threads[t]!==n&&this.threads[t].target===e&&this._stopThread(this.threads[t])}},{key:"greenFlag",value:function(){this.stopAll(),window.Unity.call({command:"cozmoGreenFlag"}),window.onScriptsStarted(),this.emit(n.PROJECT_START),this.ioDevices.clock.resetProjectTimer(),this.clearEdgeActivatedValues();for(var e=0;e<this.targets.length;e++)this.targets[e].onGreenFlag();this.startHats("event_whenflagclicked")}},{key:"stopAll",value:function(){var e=this;window.Unity.call({command:"cozmoStopAll"}),window.onScriptsStopped(),this.emit(n.PROJECT_STOP_ALL);for(var t=[],l=0;l<this.targets.length;l++)this.targets[l].onStopAll(),this.targets[l].hasOwnProperty("isOriginal")&&!this.targets[l].isOriginal?this.targets[l].dispose():t.push(this.targets[l]);this.targets=t,this.threads.forEach(function(n){return e._stopThread(n)})}},{key:"_step",value:function(){for(var e in null!==this.profiler&&(-1===C&&(C=this.profiler.idByName("Runtime._step")),this.profiler.start(C)),this.threads=this.threads.filter(function(e){return!e.isKilled}),this._hats){if(this._hats.hasOwnProperty(e))this._hats[e].edgeActivated&&this.startHats(e)}this.redrawRequested=!1,this._pushMonitors(),null!==this.profiler&&(-1===P&&(P=this.profiler.idByName("Sequencer.stepThreads")),this.profiler.start(P));var t=this.sequencer.stepThreads();this._ankiUpdateIsRunning(),null!==this.profiler&&this.profiler.stop(),this._updateGlows(t),this._emitProjectRunStatus(this.threads.length+t.length-this._getMonitorThreadCount([].concat(i(this.threads),i(t)))),this.renderer&&(null!==this.profiler&&(-1===D&&(D=this.profiler.idByName("RenderWebGL.draw")),this.profiler.start(D)),this.renderer.draw(),null!==this.profiler&&this.profiler.stop()),this._refreshTargets&&(this.emit(n.TARGETS_UPDATE),this._refreshTargets=!1),this._prevMonitorState.equals(this._monitorState)||(this.emit(n.MONITORS_UPDATE,this._monitorState),this._prevMonitorState=this._monitorState),null!==this.profiler&&(this.profiler.stop(),this.profiler.reportFrames())}},{key:"_getMonitorThreadCount",value:function(e){var n=0;return e.forEach(function(e){e.updateMonitor&&n++}),n}},{key:"_pushMonitors",value:function(){this.monitorBlocks.runAllMonitored(this)}},{key:"setEditingTarget",value:function(e){this._editingTarget=e,this._scriptGlowsPreviousFrame=[],this._updateGlows(),this.requestTargetsUpdate(e)}},{key:"setCompatibilityMode",value:function(e){this.compatibilityMode=e,this._steppingInterval&&(clearInterval(this._steppingInterval),this.start())}},{key:"_updateGlows",value:function(e){var n=[];n.push.apply(n,this.threads),e&&n.push.apply(n,e);for(var t=[],l=[],r=0;r<n.length;r++){var i=n[r],a=i.target;if(a===this._editingTarget){var o=i.blockGlowInFrame;this.glowBlock(i.previousBlockGlowInFrame,!1),this.glowBlock(i.previousPreviousBlockGlowInFrame,!1),0==i.stackFrames.length?this.glowBlock(o,!1):i.previousBlockGlowInFrame!=o&&(this._lastBlockGlowed=o,this.glowBlock(o,!0));var u=a.blocks.getTopLevelScript(o);u||(u=this.flyoutBlocks.getTopLevelScript(o)),u&&t.push(u)}}for(var s=0;s<this._scriptGlowsPreviousFrame.length;s++){var c=this._scriptGlowsPreviousFrame[s];t.indexOf(c)<0?(this.glowScript(c,!1),this._ankiAreThreadsRunning||null==this._lastBlockGlowed||(this.glowBlock(this._lastBlockGlowed,!1),this._lastBlockGlowed=null)):l.push(c)}for(var d=0;d<t.length;d++){var h=t[d];this._scriptGlowsPreviousFrame.indexOf(h)<0&&(this.glowScript(h,!0),l.push(h))}this._scriptGlowsPreviousFrame=l}},{key:"_emitProjectRunStatus",value:function(e){0===this._nonMonitorThreadCount&&e>0&&this.emit(n.PROJECT_RUN_START),this._nonMonitorThreadCount>0&&0===e&&this.emit(n.PROJECT_RUN_STOP),this._nonMonitorThreadCount=e}},{key:"quietGlow",value:function(e){var n=this._scriptGlowsPreviousFrame.indexOf(e);n>-1&&this._scriptGlowsPreviousFrame.splice(n,1)}},{key:"glowBlock",value:function(e,t){t?this.emit(n.BLOCK_GLOW_ON,{id:e}):this.emit(n.BLOCK_GLOW_OFF,{id:e})}},{key:"glowScript",value:function(e,t){t?this.emit(n.SCRIPT_GLOW_ON,{id:e}):this.emit(n.SCRIPT_GLOW_OFF,{id:e})}},{key:"emitBlockDragUpdate",value:function(e){this.emit(n.BLOCK_DRAG_UPDATE,e)}},{key:"emitBlockEndDrag",value:function(e){this.emit(n.BLOCK_DRAG_END,e)}},{key:"visualReport",value:function(e,t){this.emit(n.VISUAL_REPORT,{id:e,value:String(t)})}},{key:"requestAddMonitor",value:function(e){var n=e.get("id");this.requestUpdateMonitor(e)||(this._monitorState=this._monitorState.set(n,e))}},{key:"requestUpdateMonitor",value:function(e){var n=e.get("id");return!!this._monitorState.has(n)&&(this._monitorState=this._monitorState.set(n,this._monitorState.get(n).mergeWith(function(e,n){return void 0===n||null===n?e:n},e)),!0)}},{key:"requestRemoveMonitor",value:function(e){this._monitorState=this._monitorState.delete(e)}},{key:"requestHideMonitor",value:function(e){return this.requestUpdateMonitor(new Map([["id",e],["visible",!1]]))}},{key:"requestShowMonitor",value:function(e){return this.requestUpdateMonitor(new Map([["id",e],["visible",!0]]))}},{key:"requestRemoveMonitorByTargetId",value:function(e){this._monitorState=this._monitorState.filterNot(function(n){return n.targetId===e})}},{key:"getTargetById",value:function(e){for(var n=0;n<this.targets.length;n++){var t=this.targets[n];if(t.id===e)return t}}},{key:"getSpriteTargetByName",value:function(e){for(var n=0;n<this.targets.length;n++){var t=this.targets[n];if(!t.isStage&&(t.sprite&&t.sprite.name===e))return t}}},{key:"getTargetByDrawableId",value:function(e){for(var n=0;n<this.targets.length;n++){var t=this.targets[n];if(t.drawableID===e)return t}}},{key:"changeCloneCounter",value:function(e){this._cloneCounter+=e}},{key:"clonesAvailable",value:function(){return this._cloneCounter<n.MAX_CLONES}},{key:"fireTargetWasCreated",value:function(e,n){this.emit("targetWasCreated",e,n)}},{key:"fireTargetWasRemoved",value:function(e){this.emit("targetWasRemoved",e)}},{key:"getTargetForStage",value:function(){for(var e=0;e<this.targets.length;e++){var n=this.targets[e];if(n.isStage)return n}}},{key:"getEditingTarget",value:function(){return this._editingTarget}},{key:"getAllVarNamesOfType",value:function(e){var n=[],t=!0,l=!1,r=void 0;try{for(var i,a=this.targets[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value.getAllVariableNamesInScopeByType(e,!0);n=n.concat(o)}}catch(e){l=!0,r=e}finally{try{!t&&a.return&&a.return()}finally{if(l)throw r}}return n}},{key:"createNewGlobalVariable",value:function(e,n,t){var l="string"==typeof t?t:b.SCALAR_TYPE,r=this.getAllVarNamesOfType(l),i=I.unusedName(e,r),a=new b(n||M(),i,l);return this.getTargetForStage().variables[a.id]=a,a}},{key:"requestRedraw",value:function(){this.redrawRequested=!0}},{key:"requestTargetsUpdate",value:function(e){e.isOriginal&&(this._refreshTargets=!0)}},{key:"start",value:function(){var e=this,t=n.THREAD_STEP_INTERVAL;this.compatibilityMode&&(t=n.THREAD_STEP_INTERVAL_COMPATIBILITY),this.currentStepTime=t,this._steppingInterval=setInterval(function(){e._step()},t)}},{key:"enableProfiling",value:function(e){h.available()&&(this.profiler=new h(e))}},{key:"disableProfiling",value:function(){this.profiler=null}}],[{key:"STAGE_WIDTH",get:function(){return 480}},{key:"STAGE_HEIGHT",get:function(){return 360}},{key:"SCRIPT_GLOW_ON",get:function(){return"SCRIPT_GLOW_ON"}},{key:"SCRIPT_GLOW_OFF",get:function(){return"SCRIPT_GLOW_OFF"}},{key:"BLOCK_GLOW_ON",get:function(){return"BLOCK_GLOW_ON"}},{key:"BLOCK_GLOW_OFF",get:function(){return"BLOCK_GLOW_OFF"}},{key:"TURBO_MODE_ON",get:function(){return"TURBO_MODE_ON"}},{key:"TURBO_MODE_OFF",get:function(){return"TURBO_MODE_OFF"}},{key:"PROJECT_START",get:function(){return"PROJECT_START"}},{key:"PROJECT_RUN_START",get:function(){return"PROJECT_RUN_START"}},{key:"PROJECT_RUN_STOP",get:function(){return"PROJECT_RUN_STOP"}},{key:"PROJECT_STOP_ALL",get:function(){return"PROJECT_STOP_ALL"}},{key:"VISUAL_REPORT",get:function(){return"VISUAL_REPORT"}},{key:"TARGETS_UPDATE",get:function(){return"TARGETS_UPDATE"}},{key:"MONITORS_UPDATE",get:function(){return"MONITORS_UPDATE"}},{key:"BLOCK_DRAG_UPDATE",get:function(){return"BLOCK_DRAG_UPDATE"}},{key:"BLOCK_DRAG_END",get:function(){return"BLOCK_DRAG_END"}},{key:"EXTENSION_ADDED",get:function(){return"EXTENSION_ADDED"}},{key:"PERIPHERAL_LIST_UPDATE",get:function(){return"PERIPHERAL_LIST_UPDATE"}},{key:"PERIPHERAL_CONNECTED",get:function(){return"PERIPHERAL_CONNECTED"}},{key:"PERIPHERAL_ERROR",get:function(){return"PERIPHERAL_ERROR"}},{key:"PERIPHERAL_SCAN_TIMEOUT",get:function(){return"PERIPHERAL_SCAN_TIMEOUT"}},{key:"BLOCKSINFO_UPDATE",get:function(){return"BLOCKSINFO_UPDATE"}},{key:"THREAD_STEP_INTERVAL",get:function(){return 1e3/60}},{key:"THREAD_STEP_INTERVAL_COMPATIBILITY",get:function(){return 1e3/30}},{key:"MAX_CLONES",get:function(){return 300}}]),n}();e.exports=z},"./src/engine/scratch-blocks-constants.js": | |
+/*! no static exports found */function(e,n,t){"use strict";var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,n){for(var t=0;t<n.length;t++){var l=n[t];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(e,l.key,l)}}return function(n,t,l){return t&&e(n.prototype,t),l&&e(n,l),n}}();function i(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}var a=t(/*! events */"./node_modules/events/events.js"),o=t(/*! immutable */"./node_modules/immutable/dist/immutable.js").OrderedMap,u=t(/*! escape-html */"./node_modules/escape-html/index.js"),s=t(/*! ../extension-support/argument-type */"./src/extension-support/argument-type.js"),c=t(/*! ./blocks */"./src/engine/blocks.js"),d=t(/*! ../extension-support/block-type */"./src/extension-support/block-type.js"),h=t(/*! ./profiler */"./src/engine/profiler.js"),m=t(/*! ./sequencer */"./src/engine/sequencer.js"),f=t(/*! ./scratch-blocks-constants */"./src/engine/scratch-blocks-constants.js"),p=t(/*! ../extension-support/target-type */"./src/extension-support/target-type.js"),g=t(/*! ./thread */"./src/engine/thread.js"),v=t(/*! ../util/log */"./src/util/log.js"),y=t(/*! ../util/maybe-format-message */"./src/util/maybe-format-message.js"),_=t(/*! ./stage-layering */"./src/engine/stage-layering.js"),b=t(/*! ./variable */"./src/engine/variable.js"),k=t(/*! ../io/clock */"./src/io/clock.js"),w=t(/*! ../io/deviceManager */"./src/io/deviceManager.js"),A=t(/*! ../io/keyboard */"./src/io/keyboard.js"),S=t(/*! ../io/mouse */"./src/io/mouse.js"),T=t(/*! ../io/mouseWheel */"./src/io/mouseWheel.js"),j=t(/*! ../io/userData */"./src/io/userData.js"),E=t(/*! ../io/video */"./src/io/video.js"),I=t(/*! ../util/string-util */"./src/util/string-util.js"),M=t(/*! ../util/uid */"./src/util/uid.js"),x={scratch3_control:t(/*! ../blocks/scratch3_control */"./src/blocks/scratch3_control.js"),scratch3_event:t(/*! ../blocks/scratch3_event */"./src/blocks/scratch3_event.js"),scratch3_looks:t(/*! ../blocks/scratch3_looks */"./src/blocks/scratch3_looks.js"),scratch3_motion:t(/*! ../blocks/scratch3_motion */"./src/blocks/scratch3_motion.js"),scratch3_operators:t(/*! ../blocks/scratch3_operators */"./src/blocks/scratch3_operators.js"),scratch3_sound:t(/*! ../blocks/scratch3_sound */"./src/blocks/scratch3_sound.js"),scratch3_sensing:t(/*! ../blocks/scratch3_sensing */"./src/blocks/scratch3_sensing.js"),scratch3_data:t(/*! ../blocks/scratch3_data */"./src/blocks/scratch3_data.js"),scratch3_procedures:t(/*! ../blocks/scratch3_procedures */"./src/blocks/scratch3_procedures.js"),scratch3_cozmo:t(/*! ../blocks/scratch3_cozmo */"./src/blocks/scratch3_cozmo.js")},N=function(){var e={};return e[s.ANGLE]={shadowType:"math_angle",fieldType:"NUM"},e[s.COLOR]={shadowType:"colour_picker"},e[s.NUMBER]={shadowType:"math_number",fieldType:"NUM"},e[s.STRING]={shadowType:"text",fieldType:"TEXT"},e[s.BOOLEAN]={check:"Boolean"},e[s.MATRIX]={shadowType:"matrix",fieldType:"MATRIX"},e}(),O={info:{},json:null,xml:'<sep gap="36"/>'},C=-1,P=-1,D=-1,z=function(e){function n(){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n);var e=function(e,n){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?e:n}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));return e.targets=[],e.threads=[],e.sequencer=new m(e),e.flyoutBlocks=new c,e.monitorBlocks=new c,e._editingTarget=null,e._primitives={},e._blockInfo=[],e._hats={},e._edgeActivatedHatValues={},e._scriptGlowsPreviousFrame=[],e._nonMonitorThreadCount=0,e._cloneCounter=0,e._refreshTargets=!1,e.monitorBlockInfo={},e._monitorState=o({}),e._prevMonitorState=o({}),e.turboMode=!1,e.compatibilityMode=!1,e._steppingInterval=null,e.currentStepTime=null,e.redrawRequested=!1,e._ankiAreThreadsRunning=!1,e._lastBlockGlowed=null,e._registerBlockPackages(),e.ioDevices={clock:new k,deviceManager:new w,keyboard:new A(e),mouse:new S(e),mouseWheel:new T(e),userData:new j,video:new E(e)},e.extensionDevices={},e.profiler=null,e}return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(e,n):e.__proto__=n)}(n,a),r(n,[{key:"_registerBlockPackages",value:function(){for(var e in x)if(x.hasOwnProperty(e)){var n=new x[e](this);if(n.getPrimitives){var t=n.getPrimitives();for(var l in t)t.hasOwnProperty(l)&&(this._primitives[l]=t[l].bind(n))}if(n.getHats){var r=n.getHats();for(var i in r)r.hasOwnProperty(i)&&(this._hats[i]=r[i])}n.getMonitored&&(this.monitorBlockInfo=Object.assign({},this.monitorBlockInfo,n.getMonitored()))}}},{key:"_makeExtensionMenuId",value:function(e,n){return n+"_menu_"+u(e)}},{key:"makeMessageContextForTarget",value:function(e){(e=e||this.getEditingTarget()||this.getTargetForStage())&&(e.isStage?p.STAGE:p.SPRITE)}},{key:"_registerExtensionPrimitives",value:function(e){var t={id:e.id,name:y(e.name),showStatusButton:e.showStatusButton,blockIconURI:e.blockIconURI,menuIconURI:e.menuIconURI,color1:e.colour||"#0FBD8C",color2:e.colourSecondary||"#0DA57A",color3:e.colourTertiary||"#0B8E69",blocks:[],menus:[]};this._blockInfo.push(t),this._fillExtensionCategory(t,e),this.emit(n.EXTENSION_ADDED,t.blocks.concat(t.menus))}},{key:"_refreshExtensionPrimitives",value:function(e){var t=[],l=!0,r=!1,i=void 0;try{for(var a,o=this._blockInfo[Symbol.iterator]();!(l=(a=o.next()).done);l=!0){var u=a.value;e.id===u.id&&(u.name=y(e.name),u.blocks=[],u.menus=[],this._fillExtensionCategory(u,e),t=t.concat(u.blocks,u.menus))}}catch(e){r=!0,i=e}finally{try{!l&&o.return&&o.return()}finally{if(r)throw i}}this.emit(n.BLOCKSINFO_UPDATE,t)}},{key:"_fillExtensionCategory",value:function(e,n){for(var t in n.menus)if(n.menus.hasOwnProperty(t)){var l=n.menus[t],r=this._buildMenuForScratchBlocks(t,l,e);e.menus.push(r)}var i=!0,a=!1,o=void 0;try{for(var u,s=n.blocks[Symbol.iterator]();!(i=(u=s.next()).done);i=!0){var c=u.value;if("---"!==c)try{var h=this._convertForScratchBlocks(c,e),m=h.json.type;e.blocks.push(h),c.blockType!==d.EVENT&&(this._primitives[m]=h.info.func),c.blockType!==d.EVENT&&c.blockType!==d.HAT||(this._hats[m]={edgeActivated:c.isEdgeActivated,restartExistingThreads:c.shouldRestartExistingThreads})}catch(e){v.error("Error parsing block: ",{block:c,error:e})}else e.blocks.push(O)}}catch(e){a=!0,o=e}finally{try{!i&&s.return&&s.return()}finally{if(a)throw o}}}},{key:"_buildMenuForScratchBlocks",value:function(e,n,t){var r=this._makeExtensionMenuId(e,t.id),i=null;if("function"==typeof n)i=n;else{var a=this.makeMessageContextForTarget();i=n.map(function(e){var n=y(e,a);switch(void 0===n?"undefined":l(n)){case"string":return[n,n];case"object":return[y(e.text,a),e.value];default:throw new Error("Can't interpret menu item: "+JSON.stringify(e))}})}return{json:{message0:"%1",type:r,inputsInline:!0,output:"String",colour:t.color1,colourSecondary:t.color2,colourTertiary:t.color3,outputShape:f.OUTPUT_SHAPE_ROUND,args0:[{type:"field_dropdown",name:e,options:i}]}}}},{key:"_convertForScratchBlocks",value:function(e,n){var t=n.id+"_"+e.opcode,l={type:t,inputsInline:!0,category:n.name,colour:n.color1,colourSecondary:n.color2,colourTertiary:n.color3,extensions:["scratch_extension"]},r={argsMap:{},blockJSON:l,categoryInfo:n,blockInfo:e,inputList:[]},i=e.blockIconURI||n.blockIconURI;if(i){l.message0="%1 %2";var a={type:"field_image",src:i,width:40,height:40};l.args0=[a,{type:"field_vertical_separator"}]}switch(e.blockType){case d.COMMAND:l.outputShape=f.OUTPUT_SHAPE_SQUARE,l.previousStatement=null,e.isTerminal||(l.nextStatement=null);break;case d.REPORTER:l.output="String",l.outputShape=f.OUTPUT_SHAPE_ROUND;break;case d.BOOLEAN:l.output="Boolean",l.outputShape=f.OUTPUT_SHAPE_HEXAGONAL;break;case d.HAT:case d.EVENT:e.hasOwnProperty("isEdgeActivated")||(e.isEdgeActivated=!0),l.outputShape=f.OUTPUT_SHAPE_SQUARE,l.nextStatement=null;break;case d.CONDITIONAL:case d.LOOP:e.branchCount=e.branchCount||1,l.outputShape=f.OUTPUT_SHAPE_SQUARE,l.previousStatement=null,e.isTerminal||(l.nextStatement=null)}for(var o=Array.isArray(e.text)?e.text:[e.text],u=0,s=0,c=0,h=this._convertPlaceholders.bind(this,r),m=this.makeMessageContextForTarget();u<o.length||s<e.branchCount;){if(u<o.length){r.outLineNum=c;var p=y(o[u],m).replace(/\[(.+?)]/g,h);l["message"+c]?l["message"+c]+=p:l["message"+c]=p,++u,++c}s<e.branchCount&&(l["message"+c]="%1",l["args"+c]=[{type:"input_statement",name:"SUBSTACK"+(s>0?s+1:"")}],++s,++c)}e.blockType===d.LOOP&&(l["lastDummyAlign"+c]="RIGHT",l["message"+c]="%1",l["args"+c]=[{type:"field_image",src:"./static/blocks-media/repeat.svg",width:24,height:24,alt:"*",flip_rtl:!0}],++c);var g='<block type="'+t+'">'+r.inputList.join("")+"</block>";return{info:r.blockInfo,json:r.blockJSON,xml:g}}},{key:"_convertPlaceholders",value:function(e,n,t){var l={type:"input_value",name:t=t.replace(/[<"&]/,"_")},r=e.blockInfo.arguments[t]||{},i=N[r.type]||{},a=void 0===r.defaultValue?"":u(y(r.defaultValue,this.makeMessageContextForTarget()).toString());i.check&&(l.check=i.check);var o=r.menu?this._makeExtensionMenuId(r.menu,e.categoryInfo.id):i.shadowType,s=r.menu||i.fieldType;e.inputList.push('<value name="'+t+'">'),o&&(e.inputList.push('<shadow type="'+o+'">'),s&&e.inputList.push('<field name="'+s+'">'+a+"</field>"),e.inputList.push("</shadow>")),e.inputList.push("</value>");var c="args"+e.outLineNum,d=e.blockJSON[c]=e.blockJSON[c]||[];d.push(l);var h=d.length;return e.argsMap[t]=h,"%"+h}},{key:"getBlocksXML",value:function(){var e=[],n=!0,t=!1,l=void 0;try{for(var r,i=this._blockInfo[Symbol.iterator]();!(n=(r=i.next()).done);n=!0){var a=r.value,o=a.name,u=a.color1,s=a.color2,c=a.blocks.filter(function(e){return!e.info.hideFromPalette}),d='colour="'+u+'" secondaryColour="'+s+'"',h="";a.menuIconURI?h=a.menuIconURI:a.blockIconURI&&(h=a.blockIconURI);var m=h?'iconURI="'+h+'"':"",f="";a.showStatusButton&&(f='showStatusButton="true"'),e.push('<category name="'+o+'" id="'+a.id+'"\n '+f+" "+d+" "+m+">"),e.push.apply(e,c.map(function(e){return e.xml})),e.push("</category>")}}catch(e){t=!0,l=e}finally{try{!n&&i.return&&i.return()}finally{if(t)throw l}}return e.join("\n")}},{key:"getBlocksJSON",value:function(){return this._blockInfo.reduce(function(e,n){return e.concat(n.blocks.map(function(e){return e.json}))},[])}},{key:"registerExtensionDevice",value:function(e,n){this.extensionDevices[e]=n}},{key:"startDeviceScan",value:function(e){this.extensionDevices[e]&&this.extensionDevices[e].startDeviceScan()}},{key:"connectToPeripheral",value:function(e,n){this.extensionDevices[e]&&this.extensionDevices[e].connectDevice(n)}},{key:"disconnectExtensionSession",value:function(e){this.extensionDevices[e]&&this.extensionDevices[e].disconnectSession()}},{key:"getPeripheralIsConnected",value:function(e){var n=!1;return this.extensionDevices[e]&&(n=this.extensionDevices[e].getPeripheralIsConnected()),n}},{key:"getOpcodeFunction",value:function(e){return this._primitives[e]}},{key:"getIsHat",value:function(e){return this._hats.hasOwnProperty(e)}},{key:"getIsEdgeActivatedHat",value:function(e){return this._hats.hasOwnProperty(e)&&this._hats[e].edgeActivated}},{key:"updateEdgeActivatedValue",value:function(e,n){var t=this._edgeActivatedHatValues[e];return this._edgeActivatedHatValues[e]=n,t}},{key:"clearEdgeActivatedValues",value:function(){this._edgeActivatedHatValues={}}},{key:"attachAudioEngine",value:function(e){this.audioEngine=e}},{key:"attachRenderer",value:function(e){this.renderer=e,this.renderer.setLayerGroupOrdering(_.LAYER_GROUPS)}},{key:"attachV2SVGAdapter",value:function(e){this.v2SvgAdapter=e}},{key:"attachV2BitmapAdapter",value:function(e){this.v2BitmapAdapter=e}},{key:"attachStorage",value:function(e){this.storage=e}},{key:"_ankiUpdateIsRunning",value:function(){this._ankiAreThreadsRunning?0==this.threads.length&&(this._ankiAreThreadsRunning=!1,window.Unity.call({command:"cozmoScriptStopped"}),window.onScriptsStopped()):0!=this.threads.length&&(this._ankiAreThreadsRunning=!0,window.Unity.call({command:"cozmoScriptStarted"}),window.onScriptsStarted())}},{key:"_pushThread",value:function(e,n,t){t=Object.assign({stackClick:!1,updateMonitor:!1},t);var l=new g(e);return l.target=n,l.stackClick=t.stackClick,l.updateMonitor=t.updateMonitor,l.blockContainer=t.updateMonitor?this.monitorBlocks:n.blocks,l.pushStack(e),this.threads.push(l),this._ankiUpdateIsRunning(),l}},{key:"_stopThread",value:function(e){e.isKilled=!0,this.sequencer.retireThread(e),this._ankiUpdateIsRunning()}},{key:"_restartThread",value:function(e){var n=new g(e.topBlock);n.target=e.target,n.stackClick=e.stackClick,n.updateMonitor=e.updateMonitor,n.blockContainer=e.blockContainer,n.pushStack(e.topBlock);var t=this.threads.indexOf(e);return t>-1?(this.threads[t]=n,n):(this.threads.push(e),e)}},{key:"isActiveThread",value:function(e){return e.stack.length>0&&e.status!==g.STATUS_DONE&&this.threads.indexOf(e)>-1}},{key:"isWaitingThread",value:function(e){return e.status===g.STATUS_PROMISE_WAIT||e.status===g.STATUS_YIELD_TICK||!this.isActiveThread(e)}},{key:"toggleScript",value:function(e,n){n=Object.assign({target:this._editingTarget,stackClick:!1},n);for(var t=0;t<this.threads.length;t++)if(this.threads[t].topBlock===e&&this.threads[t].status!==g.STATUS_DONE){var l=n.target.blocks,r=l.getOpcode(l.getBlock(e));if(this.getIsEdgeActivatedHat(r)&&this.threads[t].stackClick!==n.stackClick)continue;return void this._stopThread(this.threads[t])}this._pushThread(e,n.target,n)}},{key:"addMonitorScript",value:function(e,n){n||(n=this._editingTarget);for(var t=0;t<this.threads.length;t++)if(this.threads[t].topBlock===e&&this.threads[t].status!==g.STATUS_DONE&&this.threads[t].updateMonitor)return;this._pushThread(e,n,{updateMonitor:!0})}},{key:"allScriptsDo",value:function(e,n){var t=this.targets;n&&(t=[n]);for(var l=t.length-1;l>=0;l--)for(var r=t[l],i=r.blocks.getScripts(),a=0;a<i.length;a++){e(i[a],r)}}},{key:"startHats",value:function(e,n,t){if(this._hats.hasOwnProperty(e)){var l=this,r=[];for(var i in n)n.hasOwnProperty(i)&&(n[i]=n[i].toUpperCase());return this.allScriptsDo(function(t,i){var a=i.blocks,o=a.getBlock(t);if(o.opcode===e){var u=a.getFields(o);if(0===Object.keys(u).length){u={};var s=a.getInputs(o);for(var c in s)if(s.hasOwnProperty(c)){var d=s[c].block,h=a.getBlock(d),m=a.getFields(h);Object.assign(u,m)}}if(n)for(var f in n)if(u[f].value.toUpperCase()!==n[f])return;if(l._hats[e].restartExistingThreads){for(var p=0;p<l.threads.length;p++)if(l.threads[p].topBlock===t&&!l.threads[p].stackClick&&l.threads[p].target===i)return void r.push(l._restartThread(l.threads[p]))}else for(var v=0;v<l.threads.length;v++)if(l.threads[v].topBlock===t&&l.threads[v].target===i&&!l.threads[v].stackClick&&l.threads[v].status!==g.STATUS_DONE)return;r.push(l._pushThread(t,i))}},t),r}}},{key:"dispose",value:function(){this.stopAll(),this.targets.map(this.disposeTarget,this),this._monitorState=o({})}},{key:"disposeTarget",value:function(e){this.targets=this.targets.filter(function(n){return e!==n||(n.dispose(),!1)})}},{key:"stopForTarget",value:function(e,n){for(var t=0;t<this.threads.length;t++)this.threads[t]!==n&&this.threads[t].target===e&&this._stopThread(this.threads[t])}},{key:"greenFlag",value:function(){this.stopAll(),window.Unity.call({command:"cozmoGreenFlag"}),window.onScriptsStarted(),this.emit(n.PROJECT_START),this.ioDevices.clock.resetProjectTimer(),this.clearEdgeActivatedValues();for(var e=0;e<this.targets.length;e++)this.targets[e].onGreenFlag();this.startHats("event_whenflagclicked")}},{key:"stopAll",value:function(){var e=this;window.Unity.call({command:"cozmoStopAll"}),window.onScriptsStopped(),this.emit(n.PROJECT_STOP_ALL);for(var t=[],l=0;l<this.targets.length;l++)this.targets[l].onStopAll(),this.targets[l].hasOwnProperty("isOriginal")&&!this.targets[l].isOriginal?this.targets[l].dispose():t.push(this.targets[l]);this.targets=t,this.threads.forEach(function(n){return e._stopThread(n)})}},{key:"_step",value:function(){for(var e in null!==this.profiler&&(-1===C&&(C=this.profiler.idByName("Runtime._step")),this.profiler.start(C)),this.threads=this.threads.filter(function(e){return!e.isKilled}),this._hats){if(this._hats.hasOwnProperty(e))this._hats[e].edgeActivated&&this.startHats(e)}this.redrawRequested=!1,this._pushMonitors(),null!==this.profiler&&(-1===P&&(P=this.profiler.idByName("Sequencer.stepThreads")),this.profiler.start(P));var t=this.sequencer.stepThreads();this._ankiUpdateIsRunning(),null!==this.profiler&&this.profiler.stop(),this._updateGlows(t),this._emitProjectRunStatus(this.threads.length+t.length-this._getMonitorThreadCount([].concat(i(this.threads),i(t)))),this.renderer&&(null!==this.profiler&&(-1===D&&(D=this.profiler.idByName("RenderWebGL.draw")),this.profiler.start(D)),this.renderer.draw(),null!==this.profiler&&this.profiler.stop()),this._refreshTargets&&(this.emit(n.TARGETS_UPDATE),this._refreshTargets=!1),this._prevMonitorState.equals(this._monitorState)||(this.emit(n.MONITORS_UPDATE,this._monitorState),this._prevMonitorState=this._monitorState),null!==this.profiler&&(this.profiler.stop(),this.profiler.reportFrames())}},{key:"_getMonitorThreadCount",value:function(e){var n=0;return e.forEach(function(e){e.updateMonitor&&n++}),n}},{key:"_pushMonitors",value:function(){this.monitorBlocks.runAllMonitored(this)}},{key:"setEditingTarget",value:function(e){this._editingTarget=e,this._scriptGlowsPreviousFrame=[],this._updateGlows(),this.requestTargetsUpdate(e)}},{key:"setCompatibilityMode",value:function(e){this.compatibilityMode=e,this._steppingInterval&&(clearInterval(this._steppingInterval),this.start())}},{key:"_updateGlows",value:function(e){if(this.turboMode)return;var n=[];n.push.apply(n,this.threads),e&&n.push.apply(n,e);for(var t=[],l=[],r=0;r<n.length;r++){var i=n[r],a=i.target;if(a===this._editingTarget){var o=i.blockGlowInFrame;this.glowBlock(i.previousBlockGlowInFrame,!1),this.glowBlock(i.previousPreviousBlockGlowInFrame,!1),0==i.stackFrames.length?this.glowBlock(o,!1):i.previousBlockGlowInFrame!=o&&(this._lastBlockGlowed=o,this.glowBlock(o,!0));var u=a.blocks.getTopLevelScript(o);u||(u=this.flyoutBlocks.getTopLevelScript(o)),u&&t.push(u)}}for(var s=0;s<this._scriptGlowsPreviousFrame.length;s++){var c=this._scriptGlowsPreviousFrame[s];t.indexOf(c)<0?(this.glowScript(c,!1),this._ankiAreThreadsRunning||null==this._lastBlockGlowed||(this.glowBlock(this._lastBlockGlowed,!1),this._lastBlockGlowed=null)):l.push(c)}for(var d=0;d<t.length;d++){var h=t[d];this._scriptGlowsPreviousFrame.indexOf(h)<0&&(this.glowScript(h,!0),l.push(h))}this._scriptGlowsPreviousFrame=l}},{key:"_emitProjectRunStatus",value:function(e){0===this._nonMonitorThreadCount&&e>0&&this.emit(n.PROJECT_RUN_START),this._nonMonitorThreadCount>0&&0===e&&this.emit(n.PROJECT_RUN_STOP),this._nonMonitorThreadCount=e}},{key:"quietGlow",value:function(e){var n=this._scriptGlowsPreviousFrame.indexOf(e);n>-1&&this._scriptGlowsPreviousFrame.splice(n,1)}},{key:"glowBlock",value:function(e,t){t?this.emit(n.BLOCK_GLOW_ON,{id:e}):this.emit(n.BLOCK_GLOW_OFF,{id:e})}},{key:"glowScript",value:function(e,t){t?this.emit(n.SCRIPT_GLOW_ON,{id:e}):this.emit(n.SCRIPT_GLOW_OFF,{id:e})}},{key:"emitBlockDragUpdate",value:function(e){this.emit(n.BLOCK_DRAG_UPDATE,e)}},{key:"emitBlockEndDrag",value:function(e){this.emit(n.BLOCK_DRAG_END,e)}},{key:"visualReport",value:function(e,t){this.emit(n.VISUAL_REPORT,{id:e,value:String(t)})}},{key:"requestAddMonitor",value:function(e){var n=e.get("id");this.requestUpdateMonitor(e)||(this._monitorState=this._monitorState.set(n,e))}},{key:"requestUpdateMonitor",value:function(e){var n=e.get("id");return!!this._monitorState.has(n)&&(this._monitorState=this._monitorState.set(n,this._monitorState.get(n).mergeWith(function(e,n){return void 0===n||null===n?e:n},e)),!0)}},{key:"requestRemoveMonitor",value:function(e){this._monitorState=this._monitorState.delete(e)}},{key:"requestHideMonitor",value:function(e){return this.requestUpdateMonitor(new Map([["id",e],["visible",!1]]))}},{key:"requestShowMonitor",value:function(e){return this.requestUpdateMonitor(new Map([["id",e],["visible",!0]]))}},{key:"requestRemoveMonitorByTargetId",value:function(e){this._monitorState=this._monitorState.filterNot(function(n){return n.targetId===e})}},{key:"getTargetById",value:function(e){for(var n=0;n<this.targets.length;n++){var t=this.targets[n];if(t.id===e)return t}}},{key:"getSpriteTargetByName",value:function(e){for(var n=0;n<this.targets.length;n++){var t=this.targets[n];if(!t.isStage&&(t.sprite&&t.sprite.name===e))return t}}},{key:"getTargetByDrawableId",value:function(e){for(var n=0;n<this.targets.length;n++){var t=this.targets[n];if(t.drawableID===e)return t}}},{key:"changeCloneCounter",value:function(e){this._cloneCounter+=e}},{key:"clonesAvailable",value:function(){return this._cloneCounter<n.MAX_CLONES}},{key:"fireTargetWasCreated",value:function(e,n){this.emit("targetWasCreated",e,n)}},{key:"fireTargetWasRemoved",value:function(e){this.emit("targetWasRemoved",e)}},{key:"getTargetForStage",value:function(){for(var e=0;e<this.targets.length;e++){var n=this.targets[e];if(n.isStage)return n}}},{key:"getEditingTarget",value:function(){return this._editingTarget}},{key:"getAllVarNamesOfType",value:function(e){var n=[],t=!0,l=!1,r=void 0;try{for(var i,a=this.targets[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value.getAllVariableNamesInScopeByType(e,!0);n=n.concat(o)}}catch(e){l=!0,r=e}finally{try{!t&&a.return&&a.return()}finally{if(l)throw r}}return n}},{key:"createNewGlobalVariable",value:function(e,n,t){var l="string"==typeof t?t:b.SCALAR_TYPE,r=this.getAllVarNamesOfType(l),i=I.unusedName(e,r),a=new b(n||M(),i,l);return this.getTargetForStage().variables[a.id]=a,a}},{key:"requestRedraw",value:function(){this.redrawRequested=!0}},{key:"requestTargetsUpdate",value:function(e){e.isOriginal&&(this._refreshTargets=!0)}},{key:"start",value:function(){var e=this,t=n.THREAD_STEP_INTERVAL;this.compatibilityMode&&(t=n.THREAD_STEP_INTERVAL_COMPATIBILITY),this.currentStepTime=t,this._steppingInterval=setInterval(function(){e._step()},t)}},{key:"enableProfiling",value:function(e){h.available()&&(this.profiler=new h(e))}},{key:"disableProfiling",value:function(){this.profiler=null}}],[{key:"STAGE_WIDTH",get:function(){return 480}},{key:"STAGE_HEIGHT",get:function(){return 360}},{key:"SCRIPT_GLOW_ON",get:function(){return"SCRIPT_GLOW_ON"}},{key:"SCRIPT_GLOW_OFF",get:function(){return"SCRIPT_GLOW_OFF"}},{key:"BLOCK_GLOW_ON",get:function(){return"BLOCK_GLOW_ON"}},{key:"BLOCK_GLOW_OFF",get:function(){return"BLOCK_GLOW_OFF"}},{key:"TURBO_MODE_ON",get:function(){return"TURBO_MODE_ON"}},{key:"TURBO_MODE_OFF",get:function(){return"TURBO_MODE_OFF"}},{key:"PROJECT_START",get:function(){return"PROJECT_START"}},{key:"PROJECT_RUN_START",get:function(){return"PROJECT_RUN_START"}},{key:"PROJECT_RUN_STOP",get:function(){return"PROJECT_RUN_STOP"}},{key:"PROJECT_STOP_ALL",get:function(){return"PROJECT_STOP_ALL"}},{key:"VISUAL_REPORT",get:function(){return"VISUAL_REPORT"}},{key:"TARGETS_UPDATE",get:function(){return"TARGETS_UPDATE"}},{key:"MONITORS_UPDATE",get:function(){return"MONITORS_UPDATE"}},{key:"BLOCK_DRAG_UPDATE",get:function(){return"BLOCK_DRAG_UPDATE"}},{key:"BLOCK_DRAG_END",get:function(){return"BLOCK_DRAG_END"}},{key:"EXTENSION_ADDED",get:function(){return"EXTENSION_ADDED"}},{key:"PERIPHERAL_LIST_UPDATE",get:function(){return"PERIPHERAL_LIST_UPDATE"}},{key:"PERIPHERAL_CONNECTED",get:function(){return"PERIPHERAL_CONNECTED"}},{key:"PERIPHERAL_ERROR",get:function(){return"PERIPHERAL_ERROR"}},{key:"PERIPHERAL_SCAN_TIMEOUT",get:function(){return"PERIPHERAL_SCAN_TIMEOUT"}},{key:"BLOCKSINFO_UPDATE",get:function(){return"BLOCKSINFO_UPDATE"}},{key:"THREAD_STEP_INTERVAL",get:function(){return 1e3/60}},{key:"THREAD_STEP_INTERVAL_COMPATIBILITY",get:function(){return 1e3/30}},{key:"MAX_CLONES",get:function(){return 300}}]),n}();e.exports=z},"./src/engine/scratch-blocks-constants.js": | |
/*!************************************************!*\ | |
!*** ./src/engine/scratch-blocks-constants.js ***! | |
\************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment