mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-12 07:45:41 -05:00
Automatically create asset for generated 'flattened' image
This commit is contained in:
parent
9180f9cc24
commit
8f0130e439
1 changed files with 31 additions and 4 deletions
|
@ -153,7 +153,7 @@ const loadOldTextCostume = function (baseMD5ext, textMD5ext, costume, runtime) {
|
|||
loadedOne = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const removeEventListeners = function () {
|
||||
baseImageElement.removeEventListener('error', onError);
|
||||
textImageElement.removeEventListener('error', onError);
|
||||
|
@ -183,9 +183,36 @@ const loadOldTextCostume = function (baseMD5ext, textMD5ext, costume, runtime) {
|
|||
ctx.drawImage(baseImageElement, 0, 0);
|
||||
ctx.drawImage(textImageElement, 0, 0);
|
||||
|
||||
costume.skinId = runtime.renderer.createBitmapSkin(canvas, costume.bitmapResolution, rotationCenter);
|
||||
|
||||
return costume;
|
||||
return new Promise((resolve, reject) => {
|
||||
canvas.toBlob(blob => {
|
||||
const reader = new FileReader();
|
||||
const onError = function() {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
removeEventListeners();
|
||||
reject();
|
||||
};
|
||||
const onLoad = function () {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
removeEventListeners();
|
||||
costume.assetId = runtime.storage.builtinHelper.cache(
|
||||
assetType,
|
||||
runtime.storage.DataFormat.PNG,
|
||||
new Buffer(reader.result)
|
||||
);
|
||||
costume.skinId = runtime.renderer.createBitmapSkin(
|
||||
canvas, costume.bitmapResolution, rotationCenter
|
||||
);
|
||||
resolve(costume);
|
||||
};
|
||||
const removeEventListeners = function () {
|
||||
reader.removeEventListener('error', onError);
|
||||
reader.removeEventListener('load', onLoad);
|
||||
};
|
||||
reader.addEventListener('error', onError);
|
||||
reader.addEventListener('load', onLoad);
|
||||
reader.readAsArrayBuffer(blob);
|
||||
}, 'image/png');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue