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 {
1429
1429
break ;
1430
1430
}
1431
1431
1432
+ // Allow extensiosn to override outputShape
1433
+ if ( blockInfo . blockShape ) {
1434
+ blockJSON . outputShape = blockInfo . blockShape ;
1435
+ }
1436
+
1432
1437
const blockText = Array . isArray ( blockInfo . text ) ? blockInfo . text : [ blockInfo . text ] ;
1433
1438
let inTextNum = 0 ; // text for the next block "arm" is blockText[inTextNum]
1434
1439
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 1
1
const ArgumentType = require ( './argument-type' ) ;
2
2
const BlockType = require ( './block-type' ) ;
3
+ const BlockShape = require ( './tw-block-shape' ) ;
3
4
const TargetType = require ( './target-type' ) ;
4
5
const Cast = require ( '../util/cast' ) ;
5
6
6
7
const Scratch = {
7
8
ArgumentType,
8
9
BlockType,
10
+ BlockShape,
9
11
TargetType,
10
12
Cast
11
13
} ;
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