mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Merge pull request #1088 from paulkaplan/fix-say-timing
Track say/thinks per target so they can maintain correct timing.
This commit is contained in:
commit
ad4f5652e4
1 changed files with 18 additions and 7 deletions
|
@ -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.
|
||||
|
@ -10,6 +11,8 @@ const RenderedTarget = require('../sprites/rendered-target');
|
|||
* 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 {
|
||||
|
@ -44,7 +47,8 @@ class Scratch3LooksBlocks {
|
|||
onSpriteRight: true,
|
||||
skinId: null,
|
||||
text: '',
|
||||
type: 'say'
|
||||
type: 'say',
|
||||
usageId: null
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -224,6 +228,7 @@ class Scratch3LooksBlocks {
|
|||
const bubbleState = this._getBubbleState(target);
|
||||
bubbleState.type = type;
|
||||
bubbleState.text = text;
|
||||
bubbleState.usageId = uid();
|
||||
this._renderBubble(target);
|
||||
}
|
||||
|
||||
|
@ -277,12 +282,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 +302,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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue