mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-22 22:12:28 -05:00
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:
commit
dfd4735871
3 changed files with 50 additions and 1 deletions
|
@ -442,7 +442,15 @@ const parseScratchObject = function (object, runtime, extensions, topLevel, zip)
|
|||
const md5ext = costumeSource.baseLayerMD5;
|
||||
const idParts = StringUtil.splitFirst(md5ext, '.');
|
||||
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.assetId = md5;
|
||||
if (costumeSource.textLayerMD5) {
|
||||
|
|
BIN
test/fixtures/sb2-from-sb1-missing-backdrop-image.sb2
vendored
Normal file
BIN
test/fixtures/sb2-from-sb1-missing-backdrop-image.sb2
vendored
Normal file
Binary file not shown.
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue