From 24af2342aac2567af3252f7df8d4e638208d11bc Mon Sep 17 00:00:00 2001 From: jmoenig Date: Mon, 8 Nov 2021 18:19:02 +0100 Subject: [PATCH] fixed upvars in hat block prims when the user clicks on them to run them --- HISTORY.md | 1 + src/objects.js | 2 +- src/threads.js | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 271f334c..46170ea4 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -55,6 +55,7 @@ * objects, store: renamed internal pen color channel cache * objects, blocks, threads: renamed internal pen accessor methods * objects, threads, store, extensions: switched pen color dimensions from HSV to HSL +* threads: fixed upvars in hat block prims when the user clicks on them to run them ### 2021-11-07 * widgets, blocks, byob: allow block-instances to be dragged off from templates in the "hide blocks" dialog diff --git a/src/objects.js b/src/objects.js index b83bdc74..6986f0fc 100644 --- a/src/objects.js +++ b/src/objects.js @@ -8468,7 +8468,7 @@ StageMorph.prototype.fireKeyEvent = function (key) { this.children.concat(this).forEach(morph => { if (isSnapObject(morph)) { morph.allHatBlocksForKey(evt).forEach(block => { - var varName = block.inputs()[1].evaluate()[0], + var varName = block.inputs()[1].evaluate()[0], varFrame; if (varName) { varFrame = new VariableFrame(); diff --git a/src/threads.js b/src/threads.js index 1010a626..5c3e4c1e 100644 --- a/src/threads.js +++ b/src/threads.js @@ -60,11 +60,11 @@ IDE_Morph, ArgLabelMorph, localize, XML_Element, hex_sha512, TableDialogMorph, StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, Map, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, BLACK, TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume, -SnapExtensions, AlignmentMorph, TextMorph, Cloud*/ +SnapExtensions, AlignmentMorph, TextMorph, Cloud, HatBlockMorph*/ /*jshint esversion: 6*/ -modules.threads = '2021-October-22'; +modules.threads = '2021-November-08'; var ThreadManager; var Process; @@ -200,7 +200,17 @@ ThreadManager.prototype.toggleProcess = function (block, receiver) { if (active) { active.stop(); } else { - return this.startProcess(block, receiver, null, null, null, true); + return this.startProcess( + block, + receiver, + null, + null, + null, + true, // isClicked + null, + null, + this.clickFrameFor(block) // for upvars declared inside hat blocks + ); } }; @@ -490,6 +500,24 @@ ThreadManager.prototype.toggleSingleStepping = function () { } }; +ThreadManager.prototype.clickFrameFor = function (block) { + // private - answer a variable frame or null containing upvar declarations + // in certain hat blocks if the user manually clicks on them + var name, frame; + if (block instanceof HatBlockMorph) { + if (block.selector === 'receiveKey' || + block.selector === 'receiveMessage') { + name = block.inputs()[1].evaluate()[0]; + if (name) { + frame = new VariableFrame(); + frame.addVar(name, ''); + return frame; + } + } + } + return null; +}; + // Process ///////////////////////////////////////////////////////////// /*