mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-07-30 16:10:27 -04:00
* Allow 'isTouching' and 'pick' to still work on invisible drawables.
* Always ignore visibility for isTouching on drawable
* Filter invisble drawbles in isTouchingDrawable per rules of collision
* polish up some docs/get logic 👍
* leftover line from deleted comment
* revert to ghosted pick behavior
* Add clientSpaceToScratchBounds method
* fix lint
* add some pick tests
56 lines
2.1 KiB
JavaScript
56 lines
2.1 KiB
JavaScript
/* global vm, render, Promise */
|
|
const {Chromeless} = require('chromeless');
|
|
const test = require('tap').test;
|
|
const path = require('path');
|
|
const chromeless = new Chromeless();
|
|
|
|
const indexHTML = path.resolve(__dirname, 'index.html');
|
|
const testDir = (...args) => path.resolve(__dirname, 'pick-tests', ...args);
|
|
|
|
const runFile = (file, script) =>
|
|
// start each test by going to the index.html, and loading the scratch file
|
|
chromeless.goto(`file://${indexHTML}`)
|
|
.setFileInput('#file', testDir(file))
|
|
// the index.html handler for file input will add a #loaded element when it
|
|
// finishes.
|
|
.wait('#loaded')
|
|
.evaluate(script)
|
|
;
|
|
|
|
// immediately invoked async function to let us wait for each test to finish before starting the next.
|
|
(async () => {
|
|
|
|
await test('pick tests', async t => {
|
|
|
|
const results = await runFile('test-mouse-touch.sb2', () => {
|
|
vm.greenFlag();
|
|
const sendResults = [];
|
|
|
|
const idToTargetName = id => vm.runtime.targets.find(target => target.drawableID === id).sprite.name;
|
|
const sprite = vm.runtime.targets.find(target => target.sprite.name === 'Sprite1');
|
|
|
|
sendResults.push(['center', idToTargetName(render.pick(240, 180))]);
|
|
sendResults.push(['left', idToTargetName(render.pick(200, 180))]);
|
|
sendResults.push(['over', render.drawableTouching(sprite.drawableID, 240, 180)]);
|
|
sprite.setVisible(false);
|
|
sendResults.push(['hidden sprite pick center', idToTargetName(render.pick(240, 180))]);
|
|
sendResults.push(['hidden over', render.drawableTouching(sprite.drawableID, 240, 180)]);
|
|
return sendResults;
|
|
});
|
|
const expect = [
|
|
['center', 'Sprite1'],
|
|
['left', 'Stage'],
|
|
['over', true],
|
|
['hidden sprite pick center', 'Stage'],
|
|
['hidden over', true]
|
|
];
|
|
t.plan(expect.length);
|
|
for (let x = 0; x < expect.length; x++) {
|
|
t.deepEqual(results[x], expect[x], expect[x][0]);
|
|
}
|
|
t.end();
|
|
});
|
|
|
|
// close the browser window we used
|
|
await chromeless.end();
|
|
})();
|