diff --git a/extensions/qxsck/var-and-list.js b/extensions/qxsck/var-and-list.js index 83ef8aa0cd..f74093665c 100644 --- a/extensions/qxsck/var-and-list.js +++ b/extensions/qxsck/var-and-list.js @@ -1,3 +1,4 @@ + (function(Scratch) { 'use strict'; Scratch.translate.setup({ @@ -29,6 +30,7 @@ { opcode: 'getVar', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data'], text: Scratch.translate({ id: 'getVar', default: 'value of [VAR]' }), arguments: { VAR: { @@ -40,6 +42,7 @@ { opcode: 'seriVarsToJson', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data'], text: Scratch.translate({ id: 'seriVarsToJson', default: 'convert all variables starting with [START] to json' }), arguments: { START: { @@ -51,6 +54,7 @@ { opcode: 'setVar', blockType: Scratch.BlockType.COMMAND, + extensions: ['colours_data'], text: Scratch.translate({ id: 'setVar', default: 'set the value of [VAR] to [VALUE]' }), arguments: { VAR: { @@ -66,6 +70,7 @@ { opcode: 'getList', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'getList', default: 'value of [LIST]' }), arguments: { LIST: { @@ -77,6 +82,7 @@ { opcode: 'getValueOfList', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'getValueOfList', default: 'item [INDEX] of [LIST]' }), arguments: { LIST: { @@ -92,6 +98,7 @@ { opcode: 'seriListsToJson', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'seriListsToJson', default: 'convert all lists starting with [START] to json' }), arguments: { START: { @@ -103,6 +110,7 @@ { opcode: 'clearList', blockType: Scratch.BlockType.COMMAND, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'clearList', default: 'delete all of [LIST]' }), arguments: { LIST: { @@ -114,6 +122,7 @@ { opcode: 'deleteOfList', blockType: Scratch.BlockType.COMMAND, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'deleteOfList', default: 'delete [INDEX] of [LIST]' }), arguments: { LIST: { @@ -129,6 +138,7 @@ { opcode: 'addValueInList', blockType: Scratch.BlockType.COMMAND, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'addValueInList', default: 'add [VALUE] to [LIST]' }), arguments: { LIST: { @@ -144,6 +154,7 @@ { opcode: 'replaceOfList', blockType: Scratch.BlockType.COMMAND, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'replaceOfList', default: 'replace item [INDEX] of [LIST] with [VALUE]' }), arguments: { LIST: { @@ -163,6 +174,7 @@ { opcode: 'getIndexOfList', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'getIndexOfList', default: 'first index of [VALUE] in [LIST]' }), arguments: { LIST: { @@ -178,6 +190,7 @@ { opcode: 'getIndexesOfList', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'getIndexesOfList', default: 'indexes of [VALUE] in [LIST]' }), arguments: { LIST: { @@ -193,6 +206,7 @@ { opcode: 'length', blockType: Scratch.BlockType.REPORTER, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'length', default: 'length of [LIST]' }), arguments: { LIST: { @@ -204,6 +218,7 @@ { opcode: 'listContains', blockType: Scratch.BlockType.BOOLEAN, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'listContains', default: '[LIST] contains [VALUE] ?' }), arguments: { LIST: { @@ -219,6 +234,7 @@ { opcode: 'copyList', blockType: Scratch.BlockType.COMMAND, + extensions: ['colours_data_lists'], text: Scratch.translate({ id: 'copyList', default: 'copy [LIST1] to [LIST2]' }), arguments: { LIST1: { @@ -234,7 +250,6 @@ ] }; } - getVar(args, util) { const variable = util.target.lookupVariableByNameAndType(Scratch.Cast.toString(args.VAR), ''); return variable ? variable.value : ''; @@ -365,8 +380,8 @@ for (var i = 0;i < variable.value.length;i++) { if (Scratch.Cast.compare(variable.value[i], value) === 0) return true; } - } return false; + } } copyList(args, util) { /** @type {VM.ListVariable} */ @@ -377,5 +392,16 @@ } } } + + const runtime = Scratch.vm.runtime; + const cbfsb = runtime._convertBlockForScratchBlocks.bind(runtime); + runtime._convertBlockForScratchBlocks = function(blockInfo, categoryInfo) { + const res = cbfsb(blockInfo, categoryInfo); + if (blockInfo.extensions) { + if (!res.json.extensions) res.json.extensions = []; + res.json.extensions.push(...blockInfo.extensions); + } + return res; + }; Scratch.extensions.register(new VarAndList()); }(Scratch));