mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Merge branch 'develop' of github.com:LLK/scratch-vm into develop
This commit is contained in:
commit
d5c91c3b41
5 changed files with 143 additions and 63 deletions
|
@ -29,11 +29,11 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"adm-zip": "0.4.7",
|
"adm-zip": "0.4.7",
|
||||||
|
"arraybuffer-loader": "^1.0.3",
|
||||||
"babel-core": "^6.24.1",
|
"babel-core": "^6.24.1",
|
||||||
"babel-eslint": "^7.1.1",
|
"babel-eslint": "^7.1.1",
|
||||||
"babel-loader": "^7.0.0",
|
"babel-loader": "^7.0.0",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"buffer-loader": "0.0.1",
|
|
||||||
"canvas-toBlob": "1.0.0",
|
"canvas-toBlob": "1.0.0",
|
||||||
"copy-webpack-plugin": "4.2.1",
|
"copy-webpack-plugin": "4.2.1",
|
||||||
"decode-html": "2.0.0",
|
"decode-html": "2.0.0",
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Scratch3DataBlocks {
|
||||||
data_insertatlist: this.insertAtList,
|
data_insertatlist: this.insertAtList,
|
||||||
data_replaceitemoflist: this.replaceItemOfList,
|
data_replaceitemoflist: this.replaceItemOfList,
|
||||||
data_itemoflist: this.getItemOfList,
|
data_itemoflist: this.getItemOfList,
|
||||||
|
data_itemnumoflist: this.getItemNumOfList,
|
||||||
data_lengthoflist: this.lengthOfList,
|
data_lengthoflist: this.lengthOfList,
|
||||||
data_listcontainsitem: this.listContainsItem
|
data_listcontainsitem: this.listContainsItem
|
||||||
};
|
};
|
||||||
|
@ -129,6 +130,34 @@ class Scratch3DataBlocks {
|
||||||
return list.value[index - 1];
|
return list.value[index - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getItemNumOfList (args, util) {
|
||||||
|
const item = args.ITEM;
|
||||||
|
const list = util.target.lookupOrCreateList(
|
||||||
|
args.LIST.id, args.LIST.name);
|
||||||
|
|
||||||
|
// Go through the list items one-by-one using Cast.compare. This is for
|
||||||
|
// cases like checking if 123 is contained in a list [4, 7, '123'] --
|
||||||
|
// Scratch considers 123 and '123' to be equal.
|
||||||
|
for (let i = 0; i < list.value.length; i++) {
|
||||||
|
if (Cast.compare(list.value[i], item) === 0) {
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't bother using .indexOf() at all, because it would end up with
|
||||||
|
// edge cases such as the index of '123' in [4, 7, 123, '123', 9].
|
||||||
|
// If we use indexOf(), this block would return 4 instead of 3, because
|
||||||
|
// indexOf() sees the first occurence of the string 123 as the fourth
|
||||||
|
// item in the list. With Scratch, this would be confusing -- after all,
|
||||||
|
// '123' and 123 look the same, so one would expect the block to say
|
||||||
|
// that the first occurrence of '123' (or 123) to be the third item.
|
||||||
|
|
||||||
|
// Default to 0 if there's no match. Since Scratch lists are 1-indexed,
|
||||||
|
// we don't have to worry about this conflicting with the "this item is
|
||||||
|
// the first value" number (in JS that is 0, but in Scratch it's 1).
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
lengthOfList (args, util) {
|
lengthOfList (args, util) {
|
||||||
const list = util.target.lookupOrCreateList(
|
const list = util.target.lookupOrCreateList(
|
||||||
args.LIST.id, args.LIST.name);
|
args.LIST.id, args.LIST.name);
|
||||||
|
|
|
@ -115,7 +115,7 @@ class Scratch3MusicBlocks {
|
||||||
if (!assetData[fullPath]) return;
|
if (!assetData[fullPath]) return;
|
||||||
|
|
||||||
// The sound buffer has already been downloaded via the manifest file required above.
|
// The sound buffer has already been downloaded via the manifest file required above.
|
||||||
const soundBuffer = assetData[fullPath].buffer;
|
const soundBuffer = assetData[fullPath];
|
||||||
|
|
||||||
return this._decodeSound(soundBuffer).then(buffer => {
|
return this._decodeSound(soundBuffer).then(buffer => {
|
||||||
bufferArray[index] = buffer;
|
bufferArray[index] = buffer;
|
||||||
|
|
|
@ -1,63 +1,65 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'drums/1-snare.mp3': require('!buffer-loader!./assets/drums/1-snare.mp3'),
|
'drums/1-snare.mp3': require('!arraybuffer-loader!./assets/drums/1-snare.mp3'),
|
||||||
'drums/2-bass-drum.mp3': require('!buffer-loader!./assets/drums/2-bass-drum.mp3'),
|
'drums/2-bass-drum.mp3': require('!arraybuffer-loader!./assets/drums/2-bass-drum.mp3'),
|
||||||
'drums/3-side-stick.mp3': require('!buffer-loader!./assets/drums/3-side-stick.mp3'),
|
'drums/3-side-stick.mp3': require('!arraybuffer-loader!./assets/drums/3-side-stick.mp3'),
|
||||||
'drums/4-crash-cymbal.mp3': require('!buffer-loader!./assets/drums/4-crash-cymbal.mp3'),
|
'drums/4-crash-cymbal.mp3': require('!arraybuffer-loader!./assets/drums/4-crash-cymbal.mp3'),
|
||||||
'drums/5-open-hi-hat.mp3': require('!buffer-loader!./assets/drums/5-open-hi-hat.mp3'),
|
'drums/5-open-hi-hat.mp3': require('!arraybuffer-loader!./assets/drums/5-open-hi-hat.mp3'),
|
||||||
'drums/6-closed-hi-hat.mp3': require('!buffer-loader!./assets/drums/6-closed-hi-hat.mp3'),
|
'drums/6-closed-hi-hat.mp3': require('!arraybuffer-loader!./assets/drums/6-closed-hi-hat.mp3'),
|
||||||
'drums/7-tambourine.mp3': require('!buffer-loader!./assets/drums/7-tambourine.mp3'),
|
'drums/7-tambourine.mp3': require('!arraybuffer-loader!./assets/drums/7-tambourine.mp3'),
|
||||||
'drums/8-hand-clap.mp3': require('!buffer-loader!./assets/drums/8-hand-clap.mp3'),
|
'drums/8-hand-clap.mp3': require('!arraybuffer-loader!./assets/drums/8-hand-clap.mp3'),
|
||||||
'drums/9-claves.mp3': require('!buffer-loader!./assets/drums/9-claves.mp3'),
|
'drums/9-claves.mp3': require('!arraybuffer-loader!./assets/drums/9-claves.mp3'),
|
||||||
'drums/10-wood-block.mp3': require('!buffer-loader!./assets/drums/10-wood-block.mp3'),
|
'drums/10-wood-block.mp3': require('!arraybuffer-loader!./assets/drums/10-wood-block.mp3'),
|
||||||
'drums/11-cowbell.mp3': require('!buffer-loader!./assets/drums/11-cowbell.mp3'),
|
'drums/11-cowbell.mp3': require('!arraybuffer-loader!./assets/drums/11-cowbell.mp3'),
|
||||||
'drums/12-triangle.mp3': require('!buffer-loader!./assets/drums/12-triangle.mp3'),
|
'drums/12-triangle.mp3': require('!arraybuffer-loader!./assets/drums/12-triangle.mp3'),
|
||||||
'drums/13-bongo.mp3': require('!buffer-loader!./assets/drums/13-bongo.mp3'),
|
'drums/13-bongo.mp3': require('!arraybuffer-loader!./assets/drums/13-bongo.mp3'),
|
||||||
'drums/14-conga.mp3': require('!buffer-loader!./assets/drums/14-conga.mp3'),
|
'drums/14-conga.mp3': require('!arraybuffer-loader!./assets/drums/14-conga.mp3'),
|
||||||
'drums/15-cabasa.mp3': require('!buffer-loader!./assets/drums/15-cabasa.mp3'),
|
'drums/15-cabasa.mp3': require('!arraybuffer-loader!./assets/drums/15-cabasa.mp3'),
|
||||||
'drums/16-guiro.mp3': require('!buffer-loader!./assets/drums/16-guiro.mp3'),
|
'drums/16-guiro.mp3': require('!arraybuffer-loader!./assets/drums/16-guiro.mp3'),
|
||||||
'drums/17-vibraslap.mp3': require('!buffer-loader!./assets/drums/17-vibraslap.mp3'),
|
'drums/17-vibraslap.mp3': require('!arraybuffer-loader!./assets/drums/17-vibraslap.mp3'),
|
||||||
'drums/18-cuica.mp3': require('!buffer-loader!./assets/drums/18-cuica.mp3'),
|
'drums/18-cuica.mp3': require('!arraybuffer-loader!./assets/drums/18-cuica.mp3'),
|
||||||
'instruments/1-piano/24.mp3': require('!buffer-loader!./assets/instruments/1-piano/24.mp3'),
|
'instruments/1-piano/24.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/24.mp3'),
|
||||||
'instruments/1-piano/36.mp3': require('!buffer-loader!./assets/instruments/1-piano/36.mp3'),
|
'instruments/1-piano/36.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/36.mp3'),
|
||||||
'instruments/1-piano/48.mp3': require('!buffer-loader!./assets/instruments/1-piano/48.mp3'),
|
'instruments/1-piano/48.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/48.mp3'),
|
||||||
'instruments/1-piano/60.mp3': require('!buffer-loader!./assets/instruments/1-piano/60.mp3'),
|
'instruments/1-piano/60.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/60.mp3'),
|
||||||
'instruments/1-piano/72.mp3': require('!buffer-loader!./assets/instruments/1-piano/72.mp3'),
|
'instruments/1-piano/72.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/72.mp3'),
|
||||||
'instruments/1-piano/84.mp3': require('!buffer-loader!./assets/instruments/1-piano/84.mp3'),
|
'instruments/1-piano/84.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/84.mp3'),
|
||||||
'instruments/1-piano/96.mp3': require('!buffer-loader!./assets/instruments/1-piano/96.mp3'),
|
'instruments/1-piano/96.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/96.mp3'),
|
||||||
'instruments/1-piano/108.mp3': require('!buffer-loader!./assets/instruments/1-piano/108.mp3'),
|
'instruments/1-piano/108.mp3': require('!arraybuffer-loader!./assets/instruments/1-piano/108.mp3'),
|
||||||
'instruments/2-electric-piano/60.mp3': require('!buffer-loader!./assets/instruments/2-electric-piano/60.mp3'),
|
'instruments/2-electric-piano/60.mp3': require('!arraybuffer-loader!./assets/instruments/2-electric-piano/60.mp3'),
|
||||||
'instruments/3-organ/60.mp3': require('!buffer-loader!./assets/instruments/3-organ/60.mp3'),
|
'instruments/3-organ/60.mp3': require('!arraybuffer-loader!./assets/instruments/3-organ/60.mp3'),
|
||||||
'instruments/4-guitar/60.mp3': require('!buffer-loader!./assets/instruments/4-guitar/60.mp3'),
|
'instruments/4-guitar/60.mp3': require('!arraybuffer-loader!./assets/instruments/4-guitar/60.mp3'),
|
||||||
'instruments/5-electric-guitar/60.mp3': require('!buffer-loader!./assets/instruments/5-electric-guitar/60.mp3'),
|
'instruments/5-electric-guitar/60.mp3': require(
|
||||||
'instruments/6-bass/36.mp3': require('!buffer-loader!./assets/instruments/6-bass/36.mp3'),
|
'!arraybuffer-loader!./assets/instruments/5-electric-guitar/60.mp3'
|
||||||
'instruments/6-bass/48.mp3': require('!buffer-loader!./assets/instruments/6-bass/48.mp3'),
|
),
|
||||||
'instruments/7-pizzicato/60.mp3': require('!buffer-loader!./assets/instruments/7-pizzicato/60.mp3'),
|
'instruments/6-bass/36.mp3': require('!arraybuffer-loader!./assets/instruments/6-bass/36.mp3'),
|
||||||
'instruments/8-cello/36.mp3': require('!buffer-loader!./assets/instruments/8-cello/36.mp3'),
|
'instruments/6-bass/48.mp3': require('!arraybuffer-loader!./assets/instruments/6-bass/48.mp3'),
|
||||||
'instruments/8-cello/48.mp3': require('!buffer-loader!./assets/instruments/8-cello/48.mp3'),
|
'instruments/7-pizzicato/60.mp3': require('!arraybuffer-loader!./assets/instruments/7-pizzicato/60.mp3'),
|
||||||
'instruments/8-cello/60.mp3': require('!buffer-loader!./assets/instruments/8-cello/60.mp3'),
|
'instruments/8-cello/36.mp3': require('!arraybuffer-loader!./assets/instruments/8-cello/36.mp3'),
|
||||||
'instruments/9-trombone/36.mp3': require('!buffer-loader!./assets/instruments/9-trombone/36.mp3'),
|
'instruments/8-cello/48.mp3': require('!arraybuffer-loader!./assets/instruments/8-cello/48.mp3'),
|
||||||
'instruments/9-trombone/48.mp3': require('!buffer-loader!./assets/instruments/9-trombone/48.mp3'),
|
'instruments/8-cello/60.mp3': require('!arraybuffer-loader!./assets/instruments/8-cello/60.mp3'),
|
||||||
'instruments/9-trombone/60.mp3': require('!buffer-loader!./assets/instruments/9-trombone/60.mp3'),
|
'instruments/9-trombone/36.mp3': require('!arraybuffer-loader!./assets/instruments/9-trombone/36.mp3'),
|
||||||
'instruments/10-clarinet/48.mp3': require('!buffer-loader!./assets/instruments/10-clarinet/48.mp3'),
|
'instruments/9-trombone/48.mp3': require('!arraybuffer-loader!./assets/instruments/9-trombone/48.mp3'),
|
||||||
'instruments/10-clarinet/60.mp3': require('!buffer-loader!./assets/instruments/10-clarinet/60.mp3'),
|
'instruments/9-trombone/60.mp3': require('!arraybuffer-loader!./assets/instruments/9-trombone/60.mp3'),
|
||||||
'instruments/11-saxophone/36.mp3': require('!buffer-loader!./assets/instruments/11-saxophone/36.mp3'),
|
'instruments/10-clarinet/48.mp3': require('!arraybuffer-loader!./assets/instruments/10-clarinet/48.mp3'),
|
||||||
'instruments/11-saxophone/60.mp3': require('!buffer-loader!./assets/instruments/11-saxophone/60.mp3'),
|
'instruments/10-clarinet/60.mp3': require('!arraybuffer-loader!./assets/instruments/10-clarinet/60.mp3'),
|
||||||
'instruments/11-saxophone/84.mp3': require('!buffer-loader!./assets/instruments/11-saxophone/84.mp3'),
|
'instruments/11-saxophone/36.mp3': require('!arraybuffer-loader!./assets/instruments/11-saxophone/36.mp3'),
|
||||||
'instruments/12-flute/60.mp3': require('!buffer-loader!./assets/instruments/12-flute/60.mp3'),
|
'instruments/11-saxophone/60.mp3': require('!arraybuffer-loader!./assets/instruments/11-saxophone/60.mp3'),
|
||||||
'instruments/12-flute/72.mp3': require('!buffer-loader!./assets/instruments/12-flute/72.mp3'),
|
'instruments/11-saxophone/84.mp3': require('!arraybuffer-loader!./assets/instruments/11-saxophone/84.mp3'),
|
||||||
'instruments/13-wooden-flute/60.mp3': require('!buffer-loader!./assets/instruments/13-wooden-flute/60.mp3'),
|
'instruments/12-flute/60.mp3': require('!arraybuffer-loader!./assets/instruments/12-flute/60.mp3'),
|
||||||
'instruments/13-wooden-flute/72.mp3': require('!buffer-loader!./assets/instruments/13-wooden-flute/72.mp3'),
|
'instruments/12-flute/72.mp3': require('!arraybuffer-loader!./assets/instruments/12-flute/72.mp3'),
|
||||||
'instruments/14-bassoon/36.mp3': require('!buffer-loader!./assets/instruments/14-bassoon/36.mp3'),
|
'instruments/13-wooden-flute/60.mp3': require('!arraybuffer-loader!./assets/instruments/13-wooden-flute/60.mp3'),
|
||||||
'instruments/14-bassoon/48.mp3': require('!buffer-loader!./assets/instruments/14-bassoon/48.mp3'),
|
'instruments/13-wooden-flute/72.mp3': require('!arraybuffer-loader!./assets/instruments/13-wooden-flute/72.mp3'),
|
||||||
'instruments/14-bassoon/60.mp3': require('!buffer-loader!./assets/instruments/14-bassoon/60.mp3'),
|
'instruments/14-bassoon/36.mp3': require('!arraybuffer-loader!./assets/instruments/14-bassoon/36.mp3'),
|
||||||
'instruments/15-choir/48.mp3': require('!buffer-loader!./assets/instruments/15-choir/48.mp3'),
|
'instruments/14-bassoon/48.mp3': require('!arraybuffer-loader!./assets/instruments/14-bassoon/48.mp3'),
|
||||||
'instruments/15-choir/60.mp3': require('!buffer-loader!./assets/instruments/15-choir/60.mp3'),
|
'instruments/14-bassoon/60.mp3': require('!arraybuffer-loader!./assets/instruments/14-bassoon/60.mp3'),
|
||||||
'instruments/15-choir/72.mp3': require('!buffer-loader!./assets/instruments/15-choir/72.mp3'),
|
'instruments/15-choir/48.mp3': require('!arraybuffer-loader!./assets/instruments/15-choir/48.mp3'),
|
||||||
'instruments/16-vibraphone/60.mp3': require('!buffer-loader!./assets/instruments/16-vibraphone/60.mp3'),
|
'instruments/15-choir/60.mp3': require('!arraybuffer-loader!./assets/instruments/15-choir/60.mp3'),
|
||||||
'instruments/16-vibraphone/72.mp3': require('!buffer-loader!./assets/instruments/16-vibraphone/72.mp3'),
|
'instruments/15-choir/72.mp3': require('!arraybuffer-loader!./assets/instruments/15-choir/72.mp3'),
|
||||||
'instruments/17-music-box/60.mp3': require('!buffer-loader!./assets/instruments/17-music-box/60.mp3'),
|
'instruments/16-vibraphone/60.mp3': require('!arraybuffer-loader!./assets/instruments/16-vibraphone/60.mp3'),
|
||||||
'instruments/18-steel-drum/60.mp3': require('!buffer-loader!./assets/instruments/18-steel-drum/60.mp3'),
|
'instruments/16-vibraphone/72.mp3': require('!arraybuffer-loader!./assets/instruments/16-vibraphone/72.mp3'),
|
||||||
'instruments/19-marimba/60.mp3': require('!buffer-loader!./assets/instruments/19-marimba/60.mp3'),
|
'instruments/17-music-box/60.mp3': require('!arraybuffer-loader!./assets/instruments/17-music-box/60.mp3'),
|
||||||
'instruments/20-synth-lead/60.mp3': require('!buffer-loader!./assets/instruments/20-synth-lead/60.mp3'),
|
'instruments/18-steel-drum/60.mp3': require('!arraybuffer-loader!./assets/instruments/18-steel-drum/60.mp3'),
|
||||||
'instruments/21-synth-pad/60.mp3': require('!buffer-loader!./assets/instruments/21-synth-pad/60.mp3')
|
'instruments/19-marimba/60.mp3': require('!arraybuffer-loader!./assets/instruments/19-marimba/60.mp3'),
|
||||||
|
'instruments/20-synth-lead/60.mp3': require('!arraybuffer-loader!./assets/instruments/20-synth-lead/60.mp3'),
|
||||||
|
'instruments/21-synth-pad/60.mp3': require('!arraybuffer-loader!./assets/instruments/21-synth-pad/60.mp3')
|
||||||
};
|
};
|
||||||
|
|
49
test/unit/blocks_data.js
Normal file
49
test/unit/blocks_data.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
const test = require('tap').test;
|
||||||
|
const Data = require('../../src/blocks/scratch3_data');
|
||||||
|
|
||||||
|
const blocks = new Data();
|
||||||
|
|
||||||
|
const lists = {};
|
||||||
|
const util = {
|
||||||
|
target: {
|
||||||
|
lookupOrCreateList (id, name) {
|
||||||
|
if (!(name in lists)) {
|
||||||
|
lists[name] = {value: []};
|
||||||
|
}
|
||||||
|
return lists[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
test('getItemNumOfList returns the index of an item (basic)', t => {
|
||||||
|
lists.list = {value: ['apple', 'taco', 'burrito', 'extravaganza']};
|
||||||
|
const args = {ITEM: 'burrito', LIST: {name: 'list'}};
|
||||||
|
const index = blocks.getItemNumOfList(args, util);
|
||||||
|
t.strictEqual(index, 3);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getItemNumOfList returns 0 when an item is not found', t => {
|
||||||
|
lists.list = {value: ['aaaaapple', 'burrito']};
|
||||||
|
const args = {ITEM: 'jump', LIST: {name: 'list'}};
|
||||||
|
const index = blocks.getItemNumOfList(args, util);
|
||||||
|
t.strictEqual(index, 0);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getItemNumOfList uses Scratch comparison', t => {
|
||||||
|
lists.list = {value: ['jump', 'Jump', '123', 123, 800]};
|
||||||
|
const args = {LIST: {name: 'list'}};
|
||||||
|
|
||||||
|
// Be case-insensitive:
|
||||||
|
args.ITEM = 'Jump';
|
||||||
|
t.strictEqual(blocks.getItemNumOfList(args, util), 1);
|
||||||
|
|
||||||
|
// Be type-insensitive:
|
||||||
|
args.ITEM = 123;
|
||||||
|
t.strictEqual(blocks.getItemNumOfList(args, util), 3);
|
||||||
|
args.ITEM = '800';
|
||||||
|
t.strictEqual(blocks.getItemNumOfList(args, util), 5);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
Loading…
Reference in a new issue