{"size": 3022, "ext": "js", "max_stars_repo_path": "test/integration/complex.js", "max_stars_repo_name": "stocktonkincade/scratch-vm", "max_stars_repo_stars_event_min_datetime": "2021-10-31T20:09:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T16:19:28.000Z", "max_issues_repo_path": "test/integration/complex.js", "max_issues_repo_name": "stocktonkincade/scratch-vm", "max_issues_repo_issues_event_min_datetime": "2017-09-01T18:58:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-09-02T14:47:01.000Z", "max_forks_repo_path": "test/integration/complex.js", "max_forks_repo_name": "stocktonkincade/scratch-vm", "max_forks_repo_forks_event_min_datetime": "2019-01-19T00:37:32.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-19T00:37:32.000Z"}
{"max_stars_count": 3, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 30.22, "max_line_length": 73, "alphanum_fraction": 0.4943745864}
const fs = require('fs');
const path = require('path');
const test = require('tap').test;
const attachTestStorage = require('../fixtures/attach-test-storage');
const extract = require('../fixtures/extract');
const VirtualMachine = require('../../src/index');

const projectUri = path.resolve(__dirname, '../fixtures/complex.sb2');
const project = extract(projectUri);

const spriteUri = path.resolve(__dirname, '../fixtures/sprite.json');
const sprite = fs.readFileSync(spriteUri, 'utf8');

test('complex', t => {
    const vm = new VirtualMachine();
    attachTestStorage(vm);

    // 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);
    });

    // Manipulate each target
    vm.on('targetsUpdate', data => {
        const targets = data.targetList;
        for (const i in targets) {
            if (targets[i].isStage === true) continue;
            if (targets[i].name.match(/test/)) continue;

            vm.setEditingTarget(targets[i].id);
            vm.renameSprite(targets[i].id, 'test');
            vm.postSpriteInfo({
                x: 0,
                y: 10,
                direction: 90,
                draggable: true,
                rotationStyle: 'all around',
                visible: true
            });
            vm.addCostume(
                'f9a1c175dbe2e5dee472858dd30d16bb.svg',
                {
                    costumeName: 'costume1',
                    baseLayerID: 0,
                    baseLayerMD5: 'f9a1c175dbe2e5dee472858dd30d16bb.svg',
                    bitmapResolution: 1,
                    rotationCenterX: 47,
                    rotationCenterY: 55
                }
            );
        }
    });

    // Start VM, load project, and run
    t.doesNotThrow(() => {
        vm.start();
        vm.clear();
        vm.setCompatibilityMode(false);
        vm.setTurboMode(false);
        vm.loadProject(project).then(() => {
            vm.greenFlag();

            // Post IO data
            vm.postIOData('mouse', {
                isDown: true,
                x: 0,
                y: 10,
                canvasWidth: 100,
                canvasHeight: 100
            });

            // Add sprite
            vm.addSprite2(sprite);

            // Add backdrop
            vm.addBackdrop(
                '6b3d87ba2a7f89be703163b6c1d4c964.png',
                {
                    costumeName: 'baseball-field',
                    baseLayerID: 26,
                    baseLayerMD5: '6b3d87ba2a7f89be703163b6c1d4c964.png',
                    bitmapResolution: 2,
                    rotationCenterX: 480,
                    rotationCenterY: 360
                }
            );

            // After two seconds, get playground data and stop
            setTimeout(() => {
                vm.getPlaygroundData();
                vm.stopAll();
            }, 2000);
        });
    });

});
