|
11 | 11 | } |
12 | 12 |
|
13 | 13 | const BlockType = Scratch.BlockType |
14 | | - const BlockShape = Scratch.BlockShape |
15 | 14 | const ArgumentType = Scratch.ArgumentType |
16 | | - const TargetType = Scratch.TargetType |
17 | 15 | const Cast = Scratch.Cast |
18 | 16 | const vm = Scratch.vm; |
19 | | - const runtime = Scratch.vm.runtime; |
20 | | - const SB = ScratchBlocks; |
21 | | - |
22 | | - SB.BlockSvg.registerCustomShape( |
23 | | - "dogeiscutRegularExpressions-RegularExpression", { |
24 | | - emptyInputPath: "m 16 0 h 16 h 32 l -16 32 h -16 h -16 h -16 z", |
25 | | - emptyInputWidth: 16 * ScratchBlocks.BlockSvg.GRID_UNIT, |
26 | | - leftPath: (block) => { |
27 | | - const scale = block.height / 2; |
28 | | - const s = scale / 16; |
29 | | - return [ |
30 | | - `h ${-16 * s}`, |
31 | | - ]; |
32 | | - }, |
33 | | - rightPath: (block) => { |
34 | | - const scale = block.edgeShapeWidth_; |
35 | | - const s = scale / 16; |
36 | | - return [ |
37 | | - `h ${16 * s}`, |
38 | | - `l ${-16 * s} ${32 * s}`, |
39 | | - `h 0`, |
40 | | - `h ${-16 * s}`, |
41 | | - ]; |
42 | | - }, |
43 | | - blockPaddingStart: (_, _2, _3, _4, row) => { |
44 | | - return (row.height - 16) / 2; |
45 | | - }, |
46 | | - blockPaddingEnd: (_, _2, _3, _4, row) => { |
47 | | - return (row.height - 16) / 2; |
48 | | - } |
49 | | - } |
50 | | - ); |
| 17 | + |
| 18 | + if (Scratch.gui) { |
| 19 | + Scratch.gui.getBlockly().then(ScratchBlocks => { |
| 20 | + ScratchBlocks.BlockSvg.registerCustomShape( |
| 21 | + "dogeiscutRegularExpressions-RegularExpression",{ |
| 22 | + emptyInputPath: "m 16 0 h 16 h 32 l -16 32 h -16 h -16 h -16 z", |
| 23 | + emptyInputWidth: 16 * ScratchBlocks.BlockSvg.GRID_UNIT, |
| 24 | + leftPath: (block) => { |
| 25 | + const scale = block.height / 2; |
| 26 | + const s = scale / 16; |
| 27 | + return [ |
| 28 | + `h ${-16 * s}`, |
| 29 | + ]; |
| 30 | + }, |
| 31 | + rightPath: (block) => { |
| 32 | + const scale = block.edgeShapeWidth_; |
| 33 | + const s = scale / 16; |
| 34 | + return [ |
| 35 | + `h ${16 * s}`, |
| 36 | + `l ${-16 * s} ${32 * s}`, |
| 37 | + `h 0`, |
| 38 | + `h ${-16 * s}`, |
| 39 | + ]; |
| 40 | + }, |
| 41 | + blockPaddingStart: (_, _2, _3, _4, row) => { |
| 42 | + return (row.height - 16) / 2; |
| 43 | + }, |
| 44 | + blockPaddingEnd: (_, _2, _3, _4, row) => { |
| 45 | + return (row.height - 16) / 2; |
| 46 | + } |
| 47 | + } |
| 48 | + ); |
| 49 | + }) |
| 50 | + } |
51 | 51 |
|
52 | 52 | function span(text) { |
53 | 53 | let el = document.createElement('span') |
|
0 commit comments