mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-25 09:01:07 -05:00
Merge pull request #1038 from paulkaplan/skin-size
Attach the costume size to the costume when loaded and modified
This commit is contained in:
commit
64c2d1f7b1
5 changed files with 6 additions and 3 deletions
|
@ -118,7 +118,7 @@ class Scratch3LooksBlocks {
|
||||||
*/
|
*/
|
||||||
_positionBubble (target) {
|
_positionBubble (target) {
|
||||||
const bubbleState = this._getBubbleState(target);
|
const bubbleState = this._getBubbleState(target);
|
||||||
const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getSkinSize(bubbleState.drawableId);
|
const [bubbleWidth, bubbleHeight] = this.runtime.renderer.getCurrentSkinSize(bubbleState.drawableId);
|
||||||
const targetBounds = target.getBoundsForBubble();
|
const targetBounds = target.getBoundsForBubble();
|
||||||
const stageBounds = this.runtime.getTargetForStage().getBounds();
|
const stageBounds = this.runtime.getTargetForStage().getBounds();
|
||||||
if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right &&
|
if (bubbleState.onSpriteRight && bubbleWidth + targetBounds.right > stageBounds.right &&
|
||||||
|
|
|
@ -26,6 +26,7 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
||||||
];
|
];
|
||||||
if (costumeAsset.assetType === AssetType.ImageVector) {
|
if (costumeAsset.assetType === AssetType.ImageVector) {
|
||||||
costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
|
costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
|
||||||
|
costume.size = runtime.renderer.getSkinSize(costume.skinId);
|
||||||
return costume;
|
return costume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
||||||
imageElement.src = costumeAsset.encodeDataURI();
|
imageElement.src = costumeAsset.encodeDataURI();
|
||||||
}).then(imageElement => {
|
}).then(imageElement => {
|
||||||
costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
|
costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
|
||||||
|
costume.size = runtime.renderer.getSkinSize(costume.skinId);
|
||||||
return costume;
|
return costume;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -355,7 +355,7 @@ class RenderedTarget extends Target {
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
// Clamp to scales relative to costume and stage size.
|
// Clamp to scales relative to costume and stage size.
|
||||||
// See original ScratchSprite.as:setSize.
|
// See original ScratchSprite.as:setSize.
|
||||||
const costumeSize = this.renderer.getSkinSize(this.drawableID);
|
const costumeSize = this.renderer.getCurrentSkinSize(this.drawableID);
|
||||||
const origW = costumeSize[0];
|
const origW = costumeSize[0];
|
||||||
const origH = costumeSize[1];
|
const origH = costumeSize[1];
|
||||||
const minScale = Math.min(1, Math.max(5 / origW, 5 / origH));
|
const minScale = Math.min(1, Math.max(5 / origW, 5 / origH));
|
||||||
|
|
|
@ -561,6 +561,7 @@ class VirtualMachine extends EventEmitter {
|
||||||
costume.rotationCenterX = rotationCenterX;
|
costume.rotationCenterX = rotationCenterX;
|
||||||
costume.rotationCenterY = rotationCenterY;
|
costume.rotationCenterY = rotationCenterY;
|
||||||
this.runtime.renderer.updateSVGSkin(costume.skinId, svg, [rotationCenterX, rotationCenterY]);
|
this.runtime.renderer.updateSVGSkin(costume.skinId, svg, [rotationCenterX, rotationCenterY]);
|
||||||
|
costume.size = this.runtime.renderer.getSkinSize(costume.skinId);
|
||||||
}
|
}
|
||||||
const storage = this.runtime.storage;
|
const storage = this.runtime.storage;
|
||||||
costume.assetId = storage.builtinHelper.cache(
|
costume.assetId = storage.builtinHelper.cache(
|
||||||
|
|
2
test/fixtures/fake-renderer.js
vendored
2
test/fixtures/fake-renderer.js
vendored
|
@ -22,7 +22,7 @@ FakeRenderer.prototype.updateDrawableProperties = function (d, p) { // eslint-di
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeRenderer.prototype.getSkinSize = function (d) { // eslint-disable-line no-unused-vars
|
FakeRenderer.prototype.getCurrentSkinSize = function (d) { // eslint-disable-line no-unused-vars
|
||||||
return [0, 0];
|
return [0, 0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue