fix greater than hat block click activation, and also event activation which was only on half the time

This commit is contained in:
DD Liu 2017-07-12 15:43:13 -04:00
parent 6fa49b1e7a
commit 3722aefb17
3 changed files with 31 additions and 17 deletions

View file

@ -198,7 +198,7 @@ class Blocks {
// UI event: clicked scripts toggle in the runtime. // UI event: clicked scripts toggle in the runtime.
if (e.element === 'stackclick') { if (e.element === 'stackclick') {
if (optRuntime) { if (optRuntime) {
optRuntime.toggleScript(e.blockId, {showVisualReport: true}); optRuntime.toggleScript(e.blockId, {stackClick: true});
} }
return; return;
} }

View file

@ -74,14 +74,17 @@ const execute = function (sequencer, thread) {
// Hat predicate was evaluated. // Hat predicate was evaluated.
if (runtime.getIsEdgeActivatedHat(opcode)) { if (runtime.getIsEdgeActivatedHat(opcode)) {
// If this is an edge-activated hat, only proceed if // If this is an edge-activated hat, only proceed if
// the value is true and used to be false. // the value is true and used to be false, or the stack was activated
const oldEdgeValue = runtime.updateEdgeActivatedValue( // explicitly via stack click
currentBlockId, if (!thread.stackClick) {
resolvedValue const oldEdgeValue = runtime.updateEdgeActivatedValue(
); currentBlockId,
const edgeWasActivated = !oldEdgeValue && resolvedValue; resolvedValue
if (!edgeWasActivated) { );
sequencer.retireThread(thread); const edgeWasActivated = !oldEdgeValue && resolvedValue;
if (!edgeWasActivated) {
sequencer.retireThread(thread);
}
} }
} else { } else {
// Not an edge-activated hat: retire the thread // Not an edge-activated hat: retire the thread
@ -94,7 +97,7 @@ const execute = function (sequencer, thread) {
// In a non-hat, report the value visually if necessary if // In a non-hat, report the value visually if necessary if
// at the top of the thread stack. // at the top of the thread stack.
if (typeof resolvedValue !== 'undefined' && thread.atStackTop()) { if (typeof resolvedValue !== 'undefined' && thread.atStackTop()) {
if (thread.showVisualReport) { if (thread.stackClick) {
runtime.visualReport(currentBlockId, resolvedValue); runtime.visualReport(currentBlockId, resolvedValue);
} }
if (thread.updateMonitor) { if (thread.updateMonitor) {

View file

@ -399,19 +399,19 @@ class Runtime extends EventEmitter {
* @param {!string} id ID of block that starts the stack. * @param {!string} id ID of block that starts the stack.
* @param {!Target} target Target to run thread on. * @param {!Target} target Target to run thread on.
* @param {?object} opts optional arguments * @param {?object} opts optional arguments
* @param {?boolean} opts.showVisualReport true if the script should show speech bubble for its value * @param {?boolean} opts.stackClick true if the script was activated by clicking on the stack
* @param {?boolean} opts.updateMonitor true if the script should update a monitor value * @param {?boolean} opts.updateMonitor true if the script should update a monitor value
* @return {!Thread} The newly created thread. * @return {!Thread} The newly created thread.
*/ */
_pushThread (id, target, opts) { _pushThread (id, target, opts) {
opts = Object.assign({ opts = Object.assign({
showVisualReport: false, stackClick: false,
updateMonitor: false updateMonitor: false
}, opts); }, opts);
const thread = new Thread(id); const thread = new Thread(id);
thread.target = target; thread.target = target;
thread.showVisualReport = opts.showVisualReport; thread.stackClick = opts.stackClick;
thread.updateMonitor = opts.updateMonitor; thread.updateMonitor = opts.updateMonitor;
thread.pushStack(id); thread.pushStack(id);
@ -442,7 +442,7 @@ class Runtime extends EventEmitter {
_restartThread (thread) { _restartThread (thread) {
const newThread = new Thread(thread.topBlock); const newThread = new Thread(thread.topBlock);
newThread.target = thread.target; newThread.target = thread.target;
newThread.showVisualReport = thread.showVisualReport; newThread.stackClick = thread.stackClick;
newThread.updateMonitor = thread.updateMonitor; newThread.updateMonitor = thread.updateMonitor;
newThread.pushStack(thread.topBlock); newThread.pushStack(thread.topBlock);
const i = this.threads.indexOf(thread); const i = this.threads.indexOf(thread);
@ -467,18 +467,27 @@ class Runtime extends EventEmitter {
* @param {!string} topBlockId ID of block that starts the script. * @param {!string} topBlockId ID of block that starts the script.
* @param {?object} opts optional arguments to toggle script * @param {?object} opts optional arguments to toggle script
* @param {?string} opts.target target ID for target to run script on. If not supplied, uses editing target. * @param {?string} opts.target target ID for target to run script on. If not supplied, uses editing target.
* @param {?boolean} opts.showVisualReport true if the speech bubble should pop up on the block, false if not. * @param {?boolean} opts.stackClick true if the user activated the stack by clicking, false if not.
* @param {?boolean} opts.updateMonitor true if the monitor for this block should get updated. * @param {?boolean} opts.updateMonitor true if the monitor for this block should get updated.
*/ */
toggleScript (topBlockId, opts) { toggleScript (topBlockId, opts) {
opts = Object.assign({ opts = Object.assign({
target: this._editingTarget, target: this._editingTarget,
showVisualReport: false, stackClick: false,
updateMonitor: false updateMonitor: false
}, opts); }, opts);
// Remove any existing thread. // Remove any existing thread.
for (let i = 0; i < this.threads.length; i++) { for (let i = 0; i < this.threads.length; i++) {
if (this.threads[i].topBlock === topBlockId) { if (this.threads[i].topBlock === topBlockId) {
const blockContainer = opts.target.blocks;
const opcode = blockContainer.getOpcode(blockContainer.getBlock(topBlockId));
if (this.getIsEdgeActivatedHat(opcode) && this.threads[i].stackClick !== opts.stackClick) {
// Allow edge activated hat thread stack click to coexist with
// edge activated hat thread that runs every frame
continue;
}
this._removeThread(this.threads[i]); this._removeThread(this.threads[i]);
return; return;
} }
@ -487,6 +496,7 @@ class Runtime extends EventEmitter {
this._pushThread(topBlockId, opts.target, opts); this._pushThread(topBlockId, opts.target, opts);
} }
/** /**
* Run a function `f` for all scripts in a workspace. * Run a function `f` for all scripts in a workspace.
* `f` will be called with two parameters: * `f` will be called with two parameters:
@ -587,7 +597,8 @@ class Runtime extends EventEmitter {
// give up if any threads with the top block are running. // give up if any threads with the top block are running.
for (let j = 0; j < instance.threads.length; j++) { for (let j = 0; j < instance.threads.length; j++) {
if (instance.threads[j].topBlock === topBlockId && if (instance.threads[j].topBlock === topBlockId &&
instance.threads[j].target === target) { instance.threads[j].target === target &&
!instance.threads[j].status === Thread.STATUS_DONE) {
// Some thread is already running. // Some thread is already running.
return; return;
} }