mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Use calculated rotation center from renderer when rotation center is not provided with the costume being loaded.
This commit is contained in:
parent
d6f28f2266
commit
54b52ba96c
2 changed files with 21 additions and 7 deletions
|
@ -15,7 +15,8 @@ const log = require('../util/log');
|
||||||
*/
|
*/
|
||||||
const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
||||||
costume.assetId = costumeAsset.assetId;
|
costume.assetId = costumeAsset.assetId;
|
||||||
if (!runtime.renderer) {
|
const renderer = runtime.renderer;
|
||||||
|
if (!renderer) {
|
||||||
log.error('No rendering module present; cannot load costume: ', costume.name);
|
log.error('No rendering module present; cannot load costume: ', costume.name);
|
||||||
return costume;
|
return costume;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +31,15 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
||||||
if (costumeAsset.assetType === AssetType.ImageVector) {
|
if (costumeAsset.assetType === AssetType.ImageVector) {
|
||||||
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
|
// createSVGSkin does the right thing if rotationCenter isn't provided, so it's okay if it's
|
||||||
// undefined here
|
// undefined here
|
||||||
costume.skinId = runtime.renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
|
costume.skinId = renderer.createSVGSkin(costumeAsset.decodeText(), rotationCenter);
|
||||||
costume.size = runtime.renderer.getSkinSize(costume.skinId);
|
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;
|
return costume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +64,14 @@ const loadCostumeFromAsset = function (costume, costumeAsset, runtime) {
|
||||||
imageElement.src = costumeAsset.encodeDataURI();
|
imageElement.src = costumeAsset.encodeDataURI();
|
||||||
}).then(imageElement => {
|
}).then(imageElement => {
|
||||||
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
|
// createBitmapSkin does the right thing if costume.bitmapResolution or rotationCenter are undefined...
|
||||||
costume.skinId = runtime.renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
|
costume.skinId = renderer.createBitmapSkin(imageElement, costume.bitmapResolution, rotationCenter);
|
||||||
costume.size = runtime.renderer.getSkinSize(costume.skinId);
|
costume.size = renderer.getSkinSize(costume.skinId);
|
||||||
|
|
||||||
|
if (!rotationCenter) {
|
||||||
|
rotationCenter = renderer.getSkinRotationCenter(costume.skinId);
|
||||||
|
costume.rotationCenterX = rotationCenter[0];
|
||||||
|
costume.rotationCenterY = rotationCenter[1];
|
||||||
|
}
|
||||||
return costume;
|
return costume;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -405,8 +405,8 @@ class VirtualMachine extends EventEmitter {
|
||||||
* @returns {?Promise} - a promise that resolves when the costume has been added
|
* @returns {?Promise} - a promise that resolves when the costume has been added
|
||||||
*/
|
*/
|
||||||
addCostume (md5ext, costumeObject) {
|
addCostume (md5ext, costumeObject) {
|
||||||
return loadCostume(md5ext, costumeObject, this.runtime).then(() => {
|
return loadCostume(md5ext, costumeObject, this.runtime).then(loadedCostume => {
|
||||||
this.editingTarget.addCostume(costumeObject);
|
this.editingTarget.addCostume(loadedCostume);
|
||||||
this.editingTarget.setCostume(
|
this.editingTarget.setCostume(
|
||||||
this.editingTarget.getCostumes().length - 1
|
this.editingTarget.getCostumes().length - 1
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue