@@ -7,6 +7,33 @@ export default async function ({ addon, console }) {
7
7
8
8
const { GRID_UNIT } = BlockSvg ;
9
9
10
+ function scalePathXY ( path , scaleX , scaleY ) {
11
+ const util = BlockSvg . CUSTOM_NOTCH_UTIL ;
12
+ const tokens = util . path2TokenList ( pathStr ) ;
13
+ const result = [ ] ;
14
+ let i = 0 ;
15
+ while ( i < tokens . length ) {
16
+ const cmd = tokens [ i ++ ] ;
17
+ result . push ( cmd ) ;
18
+
19
+ const expected = util . supportedCommands [ cmd ] ;
20
+ const xIndexes = util . commandXpos [ cmd ] || [ ] ;
21
+
22
+ while ( i + expected <= tokens . length && ! / ^ [ a - z ] $ / i. test ( tokens [ i ] ) ) {
23
+ for ( let j = 0 ; j < expected ; j ++ ) {
24
+ let val = parseFloat ( tokens [ i + j ] ) ;
25
+ if ( isNaN ( val ) ) throw new Error ( `Invalid number '${ tokens [ i + j ] } '` ) ;
26
+
27
+ if ( xIndexes . includes ( j ) ) val *= scaleX ;
28
+ else val *= scaleY ;
29
+ result . push ( + val . toFixed ( 6 ) ) ;
30
+ }
31
+ i += expected ;
32
+ }
33
+ }
34
+ return result . join ( ' ' ) ;
35
+ }
36
+
10
37
function updateAllBlocks ( ) {
11
38
const workspace = Blockly . getMainWorkspace ( ) ;
12
39
if ( workspace ) {
@@ -64,25 +91,18 @@ export default async function ({ addon, console }) {
64
91
`l ${ - 4 * multiplier * notchSize } ${ - 4 * multiplier * notchSize } ` +
65
92
`c -1 ${ - 1 * notchSize } -2 ${ - 2 * notchSize } -4 ${ - 2 * notchSize } `
66
93
67
- BlockSvg . NOTCH_SWITCH_PATH_LEFT =
68
- `c 2 0 3 ${ 1 * notchSize } 4 ${ 2 * notchSize } ` +
69
- `l ${ 4 * multiplier * notchSize } ${ 4 * multiplier * notchSize } ` +
70
- `c 1 ${ 1 * notchSize } 2 ${ 2 * notchSize } 4 ${ 2 * notchSize } ` +
71
- `c ${ 4 * ( multiplier - 0.5 ) } 0 ${ 8 * ( multiplier - 0.5 ) } ${ - 8 * ( multiplier - 0.5 ) * notchSize } ${ 12 * ( multiplier - 0.5 ) } ${ - 8 * ( multiplier - 0.5 ) * notchSize } ` +
72
- `c ${ 4 * ( multiplier - 0.5 ) } 0 ${ 8 * ( multiplier - 0.5 ) } ${ 8 * ( multiplier - 0.5 ) * notchSize } ${ 12 * ( multiplier - 0.5 ) } ${ 8 * ( multiplier - 0.5 ) * notchSize } ` +
73
- `c 2 0 3 ${ - 1 * notchSize } 4 ${ - 2 * notchSize } ` +
74
- `l ${ 4 * multiplier * notchSize } ${ - 4 * multiplier * notchSize } ` +
75
- `c 1 ${ - 1 * notchSize } 2 ${ - 2 * notchSize } 4 ${ - 2 * notchSize } `
76
- BlockSvg . NOTCH_SWITCH_PATH_RIGHT =
77
- `h ${ ( - 4 * ( cornerSize - 1 ) - 5 * ( 1 - notchSize ) ) } ` +
78
- `c -2 0 -3 ${ 1 * notchSize } -4 ${ 2 * notchSize } ` +
79
- `l ${ - 4 * multiplier * notchSize } ${ 4 * multiplier * notchSize } ` +
80
- `c -1 ${ 1 * notchSize } -2 ${ 2 * notchSize } -4 ${ 2 * notchSize } ` +
81
- `c ${ - 4 * ( multiplier - 0.5 ) } 0 ${ - 8 * ( multiplier - 0.5 ) } ${ - 8 * ( multiplier - 0.5 ) * notchSize } ${ - 12 * ( multiplier - 0.5 ) } ${ - 8 * ( multiplier - 0.5 ) * notchSize } ` +
82
- `c ${ - 4 * ( multiplier - 0.5 ) } 0 ${ - 8 * ( multiplier - 0.5 ) } ${ 8 * ( multiplier - 0.5 ) * notchSize } ${ - 12 * ( multiplier - 0.5 ) } ${ 8 * ( multiplier - 0.5 ) * notchSize } ` +
83
- `c -2 0 -3 ${ - 1 * notchSize } -4 ${ - 2 * notchSize } ` +
84
- `l ${ - 4 * multiplier * notchSize } ${ - 4 * multiplier * notchSize } ` +
85
- `c -1 ${ - 1 * notchSize } -2 ${ - 2 * notchSize } -4 ${ - 2 * notchSize } `
94
+ /* Custom Notch API Support */
95
+ const adjustedNotchSize = notchSize === 1 ? 1 :
96
+ notchSize > 1 ? notchSize - 0.05 : notchSize + 0.05 ;
97
+ BlockSvg . CUSTOM_NOTCHES . forEach ( ( notch ) => {
98
+ if ( ! notch . ogLeft ) notch . ogLeft = notch . left ;
99
+ if ( ! notch . ogRight ) notch . ogRight = notch . right ;
100
+ notch . left = scalePathXY ( notch . ogLeft , adjustedNotchSize , notchSize ) ;
101
+ notch . right = scalePathXY ( notch . ogRight , adjustedNotchSize , notchSize ) ;
102
+ } ) ;
103
+
104
+ /* Custom Shape API Support */
105
+ // TODO here...
86
106
87
107
BlockSvg . INPUT_SHAPE_HEXAGONAL =
88
108
"M " +
0 commit comments