mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-10 21:14:06 -04:00
Make Scratch 3 project timer more compatible with Scratch 2 currentMSecs usage
These compatibility changes: - Use runtime.currentMSecs for the Clock timer "now" value - Start executing hats before other threads change values - Update test and fixtures to work with earlier hat execution - Add test for hat execution block order
This commit is contained in:
parent
c5abcf5888
commit
2a60391fb4
9 changed files with 31 additions and 17 deletions
test/integration
|
@ -7,7 +7,7 @@ const Thread = require('../../src/engine/thread');
|
|||
const Runtime = require('../../src/engine/runtime');
|
||||
const execute = require('../../src/engine/execute.js');
|
||||
|
||||
const projectUri = path.resolve(__dirname, '../fixtures/loudness-hat-block.sb2');
|
||||
const projectUri = path.resolve(__dirname, '../fixtures/timer-greater-than-hat.sb2');
|
||||
const project = readFileToBuffer(projectUri);
|
||||
|
||||
const checkIsHatThread = (t, vm, hatThread) => {
|
||||
|
@ -24,8 +24,8 @@ const checkIsStackClickThread = (t, vm, stackClickThread) => {
|
|||
};
|
||||
|
||||
/**
|
||||
* loudness-hat-block.sb2 contains a single stack
|
||||
* when loudness > 10
|
||||
* timer-greater-than-hat.sb2 contains a single stack
|
||||
* when timer > -1
|
||||
* change color effect by 25
|
||||
* The intention is to make sure that the hat block condition is evaluated
|
||||
* on each frame.
|
||||
|
@ -111,7 +111,7 @@ test('edge activated hat thread not added twice', t => {
|
|||
*/
|
||||
test('edge activated hat should trigger for both sprites when sprite is duplicated', t => {
|
||||
|
||||
// Project that is similar to loudness-hat-block.sb2, but has code on the sprite so that
|
||||
// Project that is similar to timer-greater-than-hat.sb2, but has code on the sprite so that
|
||||
// the sprite can be duplicated
|
||||
const projectWithSpriteUri = path.resolve(__dirname, '../fixtures/edge-triggered-hat.sb3');
|
||||
const projectWithSprite = readFileToBuffer(projectWithSpriteUri);
|
||||
|
@ -134,9 +134,6 @@ test('edge activated hat should trigger for both sprites when sprite is duplicat
|
|||
t.equal(vm.runtime.threads.length, 1);
|
||||
checkIsHatThread(t, vm, vm.runtime.threads[0]);
|
||||
t.assert(vm.runtime.threads[0].status === Thread.STATUS_RUNNING);
|
||||
// Run execute on the thread to populate the runtime's
|
||||
// _edgeActivatedHatValues object
|
||||
execute(vm.runtime.sequencer, vm.runtime.threads[0]);
|
||||
let numTargetEdgeHats = vm.runtime.targets.reduce((val, target) =>
|
||||
val + Object.keys(target._edgeActivatedHatValues).length, 0);
|
||||
t.equal(numTargetEdgeHats, 1);
|
||||
|
@ -145,7 +142,6 @@ test('edge activated hat should trigger for both sprites when sprite is duplicat
|
|||
vm.runtime._step();
|
||||
// Check that the runtime's _edgeActivatedHatValues object has two separate keys
|
||||
// after execute is run on each thread
|
||||
vm.runtime.threads.forEach(thread => execute(vm.runtime.sequencer, thread));
|
||||
numTargetEdgeHats = vm.runtime.targets.reduce((val, target) =>
|
||||
val + Object.keys(target._edgeActivatedHatValues).length, 0);
|
||||
t.equal(numTargetEdgeHats, 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue