From bc2824dfdc17a0fa5c9e5c4e590ac4300265c8d8 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Tue, 19 Mar 2019 15:31:30 -0400 Subject: [PATCH] Add an example core blocks category using the extension spec. --- src/blocks/scratch3_core_example.js | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/blocks/scratch3_core_example.js diff --git a/src/blocks/scratch3_core_example.js b/src/blocks/scratch3_core_example.js new file mode 100644 index 000000000..b53d0b111 --- /dev/null +++ b/src/blocks/scratch3_core_example.js @@ -0,0 +1,44 @@ +const BlockType = require('../extension-support/block-type'); + +/** + * An example core block implemented using the extension spec. + * This is not loaded as part of the core blocks in the VM but it is provided + * and used as part of tests. + */ +class Scratch3CoreExample { + constructor (runtime) { + /** + * The runtime instantiating this block package. + * @type {Runtime} + */ + this.runtime = runtime; + } + + /** + * @returns {object} metadata for this extension and its blocks. + */ + getInfo () { + return { + id: 'coreExample', + name: 'CoreEx', // This string does not need to be translated as this extension is only used as an example. + blocks: [ + { + opcode: 'exampleOpcode', + blockType: BlockType.REPORTER, + text: 'example block' + } + ] + }; + } + + /** + * Example opcode just returns the name of the stage target. + * @returns {string} The name of the first target in the project. + */ + exampleOpcode () { + return this.runtime.getTargetForStage().getName(); + } + +} + +module.exports = Scratch3CoreExample;