Merge pull request #1719 from rschamp/hotfix/sprite-upload-from-image

Handle images uploaded as sprites
This commit is contained in:
Karishma Chadha 2018-11-01 18:18:52 -04:00 committed by GitHub
commit d64322a110
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -71,7 +71,19 @@ const deserializeCostume = function (costume, runtime, zip, assetFileName) {
return Promise.resolve(null); return Promise.resolve(null);
} }
if (!zip) { // Zip will not be provided if loading project json from server if (costume.asset) {
// When uploading a sprite from an image file, the asset data will be provided
// @todo Cache the asset data somewhere and pull it out here
return Promise.resolve(storage.createAsset(
costume.asset.assetType,
costume.asset.dataFormat,
new Uint8Array(Object.keys(costume.asset.data).map(key => costume.asset.data[key])),
costume.asset.assetId
));
}
if (!zip) {
// Zip will not be provided if loading project json from server
return Promise.resolve(null); return Promise.resolve(null);
} }

View file

@ -823,6 +823,9 @@ const parseScratchObject = function (object, runtime, extensions, zip) {
const costumePromises = (object.costumes || []).map(costumeSource => { const costumePromises = (object.costumes || []).map(costumeSource => {
// @todo: Make sure all the relevant metadata is being pulled out. // @todo: Make sure all the relevant metadata is being pulled out.
const costume = { const costume = {
// costumeSource only has an asset if an image is being uploaded as
// a sprite
asset: costumeSource.asset,
assetId: costumeSource.assetId, assetId: costumeSource.assetId,
skinId: null, skinId: null,
name: costumeSource.name, name: costumeSource.name,