Merge pull request #1833 from kchadha/fix-sb2-from-sb1-import

Fix issue importing some sb2s that were originally sb1s, with baseLayerMd5 property formatted differently.
This commit is contained in:
Karishma Chadha 2018-12-13 15:59:44 -05:00 committed by GitHub
commit dfd4735871
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 1 deletions

View file

@ -442,7 +442,15 @@ const parseScratchObject = function (object, runtime, extensions, topLevel, zip)
const md5ext = costumeSource.baseLayerMD5; const md5ext = costumeSource.baseLayerMD5;
const idParts = StringUtil.splitFirst(md5ext, '.'); const idParts = StringUtil.splitFirst(md5ext, '.');
const md5 = idParts[0]; const md5 = idParts[0];
const ext = idParts[1].toLowerCase(); let ext;
if (idParts.length === 2 && idParts[1]) {
ext = idParts[1];
} else {
// Default to 'png' if baseLayerMD5 is not formatted correctly
ext = 'png';
// Fix costume md5 for later
costume.md5 = `${costume.md5}.${ext}`;
}
costume.dataFormat = ext; costume.dataFormat = ext;
costume.assetId = md5; costume.assetId = md5;
if (costumeSource.textLayerMD5) { if (costumeSource.textLayerMD5) {

Binary file not shown.

View file

@ -0,0 +1,41 @@
const path = require('path');
const test = require('tap').test;
const makeTestStorage = require('../fixtures/make-test-storage');
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
const VirtualMachine = require('../../src/virtual-machine');
const projectUri = path.resolve(__dirname, '../fixtures/sb2-from-sb1-missing-backdrop-image.sb2');
const project = readFileToBuffer(projectUri);
const vm = new VirtualMachine();
test('sb2 project (originally from Scratch 1.4) with missing backdrop image should load', t => {
vm.attachStorage(makeTestStorage());
// Evaluate playground data and exit
vm.on('playgroundData', e => {
const threads = JSON.parse(e.threads);
t.ok(threads.length === 0);
t.end();
process.nextTick(process.exit);
});
vm.start();
vm.clear();
vm.setCompatibilityMode(false);
vm.setTurboMode(false);
t.doesNotThrow(() => {
vm.loadProject(project).then(() => {
t.equal(vm.runtime.targets.length, 2); // stage and default sprite
vm.greenFlag();
setTimeout(() => {
vm.getPlaygroundData();
vm.stopAll();
}, 1000);
});
});
});