mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-08 03:54:04 -04:00
just hat changes
This commit is contained in:
parent
936ff04b0f
commit
fed449876f
7 changed files with 291 additions and 19 deletions
test/integration
59
test/integration/stack-click.js
Normal file
59
test/integration/stack-click.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
const path = require('path');
|
||||
const test = require('tap').test;
|
||||
const makeTestStorage = require('../fixtures/make-test-storage');
|
||||
const extract = require('../fixtures/extract');
|
||||
const VirtualMachine = require('../../src/index');
|
||||
|
||||
const projectUri = path.resolve(__dirname, '../fixtures/stack-click.sb2');
|
||||
const project = extract(projectUri);
|
||||
|
||||
/**
|
||||
* stack-click.sb2 contains a sprite at (0, 0) with a single stack
|
||||
* when timer > 100000000
|
||||
* move 100 steps
|
||||
* The intention is to make sure that the stack can be activated by a stack click
|
||||
* even when the hat predicate is false.
|
||||
*/
|
||||
test('stack click activates the stack', t => {
|
||||
const vm = new VirtualMachine();
|
||||
vm.attachStorage(makeTestStorage());
|
||||
|
||||
// Evaluate playground data and exit
|
||||
vm.on('playgroundData', () => {
|
||||
// The sprite should have moved 100 to the right
|
||||
t.equal(vm.editingTarget.x, 100);
|
||||
t.end();
|
||||
process.nextTick(process.exit);
|
||||
});
|
||||
|
||||
// Start VM, load project, and run
|
||||
t.doesNotThrow(() => {
|
||||
vm.start();
|
||||
vm.clear();
|
||||
vm.setCompatibilityMode(false);
|
||||
vm.setTurboMode(false);
|
||||
vm.loadProject(project).then(() => {
|
||||
const blockContainer = vm.runtime.targets[1].blocks;
|
||||
const allBlocks = blockContainer._blocks;
|
||||
|
||||
// Confirm the editing target is initially at 0
|
||||
t.equal(vm.editingTarget.x, 0);
|
||||
|
||||
// Find hat for greater than and click it
|
||||
for (const blockId in allBlocks) {
|
||||
if (allBlocks[blockId].opcode === 'event_whengreaterthan') {
|
||||
blockContainer.blocklyListen({
|
||||
blockId: blockId,
|
||||
element: 'stackclick'
|
||||
}, vm.runtime);
|
||||
}
|
||||
}
|
||||
|
||||
// After two seconds, get playground data and stop
|
||||
setTimeout(() => {
|
||||
vm.getPlaygroundData();
|
||||
vm.stopAll();
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue