mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-14 19:49:57 -05:00
Code review
This commit is contained in:
parent
3a3d807cba
commit
009253a8d1
2 changed files with 18 additions and 24 deletions
|
@ -34,7 +34,6 @@
|
||||||
"babel-loader": "^7.0.0",
|
"babel-loader": "^7.0.0",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"buffer-loader": "0.0.1",
|
"buffer-loader": "0.0.1",
|
||||||
"canvas-toBlob": "1.0.0",
|
|
||||||
"copy-webpack-plugin": "4.2.1",
|
"copy-webpack-plugin": "4.2.1",
|
||||||
"decode-html": "2.0.0",
|
"decode-html": "2.0.0",
|
||||||
"escape-html": "1.0.3",
|
"escape-html": "1.0.3",
|
||||||
|
|
|
@ -2,7 +2,6 @@ const TextEncoder = require('text-encoding').TextEncoder;
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const JSZip = require('jszip');
|
const JSZip = require('jszip');
|
||||||
|
|
||||||
const Buffer = require('buffer').Buffer;
|
|
||||||
const centralDispatch = require('./dispatch/central-dispatch');
|
const centralDispatch = require('./dispatch/central-dispatch');
|
||||||
const ExtensionManager = require('./extension-support/extension-manager');
|
const ExtensionManager = require('./extension-support/extension-manager');
|
||||||
const log = require('./util/log');
|
const log = require('./util/log');
|
||||||
|
@ -18,7 +17,6 @@ const Variable = require('./engine/variable');
|
||||||
const {loadCostume} = require('./import/load-costume.js');
|
const {loadCostume} = require('./import/load-costume.js');
|
||||||
const {loadSound} = require('./import/load-sound.js');
|
const {loadSound} = require('./import/load-sound.js');
|
||||||
const {serializeSounds, serializeCostumes} = require('./serialization/serialize-assets');
|
const {serializeSounds, serializeCostumes} = require('./serialization/serialize-assets');
|
||||||
require('canvas-toBlob');
|
|
||||||
|
|
||||||
const RESERVED_NAMES = ['_mouse_', '_stage_', '_edge_', '_myself_', '_random_'];
|
const RESERVED_NAMES = ['_mouse_', '_stage_', '_edge_', '_myself_', '_random_'];
|
||||||
|
|
||||||
|
@ -554,8 +552,9 @@ class VirtualMachine extends EventEmitter {
|
||||||
const format = this.runtime.storage.get(id).dataFormat;
|
const format = this.runtime.storage.get(id).dataFormat;
|
||||||
if (format === this.runtime.storage.DataFormat.SVG) {
|
if (format === this.runtime.storage.DataFormat.SVG) {
|
||||||
return this.runtime.storage.get(id).decodeText();
|
return this.runtime.storage.get(id).decodeText();
|
||||||
} else if (format === this.runtime.storage.DataFormat.PNG) {
|
} else if (format === this.runtime.storage.DataFormat.PNG ||
|
||||||
const data = this.runtime.storage.get(id).encodeDataURI('image/png');
|
format === this.runtime.storage.DataFormat.JPG) {
|
||||||
|
const data = this.runtime.storage.get(id).encodeDataURI();
|
||||||
const image = new Image();
|
const image = new Image();
|
||||||
image.src = data;
|
image.src = data;
|
||||||
return image;
|
return image;
|
||||||
|
@ -570,32 +569,28 @@ class VirtualMachine extends EventEmitter {
|
||||||
* @param {HTMLCanvasElement} bitmap - new bitmap for the renderer.
|
* @param {HTMLCanvasElement} bitmap - new bitmap for the renderer.
|
||||||
* @param {number} rotationCenterX x of point about which the costume rotates, relative to its upper left corner
|
* @param {number} rotationCenterX x of point about which the costume rotates, relative to its upper left corner
|
||||||
* @param {number} rotationCenterY y of point about which the costume rotates, relative to its upper left corner
|
* @param {number} rotationCenterY y of point about which the costume rotates, relative to its upper left corner
|
||||||
|
* @param {number} bitmapResolution 1 for bitmaps that have 1 pixel per unit of stage, 2 for double-resolution bitmaps
|
||||||
*/
|
*/
|
||||||
updateBitmap (costumeIndex, bitmap, rotationCenterX, rotationCenterY) {
|
updateBitmap (costumeIndex, bitmap, rotationCenterX, rotationCenterY, bitmapResolution) {
|
||||||
const costume = this.editingTarget.getCostumes()[costumeIndex];
|
const costume = this.editingTarget.getCostumes()[costumeIndex];
|
||||||
if (costume && this.runtime && this.runtime.renderer) {
|
if (costume && this.runtime && this.runtime.renderer) {
|
||||||
costume.rotationCenterX = rotationCenterX;
|
costume.rotationCenterX = rotationCenterX;
|
||||||
costume.rotationCenterY = rotationCenterY;
|
costume.rotationCenterY = rotationCenterY;
|
||||||
this.runtime.renderer.updateBitmapSkin(costume.skinId, bitmap, [rotationCenterX, rotationCenterY]);
|
this.runtime.renderer.updateBitmapSkin(
|
||||||
|
costume.skinId, bitmap, bitmapResolution, [rotationCenterX, rotationCenterY]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap.toBlob(blob => {
|
const storage = this.runtime.storage;
|
||||||
const reader = new FileReader();
|
costume.assetId = storage.builtinHelper.cache(
|
||||||
reader.addEventListener('loadend', () => {
|
storage.AssetType.ImageBitmap,
|
||||||
const storage = this.runtime.storage;
|
storage.DataFormat.PNG,
|
||||||
costume.assetId = storage.builtinHelper.cache(
|
bitmap.getContext('2d').getImageData(0, 0, bitmap.width, bitmap.height).data
|
||||||
storage.AssetType.ImageBitmap,
|
);
|
||||||
storage.DataFormat.PNG,
|
costume.dataFormat = storage.DataFormat.PNG;
|
||||||
Buffer.from(reader.result)
|
costume.bitmapResolution = bitmapResolution;
|
||||||
);
|
costume.size = [bitmap.width, bitmap.height];
|
||||||
// @todo is there a better way to make sure all info is up to date on the costume?
|
costume.md5 = `${costume.assetId}.${costume.dataFormat}`;
|
||||||
costume.dataFormat = storage.DataFormat.PNG;
|
this.emitTargetsUpdate();
|
||||||
costume.bitmapResolution = 2;
|
|
||||||
this.emitTargetsUpdate();
|
|
||||||
});
|
|
||||||
reader.readAsArrayBuffer(blob);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue