mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Track say/thinks per target so they can maintain correct timing.
This commit is contained in:
parent
cde801bc17
commit
50708c15e4
1 changed files with 16 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
||||||
const Cast = require('../util/cast');
|
const Cast = require('../util/cast');
|
||||||
const Clone = require('../util/clone');
|
const Clone = require('../util/clone');
|
||||||
const RenderedTarget = require('../sprites/rendered-target');
|
const RenderedTarget = require('../sprites/rendered-target');
|
||||||
|
const uid = require('../util/uid');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {object} BubbleState - the bubble state associated with a particular target.
|
* @typedef {object} BubbleState - the bubble state associated with a particular target.
|
||||||
|
@ -44,7 +45,8 @@ class Scratch3LooksBlocks {
|
||||||
onSpriteRight: true,
|
onSpriteRight: true,
|
||||||
skinId: null,
|
skinId: null,
|
||||||
text: '',
|
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);
|
const bubbleState = this._getBubbleState(target);
|
||||||
bubbleState.type = type;
|
bubbleState.type = type;
|
||||||
bubbleState.text = text;
|
bubbleState.text = text;
|
||||||
|
bubbleState.usageId = uid();
|
||||||
this._renderBubble(target);
|
this._renderBubble(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,12 +280,15 @@ class Scratch3LooksBlocks {
|
||||||
|
|
||||||
sayforsecs (args, util) {
|
sayforsecs (args, util) {
|
||||||
this.say(args, util);
|
this.say(args, util);
|
||||||
const _target = util.target;
|
const target = util.target;
|
||||||
|
const usageId = this._getBubbleState(target).usageId;
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
this._bubbleTimeout = setTimeout(() => {
|
this._bubbleTimeout = setTimeout(() => {
|
||||||
this._bubbleTimeout = null;
|
this._bubbleTimeout = null;
|
||||||
// Clear say bubble and proceed.
|
// Clear say bubble if it hasn't been changed and proceed.
|
||||||
this._updateBubble(_target, 'say', '');
|
if (this._getBubbleState(target).usageId === usageId) {
|
||||||
|
this._updateBubble(target, 'say', '');
|
||||||
|
}
|
||||||
resolve();
|
resolve();
|
||||||
}, 1000 * args.SECS);
|
}, 1000 * args.SECS);
|
||||||
});
|
});
|
||||||
|
@ -294,12 +300,15 @@ class Scratch3LooksBlocks {
|
||||||
|
|
||||||
thinkforsecs (args, util) {
|
thinkforsecs (args, util) {
|
||||||
this.think(args, util);
|
this.think(args, util);
|
||||||
const _target = util.target;
|
const target = util.target;
|
||||||
|
const usageId = this._getBubbleState(target).usageId;
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
this._bubbleTimeout = setTimeout(() => {
|
this._bubbleTimeout = setTimeout(() => {
|
||||||
this._bubbleTimeout = null;
|
this._bubbleTimeout = null;
|
||||||
// Clear say bubble and proceed.
|
// Clear think bubble if it hasn't been changed and proceed.
|
||||||
this._updateBubble(_target, 'think', '');
|
if (this._getBubbleState(target).usageId === usageId) {
|
||||||
|
this._updateBubble(target, 'think', '');
|
||||||
|
}
|
||||||
resolve();
|
resolve();
|
||||||
}, 1000 * args.SECS);
|
}, 1000 * args.SECS);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue