Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "blockShape" for extension blocks. #210

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
6 changes: 6 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,12 @@ class Runtime extends EventEmitter {
break;
}

// Check if "blockShape" is specified
if (blockInfo.blockShape) {
blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND;
}


const blockText = Array.isArray(blockInfo.text) ? blockInfo.text : [blockInfo.text];
let inTextNum = 0; // text for the next block "arm" is blockText[inTextNum]
let inBranchNum = 0; // how many branches have we placed into the JSON so far?
Expand Down
25 changes: 25 additions & 0 deletions src/extension-support/block-shape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Use the constants instead of manually redefining them again
const ScratchBlocksConstants = require('../engine/scratch-blocks-constants');

/**
* Types of block shapes
* @enum {number}
*/
const BlockShape = {
/**
* Output shape: hexagonal (booleans/predicates).
*/
HEXAGONAL: ScratchBlocksConstants.OUTPUT_SHAPE_HEXAGONAL,

/**
* Output shape: rounded (numbers).
*/
ROUND: ScratchBlocksConstants.OUTPUT_SHAPE_ROUND,

/**
* Output shape: squared (any/all values; strings).
*/
SQUARE: ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE
};

module.exports = BlockShape;
2 changes: 2 additions & 0 deletions src/extension-support/tw-extension-api-common.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const ArgumentType = require('./argument-type');
const BlockType = require('./block-type');
const BlockShape = require('./block-shape');
const TargetType = require('./target-type');
const Cast = require('../util/cast');

const Scratch = {
ArgumentType,
BlockType,
BlockShape,
TargetType,
Cast
};
Expand Down