2017-04-20 19:17:05 -04:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2019-01-07 12:59:33 -05:00
|
|
|
const test = require('tap').test;
|
2017-06-09 17:54:10 -04:00
|
|
|
const makeTestStorage = require('../fixtures/make-test-storage');
|
2018-04-05 13:46:07 -04:00
|
|
|
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
|
2017-04-20 19:17:05 -04:00
|
|
|
const VirtualMachine = require('../../src/index');
|
2017-01-05 16:58:31 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
const projectUri = path.resolve(__dirname, '../fixtures/complex.sb2');
|
2018-04-05 13:46:07 -04:00
|
|
|
const project = readFileToBuffer(projectUri);
|
2017-01-05 16:58:31 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
const spriteUri = path.resolve(__dirname, '../fixtures/sprite.json');
|
|
|
|
const sprite = fs.readFileSync(spriteUri, 'utf8');
|
2017-01-05 16:58:31 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('complex', t => {
|
|
|
|
const vm = new VirtualMachine();
|
2017-06-09 17:54:10 -04:00
|
|
|
vm.attachStorage(makeTestStorage());
|
2017-01-05 16:58:31 -05:00
|
|
|
|
|
|
|
// Evaluate playground data and exit
|
2017-04-20 19:17:05 -04:00
|
|
|
vm.on('playgroundData', e => {
|
|
|
|
const threads = JSON.parse(e.threads);
|
2017-01-05 16:58:31 -05:00
|
|
|
t.ok(threads.length === 0);
|
|
|
|
t.end();
|
|
|
|
process.nextTick(process.exit);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Manipulate each target
|
2017-04-20 19:17:05 -04:00
|
|
|
vm.on('targetsUpdate', data => {
|
|
|
|
const targets = data.targetList;
|
|
|
|
for (const i in targets) {
|
2017-01-05 16:58:31 -05:00
|
|
|
if (targets[i].isStage === true) continue;
|
2017-03-20 12:52:57 -04:00
|
|
|
if (targets[i].name.match(/test/)) continue;
|
2017-01-05 16:58:31 -05:00
|
|
|
|
|
|
|
vm.setEditingTarget(targets[i].id);
|
|
|
|
vm.renameSprite(targets[i].id, 'test');
|
|
|
|
vm.postSpriteInfo({
|
|
|
|
x: 0,
|
|
|
|
y: 10,
|
|
|
|
direction: 90,
|
2017-03-01 18:49:17 -05:00
|
|
|
draggable: true,
|
2017-01-05 16:58:31 -05:00
|
|
|
rotationStyle: 'all around',
|
|
|
|
visible: true
|
|
|
|
});
|
2017-04-03 15:58:13 -04:00
|
|
|
vm.addCostume(
|
|
|
|
'f9a1c175dbe2e5dee472858dd30d16bb.svg',
|
|
|
|
{
|
2017-07-25 10:31:15 -04:00
|
|
|
name: 'costume1',
|
2017-04-03 15:58:13 -04:00
|
|
|
baseLayerID: 0,
|
|
|
|
baseLayerMD5: 'f9a1c175dbe2e5dee472858dd30d16bb.svg',
|
|
|
|
bitmapResolution: 1,
|
|
|
|
rotationCenterX: 47,
|
|
|
|
rotationCenterY: 55
|
|
|
|
}
|
|
|
|
);
|
2017-01-05 16:58:31 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start VM, load project, and run
|
2017-04-20 19:17:05 -04:00
|
|
|
t.doesNotThrow(() => {
|
2017-01-05 16:58:31 -05:00
|
|
|
vm.start();
|
|
|
|
vm.clear();
|
|
|
|
vm.setCompatibilityMode(false);
|
|
|
|
vm.setTurboMode(false);
|
2017-04-20 19:17:05 -04:00
|
|
|
vm.loadProject(project).then(() => {
|
2017-04-18 11:55:38 -04:00
|
|
|
vm.greenFlag();
|
2017-01-05 16:58:31 -05:00
|
|
|
|
2017-04-18 11:55:38 -04:00
|
|
|
// Post IO data
|
|
|
|
vm.postIOData('mouse', {
|
|
|
|
isDown: true,
|
|
|
|
x: 0,
|
|
|
|
y: 10,
|
|
|
|
canvasWidth: 100,
|
|
|
|
canvasHeight: 100
|
|
|
|
});
|
2017-01-05 16:58:31 -05:00
|
|
|
|
2017-04-18 11:55:38 -04:00
|
|
|
// Add sprite
|
2018-05-03 16:19:29 -04:00
|
|
|
vm.addSprite(sprite);
|
2017-01-05 16:58:31 -05:00
|
|
|
|
2017-04-18 11:55:38 -04:00
|
|
|
// Add backdrop
|
|
|
|
vm.addBackdrop(
|
|
|
|
'6b3d87ba2a7f89be703163b6c1d4c964.png',
|
|
|
|
{
|
2017-07-25 10:31:15 -04:00
|
|
|
name: 'baseball-field',
|
2017-04-18 11:55:38 -04:00
|
|
|
baseLayerID: 26,
|
|
|
|
baseLayerMD5: '6b3d87ba2a7f89be703163b6c1d4c964.png',
|
|
|
|
bitmapResolution: 2,
|
|
|
|
rotationCenterX: 480,
|
|
|
|
rotationCenterY: 360
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// After two seconds, get playground data and stop
|
2017-04-20 19:17:05 -04:00
|
|
|
setTimeout(() => {
|
2017-04-18 11:55:38 -04:00
|
|
|
vm.getPlaygroundData();
|
|
|
|
vm.stopAll();
|
|
|
|
}, 2000);
|
|
|
|
});
|
2017-01-05 16:58:31 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|