From 50708c15e4f7ea44dde1e8b3be7c79484b14edab Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 26 Apr 2018 11:29:24 -0400 Subject: [PATCH 1/2] Track say/thinks per target so they can maintain correct timing. --- src/blocks/scratch3_looks.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index 7954d0660..b561682be 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -1,6 +1,7 @@ const Cast = require('../util/cast'); const Clone = require('../util/clone'); const RenderedTarget = require('../sprites/rendered-target'); +const uid = require('../util/uid'); /** * @typedef {object} BubbleState - the bubble state associated with a particular target. @@ -44,7 +45,8 @@ class Scratch3LooksBlocks { onSpriteRight: true, skinId: null, text: '', - type: 'say' + type: 'say', + usageId: null // ID for hiding a timed say/think block. }; } @@ -224,6 +226,7 @@ class Scratch3LooksBlocks { const bubbleState = this._getBubbleState(target); bubbleState.type = type; bubbleState.text = text; + bubbleState.usageId = uid(); this._renderBubble(target); } @@ -277,12 +280,15 @@ class Scratch3LooksBlocks { sayforsecs (args, util) { this.say(args, util); - const _target = util.target; + const target = util.target; + const usageId = this._getBubbleState(target).usageId; return new Promise(resolve => { this._bubbleTimeout = setTimeout(() => { this._bubbleTimeout = null; - // Clear say bubble and proceed. - this._updateBubble(_target, 'say', ''); + // Clear say bubble if it hasn't been changed and proceed. + if (this._getBubbleState(target).usageId === usageId) { + this._updateBubble(target, 'say', ''); + } resolve(); }, 1000 * args.SECS); }); @@ -294,12 +300,15 @@ class Scratch3LooksBlocks { thinkforsecs (args, util) { this.think(args, util); - const _target = util.target; + const target = util.target; + const usageId = this._getBubbleState(target).usageId; return new Promise(resolve => { this._bubbleTimeout = setTimeout(() => { this._bubbleTimeout = null; - // Clear say bubble and proceed. - this._updateBubble(_target, 'think', ''); + // Clear think bubble if it hasn't been changed and proceed. + if (this._getBubbleState(target).usageId === usageId) { + this._updateBubble(target, 'think', ''); + } resolve(); }, 1000 * args.SECS); }); From c2bb1e3123966ae3daa4bf43f4a7b108fb99ec57 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 27 Apr 2018 09:21:38 -0400 Subject: [PATCH 2/2] Add comment to jsdoc typedef where it belongs. --- src/blocks/scratch3_looks.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index b561682be..c676aaa5c 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -11,6 +11,8 @@ const uid = require('../util/uid'); * See _renderBubble for explanation of this optimization. * @property {string} text - the text of the bubble. * @property {string} type - the type of the bubble, "say" or "think" + * @property {?string} usageId - ID indicating the most recent usage of the say/think bubble. + * Used for comparison when determining whether to clear a say/think bubble. */ class Scratch3LooksBlocks { @@ -46,7 +48,7 @@ class Scratch3LooksBlocks { skinId: null, text: '', type: 'say', - usageId: null // ID for hiding a timed say/think block. + usageId: null }; }