File tree Expand file tree Collapse file tree 4 files changed +70
-0
lines changed Expand file tree Collapse file tree 4 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -1429,6 +1429,11 @@ class Runtime extends EventEmitter {
14291429 break ;
14301430 }
14311431
1432+ // Allow extensiosn to override outputShape
1433+ if ( blockInfo . blockShape ) {
1434+ blockJSON . outputShape = blockInfo . blockShape ;
1435+ }
1436+
14321437 const blockText = Array . isArray ( blockInfo . text ) ? blockInfo . text : [ blockInfo . text ] ;
14331438 let inTextNum = 0 ; // text for the next block "arm" is blockText[inTextNum]
14341439 let inBranchNum = 0 ; // how many branches have we placed into the JSON so far?
Original file line number Diff line number Diff line change 1+ // Use the constants instead of manually redefining them again
2+ const ScratchBlocksConstants = require ( '../engine/scratch-blocks-constants' ) ;
3+
4+ /**
5+ * Types of block shapes
6+ * @enum {number}
7+ */
8+ const BlockShape = {
9+ /**
10+ * Output shape: hexagonal (booleans/predicates).
11+ */
12+ HEXAGONAL : ScratchBlocksConstants . OUTPUT_SHAPE_HEXAGONAL ,
13+
14+ /**
15+ * Output shape: rounded (numbers).
16+ */
17+ ROUND : ScratchBlocksConstants . OUTPUT_SHAPE_ROUND ,
18+
19+ /**
20+ * Output shape: squared (any/all values; strings).
21+ */
22+ SQUARE : ScratchBlocksConstants . OUTPUT_SHAPE_SQUARE
23+ } ;
24+
25+ module . exports = BlockShape ;
Original file line number Diff line number Diff line change 11const ArgumentType = require ( './argument-type' ) ;
22const BlockType = require ( './block-type' ) ;
3+ const BlockShape = require ( './tw-block-shape' ) ;
34const TargetType = require ( './target-type' ) ;
45const Cast = require ( '../util/cast' ) ;
56
67const Scratch = {
78 ArgumentType,
89 BlockType,
10+ BlockShape,
911 TargetType,
1012 Cast
1113} ;
Original file line number Diff line number Diff line change 1+ const { test} = require ( 'tap' ) ;
2+ const Runtime = require ( '../../src/engine/runtime' ) ;
3+ const Scratch = require ( '../../src/extension-support/tw-extension-api-common' ) ;
4+
5+ test ( 'blockShape' , t => {
6+ const rt = new Runtime ( ) ;
7+ rt . _registerExtensionPrimitives ( {
8+ id : 'shapetest' ,
9+ name : 'shapetest' ,
10+ blocks : [
11+ {
12+ blockType : Scratch . BlockType . REPORTER ,
13+ blockShape : Scratch . BlockShape . HEXAGONAL ,
14+ opcode : 'hexagonal' ,
15+ text : 'hexagonal'
16+ } ,
17+ {
18+ blockType : Scratch . BlockType . BOOLEAN ,
19+ blockShape : Scratch . BlockShape . ROUND ,
20+ opcode : 'round' ,
21+ text : 'round'
22+ } ,
23+ {
24+ blockType : Scratch . BlockType . REPORTER ,
25+ blockShape : Scratch . BlockShape . SQUARE ,
26+ opcode : 'square' ,
27+ text : 'square'
28+ }
29+ ]
30+ } ) ;
31+
32+ const json = rt . getBlocksJSON ( ) ;
33+ t . equal ( json . length , 3 ) ;
34+ t . equal ( json [ 0 ] . outputShape , 1 ) ;
35+ t . equal ( json [ 1 ] . outputShape , 2 ) ;
36+ t . equal ( json [ 2 ] . outputShape , 3 ) ;
37+ t . end ( ) ;
38+ } ) ;
You can’t perform that action at this time.
0 commit comments