diff --git a/src/extension-support/tw-scratchx-compatibility-layer.js b/src/extension-support/tw-scratchx-compatibility-layer.js index bceae527aa..237bda809e 100644 --- a/src/extension-support/tw-scratchx-compatibility-layer.js +++ b/src/extension-support/tw-scratchx-compatibility-layer.js @@ -60,10 +60,12 @@ const isScratchCompatibleValue = v => typeof v === 'string' || typeof v === 'num const parseScratchXArgument = (argument, defaultValue) => { const result = {}; const hasDefaultValue = isScratchCompatibleValue(defaultValue); - if (hasDefaultValue) { + + // defaultValue is ignored for booleans in Scratch 3 + if (hasDefaultValue && argument !== 'b') { result.defaultValue = defaultValue; } - // TODO: ScratchX docs don't mention support for boolean arguments? + if (argument === 's') { result.type = ArgumentType.STRING; if (!hasDefaultValue) { @@ -79,6 +81,8 @@ const parseScratchXArgument = (argument, defaultValue) => { const split = argument.split(/\.|:/); const menuName = split[1]; result.menu = menuName; + } else if (argument === 'b') { + result.type = ArgumentType.BOOLEAN; } else { throw new Error(`Unknown ScratchX argument type: ${argument}`); } diff --git a/test/unit/tw_scratchx.js b/test/unit/tw_scratchx.js index bf2d8d9562..9619919b42 100644 --- a/test/unit/tw_scratchx.js +++ b/test/unit/tw_scratchx.js @@ -74,7 +74,7 @@ test('complex extension', async t => { return 'This value should be ignored.'; }; - const touching = sprite => sprite === 'Sprite9'; + const touching = (sprite, bool) => sprite === 'Sprite9' && bool === true; const converted = convert( 'My Extension', @@ -87,7 +87,7 @@ test('complex extension', async t => { ['r', 'multiply %n by %n and append %s', 'multiplyAndAppend'], ['R', 'repeat %m.myMenu %n', 'repeat', ''], ['-'], - ['b', 'touching %s', 'touching', 'Sprite1'] + ['b', 'touching %s %b', 'touching', 'Sprite1', 'ignored'] ], menus: { myMenu: ['abc', 'def', 123, true, false], @@ -178,12 +178,15 @@ test('complex extension', async t => { '---', { opcode: 'touching', - text: 'touching [0]', + text: 'touching [0] [1]', blockType: 'Boolean', arguments: [ { type: 'string', defaultValue: 'Sprite1' + }, + { + type: 'Boolean' } ] } @@ -232,11 +235,17 @@ test('complex extension', async t => { }), 'scratchxscratchxscratchx'); t.equal(converted.touching({ - 0: 'Sprite1' + 0: 'Sprite1', + 1: true }), false); t.equal(converted.touching({ - 0: 'Sprite9' + 0: 'Sprite9', + 1: true }), true); + t.equal(converted.touching({ + 0: 'Sprite9', + 1: false + }), false); t.end(); });