mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Merge branch 'develop' of https://github.com/LLK/scratch-vm into feature/key-droppability
This commit is contained in:
commit
743135beb4
5 changed files with 59 additions and 22 deletions
|
@ -144,15 +144,21 @@ class Scratch3ControlBlocks {
|
|||
}
|
||||
|
||||
createClone (args, util) {
|
||||
// Cast argument to string
|
||||
args.CLONE_OPTION = Cast.toString(args.CLONE_OPTION);
|
||||
|
||||
// Set clone target
|
||||
let cloneTarget;
|
||||
if (args.CLONE_OPTION === '_myself_') {
|
||||
cloneTarget = util.target;
|
||||
} else {
|
||||
cloneTarget = this.runtime.getSpriteTargetByName(args.CLONE_OPTION);
|
||||
}
|
||||
if (!cloneTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If clone target is not found, return
|
||||
if (!cloneTarget) return;
|
||||
|
||||
// Create clone
|
||||
const newClone = cloneTarget.makeClone();
|
||||
if (newClone) {
|
||||
this.runtime.targets.push(newClone);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -15,18 +15,31 @@ const log = require('../util/log');
|
|||
*/
|
||||
const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
||||
costume.assetId = costumeAsset.assetId;
|
||||
if (!runtime.renderer) {
|
||||
const renderer = runtime.renderer;
|
||||
if (!renderer) {
|
||||
log.error('No rendering module present; cannot load costume: ', costume.name);
|
||||
return costume;
|
||||
}
|
||||
const AssetType = runtime.storage.AssetType;
|
||||
const rotationCenter = [
|
||||
costume.rotationCenterX / costume.bitmapResolution,
|
||||
costume.rotationCenterY / costume.bitmapResolution
|
||||
];
|
||||
let rotationCenter;
|
||||
if (costume.rotationCenterX && costume.rotationCenterY && costume.bitmapResolution) {
|
||||
rotationCenter = [
|
||||
costume.rotationCenterX / costume.bitmapResolution,
|
||||
costume.rotationCenterY / costume.bitmapResolution
|
||||
];
|
||||
}
|
||||
if (costumeAsset.assetType === AssetType.ImageVector) {
|
||||
costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
|
||||
costume.size = runtime.renderer.getSkinSize(costume.skinId);
|
||||
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
|
||||
// undefined here
|
||||
costume.skinId = renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
|
||||
costume.size = renderer.getSkinSize(costume.skinId);
|
||||
// Now we should have a rotationCenter even if we didn't before
|
||||
if (!rotationCenter) {
|
||||
rotationCenter = renderer.getSkinRotationCenter(costume.skinId);
|
||||
costume.rotationCenterX = rotationCenter[0];
|
||||
costume.rotationCenterY = rotationCenter[1];
|
||||
}
|
||||
|
||||
return costume;
|
||||
}
|
||||
|
||||
|
@ -50,8 +63,15 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
|||
imageElement.addEventListener('load', onLoad);
|
||||
imageElement.src = costumeAsset.encodeDataURI();
|
||||
}).then(imageElement => {
|
||||
costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
|
||||
costume.size = runtime.renderer.getSkinSize(costume.skinId);
|
||||
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
|
||||
costume.skinId = renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
|
||||
costume.size = renderer.getSkinSize(costume.skinId);
|
||||
|
||||
if (!rotationCenter) {
|
||||
rotationCenter = renderer.getSkinRotationCenter(costume.skinId);
|
||||
costume.rotationCenterX = rotationCenter[0] * 2;
|
||||
costume.rotationCenterY = rotationCenter[1] * 2;
|
||||
}
|
||||
return costume;
|
||||
});
|
||||
};
|
||||
|
|
|
@ -452,7 +452,7 @@ class RenderedTarget extends Target {
|
|||
typeof costume.rotationCenterX !== 'undefined' &&
|
||||
typeof costume.rotationCenterY !== 'undefined'
|
||||
) {
|
||||
const scale = costume.bitmapResolution || 1;
|
||||
const scale = costume.bitmapResolution || 2;
|
||||
drawableProperties.rotationCenter = [
|
||||
costume.rotationCenterX / scale,
|
||||
costume.rotationCenterY / scale
|
||||
|
@ -641,7 +641,7 @@ class RenderedTarget extends Target {
|
|||
if (this.renderer) {
|
||||
const renderedDirectionScale = this._getRenderedDirectionAndScale();
|
||||
const costume = this.getCostumes()[this.currentCostume];
|
||||
const bitmapResolution = costume.bitmapResolution || 1;
|
||||
const bitmapResolution = costume.bitmapResolution || 2;
|
||||
const props = {
|
||||
position: [this.x, this.y],
|
||||
direction: renderedDirectionScale.direction,
|
||||
|
|
|
@ -545,7 +545,7 @@ class VirtualMachine extends EventEmitter {
|
|||
* @param {int} costumeIndex - the index of the costume to be got.
|
||||
* @return {string} the costume's SVG string, or null if it's not an SVG costume.
|
||||
*/
|
||||
getCostumeSvg (costumeIndex) {
|
||||
getCostume (costumeIndex) {
|
||||
const id = this.editingTarget.getCostumes()[costumeIndex].assetId;
|
||||
if (id && this.runtime && this.runtime.storage &&
|
||||
this.runtime.storage.get(id).dataFormat === 'svg') {
|
||||
|
|
Loading…
Reference in a new issue