mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
fix greater than hat block click activation, and also event activation which was only on half the time
This commit is contained in:
parent
6fa49b1e7a
commit
3722aefb17
3 changed files with 31 additions and 17 deletions
|
@ -198,7 +198,7 @@ class Blocks {
|
|||
// UI event: clicked scripts toggle in the runtime.
|
||||
if (e.element === 'stackclick') {
|
||||
if (optRuntime) {
|
||||
optRuntime.toggleScript(e.blockId, {showVisualReport: true});
|
||||
optRuntime.toggleScript(e.blockId, {stackClick: true});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -74,14 +74,17 @@ const execute = function (sequencer, thread) {
|
|||
// Hat predicate was evaluated.
|
||||
if (runtime.getIsEdgeActivatedHat(opcode)) {
|
||||
// If this is an edge-activated hat, only proceed if
|
||||
// the value is true and used to be false.
|
||||
const oldEdgeValue = runtime.updateEdgeActivatedValue(
|
||||
currentBlockId,
|
||||
resolvedValue
|
||||
);
|
||||
const edgeWasActivated = !oldEdgeValue && resolvedValue;
|
||||
if (!edgeWasActivated) {
|
||||
sequencer.retireThread(thread);
|
||||
// the value is true and used to be false, or the stack was activated
|
||||
// explicitly via stack click
|
||||
if (!thread.stackClick) {
|
||||
const oldEdgeValue = runtime.updateEdgeActivatedValue(
|
||||
currentBlockId,
|
||||
resolvedValue
|
||||
);
|
||||
const edgeWasActivated = !oldEdgeValue && resolvedValue;
|
||||
if (!edgeWasActivated) {
|
||||
sequencer.retireThread(thread);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 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
|
||||
// at the top of the thread stack.
|
||||
if (typeof resolvedValue !== 'undefined' && thread.atStackTop()) {
|
||||
if (thread.showVisualReport) {
|
||||
if (thread.stackClick) {
|
||||
runtime.visualReport(currentBlockId, resolvedValue);
|
||||
}
|
||||
if (thread.updateMonitor) {
|
||||
|
|
|
@ -399,19 +399,19 @@ class Runtime extends EventEmitter {
|
|||
* @param {!string} id ID of block that starts the stack.
|
||||
* @param {!Target} target Target to run thread on.
|
||||
* @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
|
||||
* @return {!Thread} The newly created thread.
|
||||
*/
|
||||
_pushThread (id, target, opts) {
|
||||
opts = Object.assign({
|
||||
showVisualReport: false,
|
||||
stackClick: false,
|
||||
updateMonitor: false
|
||||
}, opts);
|
||||
|
||||
const thread = new Thread(id);
|
||||
thread.target = target;
|
||||
thread.showVisualReport = opts.showVisualReport;
|
||||
thread.stackClick = opts.stackClick;
|
||||
thread.updateMonitor = opts.updateMonitor;
|
||||
|
||||
thread.pushStack(id);
|
||||
|
@ -442,7 +442,7 @@ class Runtime extends EventEmitter {
|
|||
_restartThread (thread) {
|
||||
const newThread = new Thread(thread.topBlock);
|
||||
newThread.target = thread.target;
|
||||
newThread.showVisualReport = thread.showVisualReport;
|
||||
newThread.stackClick = thread.stackClick;
|
||||
newThread.updateMonitor = thread.updateMonitor;
|
||||
newThread.pushStack(thread.topBlock);
|
||||
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 {?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 {?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.
|
||||
*/
|
||||
toggleScript (topBlockId, opts) {
|
||||
opts = Object.assign({
|
||||
target: this._editingTarget,
|
||||
showVisualReport: false,
|
||||
stackClick: false,
|
||||
updateMonitor: false
|
||||
}, opts);
|
||||
// Remove any existing thread.
|
||||
for (let i = 0; i < this.threads.length; i++) {
|
||||
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]);
|
||||
return;
|
||||
}
|
||||
|
@ -487,6 +496,7 @@ class Runtime extends EventEmitter {
|
|||
this._pushThread(topBlockId, opts.target, opts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run a function `f` for all scripts in a workspace.
|
||||
* `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.
|
||||
for (let j = 0; j < instance.threads.length; j++) {
|
||||
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.
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue