scratch-blocks 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commitlint.config.js +2 -2
- package/dist/main.mjs +1 -2
- package/dist/types/msg/scratch_msgs.d.ts.map +1 -1
- package/dist/types/src/block_reporting.d.ts.map +1 -1
- package/dist/types/src/blocks/colour.d.ts +0 -19
- package/dist/types/src/blocks/colour.d.ts.map +1 -1
- package/dist/types/src/blocks/control.d.ts +0 -19
- package/dist/types/src/blocks/control.d.ts.map +1 -1
- package/dist/types/src/blocks/data.d.ts +0 -19
- package/dist/types/src/blocks/data.d.ts.map +1 -1
- package/dist/types/src/blocks/event.d.ts +0 -19
- package/dist/types/src/blocks/event.d.ts.map +1 -1
- package/dist/types/src/blocks/looks.d.ts +0 -19
- package/dist/types/src/blocks/looks.d.ts.map +1 -1
- package/dist/types/src/blocks/math.d.ts +0 -19
- package/dist/types/src/blocks/math.d.ts.map +1 -1
- package/dist/types/src/blocks/matrix.d.ts +0 -19
- package/dist/types/src/blocks/matrix.d.ts.map +1 -1
- package/dist/types/src/blocks/motion.d.ts +0 -19
- package/dist/types/src/blocks/motion.d.ts.map +1 -1
- package/dist/types/src/blocks/note.d.ts +0 -19
- package/dist/types/src/blocks/note.d.ts.map +1 -1
- package/dist/types/src/blocks/operators.d.ts +0 -19
- package/dist/types/src/blocks/operators.d.ts.map +1 -1
- package/dist/types/src/blocks/procedures.d.ts +6 -9
- package/dist/types/src/blocks/procedures.d.ts.map +1 -1
- package/dist/types/src/blocks/sensing.d.ts +0 -19
- package/dist/types/src/blocks/sensing.d.ts.map +1 -1
- package/dist/types/src/blocks/sound.d.ts +0 -19
- package/dist/types/src/blocks/sound.d.ts.map +1 -1
- package/dist/types/src/blocks/text.d.ts +0 -19
- package/dist/types/src/blocks/text.d.ts.map +1 -1
- package/dist/types/src/blocks/vertical_extensions.d.ts +0 -19
- package/dist/types/src/blocks/vertical_extensions.d.ts.map +1 -1
- package/dist/types/src/checkable_continuous_flyout.d.ts +2 -7
- package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
- package/dist/types/src/checkbox_bubble.d.ts +13 -12
- package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
- package/dist/types/src/colours.d.ts.map +1 -1
- package/dist/types/src/constants.d.ts +0 -7
- package/dist/types/src/constants.d.ts.map +1 -1
- package/dist/types/src/context_menu_items.d.ts +0 -5
- package/dist/types/src/context_menu_items.d.ts.map +1 -1
- package/dist/types/src/data_category.d.ts +2 -4
- package/dist/types/src/data_category.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_base.d.ts +2 -3
- package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_change.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_change.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_collapse.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_collapse.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_create.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_create.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_delete.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_delete.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_move.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_move.d.ts.map +1 -1
- package/dist/types/src/events/events_block_comment_resize.d.ts +0 -5
- package/dist/types/src/events/events_block_comment_resize.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_end.d.ts +1 -2
- package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
- package/dist/types/src/events/events_block_drag_outside.d.ts +1 -2
- package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
- package/dist/types/src/events/events_scratch_variable_create.d.ts +0 -5
- package/dist/types/src/events/events_scratch_variable_create.d.ts.map +1 -1
- package/dist/types/src/fields/field_colour_slider.d.ts +3 -27
- package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
- package/dist/types/src/fields/field_matrix.d.ts +0 -19
- package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
- package/dist/types/src/fields/field_note.d.ts +8 -23
- package/dist/types/src/fields/field_note.d.ts.map +1 -1
- package/dist/types/src/fields/field_textinput_removable.d.ts +2 -4
- package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
- package/dist/types/src/fields/field_variable_getter.d.ts +0 -19
- package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
- package/dist/types/src/fields/field_vertical_separator.d.ts +0 -19
- package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_angle.d.ts +0 -19
- package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_dropdown.d.ts +0 -5
- package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_number.d.ts +0 -19
- package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
- package/dist/types/src/fields/scratch_field_variable.d.ts +4 -7
- package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
- package/dist/types/src/flyout_checkbox_icon.d.ts +2 -3
- package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
- package/dist/types/src/glows.d.ts +1 -3
- package/dist/types/src/glows.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +50 -51
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/procedures.d.ts +6 -8
- package/dist/types/src/procedures.d.ts.map +1 -1
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts +3 -5
- package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/renderer/bowler_hat.d.ts +2 -3
- package/dist/types/src/renderer/bowler_hat.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/cat_face.d.ts +6 -5
- package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/constants.d.ts +2 -2
- package/dist/types/src/renderer/cat/constants.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/drawer.d.ts +3 -4
- package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/path_object.d.ts +2 -3
- package/dist/types/src/renderer/cat/path_object.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/render_info.d.ts +3 -4
- package/dist/types/src/renderer/cat/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/cat/renderer.d.ts +6 -7
- package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
- package/dist/types/src/renderer/constants.d.ts +4 -4
- package/dist/types/src/renderer/constants.d.ts.map +1 -1
- package/dist/types/src/renderer/drawer.d.ts +5 -4
- package/dist/types/src/renderer/drawer.d.ts.map +1 -1
- package/dist/types/src/renderer/path_object.d.ts +1 -3
- package/dist/types/src/renderer/path_object.d.ts.map +1 -1
- package/dist/types/src/renderer/render_info.d.ts +3 -4
- package/dist/types/src/renderer/render_info.d.ts.map +1 -1
- package/dist/types/src/renderer/renderer.d.ts +8 -15
- package/dist/types/src/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/scratch_block_paster.d.ts +0 -5
- package/dist/types/src/scratch_block_paster.d.ts.map +1 -1
- package/dist/types/src/scratch_blocks_utils.d.ts +0 -20
- package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_bubble.d.ts +1 -4
- package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
- package/dist/types/src/scratch_comment_icon.d.ts +2 -3
- package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
- package/dist/types/src/scratch_connection_checker.d.ts +0 -5
- package/dist/types/src/scratch_connection_checker.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_category.d.ts +5 -5
- package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
- package/dist/types/src/scratch_continuous_toolbox.d.ts +3 -6
- package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
- package/dist/types/src/scratch_dragger.d.ts +1 -10
- package/dist/types/src/scratch_dragger.d.ts.map +1 -1
- package/dist/types/src/scratch_insertion_marker_previewer.d.ts +0 -5
- package/dist/types/src/scratch_insertion_marker_previewer.d.ts.map +1 -1
- package/dist/types/src/scratch_variable_map.d.ts +0 -5
- package/dist/types/src/scratch_variable_map.d.ts.map +1 -1
- package/dist/types/src/scratch_variable_model.d.ts +1 -2
- package/dist/types/src/scratch_variable_model.d.ts.map +1 -1
- package/dist/types/src/scratch_zoom_controls.d.ts +4 -6
- package/dist/types/src/scratch_zoom_controls.d.ts.map +1 -1
- package/dist/types/src/shadows.d.ts +2 -2
- package/dist/types/src/shadows.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label.d.ts +4 -6
- package/dist/types/src/status_indicator_label.d.ts.map +1 -1
- package/dist/types/src/status_indicator_label_flyout_inflater.d.ts +1 -6
- package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
- package/dist/types/src/variables.d.ts +4 -8
- package/dist/types/src/variables.d.ts.map +1 -1
- package/dist/types/src/xml.d.ts +2 -3
- package/dist/types/src/xml.d.ts.map +1 -1
- package/dist/types/tests/jsunit/block_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/connection_db_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/connection_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/event_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/extensions_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_number_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/field_variable_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/gesture_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/input_test.d.ts +1 -0
- package/dist/types/tests/jsunit/input_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/json_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/names_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/procedure_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/svg_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/test_utilities.d.ts.map +1 -1
- package/dist/types/tests/jsunit/utils_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/variable_map_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/variable_model_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/widget_div_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +1 -1
- package/dist/types/tests/jsunit/xml_test.d.ts.map +1 -1
- package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +1 -1
- package/eslint.config.mjs +69 -0
- package/i18n/create_scratch_msgs.js +44 -45
- package/i18n/js_to_json.js +40 -32
- package/i18n/json_to_js.js +37 -37
- package/i18n/sync_tx_translations.js +64 -65
- package/i18n/test_scratch_msgs.js +66 -63
- package/msg/js/en.js +289 -287
- package/msg/json/en.json +284 -284
- package/msg/messages.js +289 -287
- package/msg/scratch_msgs.js +22959 -22970
- package/package.json +6 -3
- package/prettier.config.mjs +3 -0
- package/release.config.js +7 -7
- package/renovate.json5 +7 -9
- package/src/block_reporting.ts +15 -18
- package/src/blocks/colour.ts +12 -15
- package/src/blocks/control.ts +167 -177
- package/src/blocks/data.ts +225 -292
- package/src/blocks/event.ts +121 -123
- package/src/blocks/looks.ts +165 -167
- package/src/blocks/math.ts +44 -46
- package/src/blocks/matrix.ts +11 -13
- package/src/blocks/motion.ts +151 -153
- package/src/blocks/note.ts +11 -13
- package/src/blocks/operators.ts +158 -160
- package/src/blocks/procedures.ts +415 -523
- package/src/blocks/sensing.ts +163 -165
- package/src/blocks/sound.ts +58 -60
- package/src/blocks/text.ts +10 -12
- package/src/blocks/vertical_extensions.ts +86 -102
- package/src/checkable_continuous_flyout.ts +25 -42
- package/src/checkbox_bubble.ts +83 -100
- package/src/colours.ts +35 -37
- package/src/constants.ts +22 -29
- package/src/context_menu_items.ts +56 -81
- package/src/css.ts +3 -4
- package/src/data_category.ts +137 -251
- package/src/events/events_block_comment_base.ts +21 -31
- package/src/events/events_block_comment_change.ts +21 -42
- package/src/events/events_block_comment_collapse.ts +22 -43
- package/src/events/events_block_comment_create.ts +29 -46
- package/src/events/events_block_comment_delete.ts +10 -19
- package/src/events/events_block_comment_move.ts +27 -52
- package/src/events/events_block_comment_resize.ts +28 -55
- package/src/events/events_block_drag_end.ts +16 -26
- package/src/events/events_block_drag_outside.ts +12 -22
- package/src/events/events_scratch_variable_create.ts +33 -56
- package/src/fields/field_colour_slider.ts +173 -228
- package/src/fields/field_matrix.ts +200 -269
- package/src/fields/field_note.ts +272 -377
- package/src/fields/field_textinput_removable.ts +25 -40
- package/src/fields/field_variable_getter.ts +26 -31
- package/src/fields/field_vertical_separator.ts +19 -24
- package/src/fields/scratch_field_angle.ts +150 -186
- package/src/fields/scratch_field_dropdown.ts +15 -19
- package/src/fields/scratch_field_number.ts +123 -180
- package/src/fields/scratch_field_variable.ts +54 -75
- package/src/flyout_checkbox_icon.ts +18 -28
- package/src/glows.ts +51 -58
- package/src/index.ts +119 -133
- package/src/procedures.ts +146 -213
- package/src/recyclable_block_flyout_inflater.ts +14 -25
- package/src/renderer/bowler_hat.ts +6 -8
- package/src/renderer/cat/cat_face.ts +98 -99
- package/src/renderer/cat/constants.ts +67 -87
- package/src/renderer/cat/drawer.ts +21 -27
- package/src/renderer/cat/path_object.ts +3 -5
- package/src/renderer/cat/render_info.ts +5 -8
- package/src/renderer/cat/renderer.ts +11 -15
- package/src/renderer/constants.ts +34 -49
- package/src/renderer/drawer.ts +35 -51
- package/src/renderer/path_object.ts +4 -10
- package/src/renderer/render_info.ts +36 -56
- package/src/renderer/renderer.ts +16 -29
- package/src/scratch_block_paster.ts +12 -20
- package/src/scratch_blocks_utils.ts +4 -7
- package/src/scratch_comment_bubble.ts +70 -101
- package/src/scratch_comment_icon.ts +74 -123
- package/src/scratch_connection_checker.ts +7 -17
- package/src/scratch_continuous_category.ts +24 -28
- package/src/scratch_continuous_toolbox.ts +20 -27
- package/src/scratch_dragger.ts +42 -81
- package/src/scratch_insertion_marker_previewer.ts +6 -11
- package/src/scratch_variable_map.ts +5 -12
- package/src/scratch_variable_model.ts +4 -11
- package/src/scratch_zoom_controls.ts +101 -156
- package/src/shadows.ts +32 -37
- package/src/status_indicator_label.ts +54 -67
- package/src/status_indicator_label_flyout_inflater.ts +11 -21
- package/src/variables.ts +89 -138
- package/src/xml.ts +21 -35
- package/tsconfig.json +2 -6
- package/types/continuous-toolbox.d.ts +1 -1
- package/dist/main.mjs.LICENSE.txt +0 -163
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license
|
|
3
2
|
* Visual Blocks Editor
|
|
4
3
|
*
|
|
5
4
|
* Copyright 2016 Massachusetts Institute of Technology
|
|
@@ -17,92 +16,91 @@
|
|
|
17
16
|
* See the License for the specific language governing permissions and
|
|
18
17
|
* limitations under the License.
|
|
19
18
|
*/
|
|
20
|
-
|
|
21
19
|
/**
|
|
22
|
-
* @
|
|
20
|
+
* @file 5x5 matrix input field.
|
|
23
21
|
* Displays an editable 5x5 matrix for controlling LED arrays.
|
|
24
22
|
* @author khanning@gmail.com (Kreg Hanning)
|
|
25
23
|
*/
|
|
26
|
-
import * as Blockly from
|
|
24
|
+
import * as Blockly from 'blockly/core'
|
|
27
25
|
|
|
28
26
|
enum PaintStyle {
|
|
29
|
-
FILL =
|
|
30
|
-
CLEAR =
|
|
27
|
+
FILL = 'fill',
|
|
28
|
+
CLEAR = 'clear',
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
enum LEDState {
|
|
34
|
-
ON =
|
|
35
|
-
OFF =
|
|
32
|
+
ON = '1',
|
|
33
|
+
OFF = '0',
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
37
|
* Class for a matrix field.
|
|
40
38
|
*/
|
|
41
39
|
class FieldMatrix extends Blockly.Field<string> {
|
|
42
|
-
private originalStyle =
|
|
40
|
+
private originalStyle = ''
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
43
|
* Array of SVGElement<rect> for matrix thumbnail image on block field.
|
|
46
44
|
*/
|
|
47
|
-
private ledThumbNodes_: SVGElement[] = []
|
|
45
|
+
private ledThumbNodes_: SVGElement[] = []
|
|
48
46
|
/**
|
|
49
47
|
* Array of SVGElement<rect> for matrix editor in dropdown menu.
|
|
50
48
|
*/
|
|
51
|
-
private ledButtons_: SVGElement[] = []
|
|
49
|
+
private ledButtons_: SVGElement[] = []
|
|
52
50
|
|
|
53
51
|
/**
|
|
54
52
|
* SVGElement for LED matrix in editor.
|
|
55
53
|
*/
|
|
56
|
-
private matrixStage_: SVGElement | null = null
|
|
54
|
+
private matrixStage_: SVGElement | null = null
|
|
57
55
|
|
|
58
56
|
/**
|
|
59
57
|
* SVG image for dropdown arrow.
|
|
60
58
|
*/
|
|
61
|
-
private arrow_: SVGElement | null = null
|
|
59
|
+
private arrow_: SVGElement | null = null
|
|
62
60
|
|
|
63
61
|
/**
|
|
64
62
|
* String indicating matrix paint style.
|
|
65
63
|
* value can be [null, 'fill', 'clear'].
|
|
66
64
|
*/
|
|
67
|
-
private paintStyle_: PaintStyle | null = null
|
|
65
|
+
private paintStyle_: PaintStyle | null = null
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
68
|
* Touch event wrapper.
|
|
71
69
|
* Runs when the field is selected.
|
|
72
70
|
*/
|
|
73
|
-
private mouseDownWrapper_: Blockly.browserEvents.Data | null = null
|
|
71
|
+
private mouseDownWrapper_: Blockly.browserEvents.Data | null = null
|
|
74
72
|
|
|
75
73
|
/**
|
|
76
74
|
* Touch event wrapper.
|
|
77
75
|
* Runs when the clear button editor button is selected.
|
|
78
76
|
*/
|
|
79
|
-
private clearButtonWrapper_: Blockly.browserEvents.Data | null = null
|
|
77
|
+
private clearButtonWrapper_: Blockly.browserEvents.Data | null = null
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
80
|
* Touch event wrapper.
|
|
83
81
|
* Runs when the fill button editor button is selected.
|
|
84
82
|
*/
|
|
85
|
-
private fillButtonWrapper_: Blockly.browserEvents.Data | null = null
|
|
83
|
+
private fillButtonWrapper_: Blockly.browserEvents.Data | null = null
|
|
86
84
|
|
|
87
85
|
/**
|
|
88
86
|
* Touch event wrapper.
|
|
89
87
|
* Runs when the matrix editor is touched.
|
|
90
88
|
*/
|
|
91
|
-
private matrixTouchWrapper_: Blockly.browserEvents.Data | null = null
|
|
89
|
+
private matrixTouchWrapper_: Blockly.browserEvents.Data | null = null
|
|
92
90
|
|
|
93
91
|
/**
|
|
94
92
|
* Touch event wrapper.
|
|
95
93
|
* Runs when the matrix editor touch event moves.
|
|
96
94
|
*/
|
|
97
|
-
private matrixMoveWrapper_: Blockly.browserEvents.Data | null = null
|
|
95
|
+
private matrixMoveWrapper_: Blockly.browserEvents.Data | null = null
|
|
98
96
|
|
|
99
97
|
/**
|
|
100
98
|
* Touch event wrapper.
|
|
101
99
|
* Runs when the matrix editor is released.
|
|
102
100
|
*/
|
|
103
|
-
private matrixReleaseWrapper_: Blockly.browserEvents.Data | null = null
|
|
101
|
+
private matrixReleaseWrapper_: Blockly.browserEvents.Data | null = null
|
|
104
102
|
|
|
105
|
-
SERIALIZABLE = true
|
|
103
|
+
SERIALIZABLE = true
|
|
106
104
|
|
|
107
105
|
/**
|
|
108
106
|
* Construct a FieldMatrix from a JSON arg object.
|
|
@@ -110,78 +108,77 @@ class FieldMatrix extends Blockly.Field<string> {
|
|
|
110
108
|
* @returns The new field instance.
|
|
111
109
|
*/
|
|
112
110
|
static fromJson(options: FieldMatrixConfig): FieldMatrix {
|
|
113
|
-
return new FieldMatrix(options
|
|
111
|
+
return new FieldMatrix(options.matrix)
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
/**
|
|
117
115
|
* Fixed size of the matrix thumbnail in the input field, in px.
|
|
118
116
|
*/
|
|
119
|
-
static readonly THUMBNAIL_SIZE = 26
|
|
117
|
+
static readonly THUMBNAIL_SIZE = 26
|
|
120
118
|
|
|
121
119
|
/**
|
|
122
120
|
* Fixed size of each matrix thumbnail node, in px.
|
|
123
121
|
*/
|
|
124
|
-
static readonly THUMBNAIL_NODE_SIZE = 4
|
|
122
|
+
static readonly THUMBNAIL_NODE_SIZE = 4
|
|
125
123
|
|
|
126
124
|
/**
|
|
127
125
|
* Fixed size of each matrix thumbnail node, in px.
|
|
128
126
|
*/
|
|
129
|
-
static readonly THUMBNAIL_NODE_PAD = 1
|
|
127
|
+
static readonly THUMBNAIL_NODE_PAD = 1
|
|
130
128
|
|
|
131
129
|
/**
|
|
132
130
|
* Fixed size of arrow icon in drop down menu, in px.
|
|
133
131
|
*/
|
|
134
|
-
static readonly ARROW_SIZE = 12
|
|
132
|
+
static readonly ARROW_SIZE = 12
|
|
135
133
|
|
|
136
134
|
/**
|
|
137
135
|
* Fixed size of each button inside the 5x5 matrix, in px.
|
|
138
136
|
*/
|
|
139
|
-
static readonly MATRIX_NODE_SIZE = 18
|
|
137
|
+
static readonly MATRIX_NODE_SIZE = 18
|
|
140
138
|
|
|
141
139
|
/**
|
|
142
140
|
* Fixed corner radius for 5x5 matrix buttons, in px.
|
|
143
141
|
*/
|
|
144
|
-
static readonly MATRIX_NODE_RADIUS = 4
|
|
142
|
+
static readonly MATRIX_NODE_RADIUS = 4
|
|
145
143
|
|
|
146
144
|
/**
|
|
147
145
|
* Fixed padding for 5x5 matrix buttons, in px.
|
|
148
146
|
*/
|
|
149
|
-
static readonly MATRIX_NODE_PAD = 5
|
|
147
|
+
static readonly MATRIX_NODE_PAD = 5
|
|
150
148
|
|
|
151
149
|
/**
|
|
152
150
|
* String with 25 '0' chars.
|
|
153
151
|
* Used for clearing a matrix or filling an LED node array.
|
|
154
152
|
*/
|
|
155
|
-
static readonly ZEROS =
|
|
153
|
+
static readonly ZEROS = '0000000000000000000000000'
|
|
156
154
|
|
|
157
155
|
/**
|
|
158
156
|
* String with 25 '1' chars.
|
|
159
157
|
* Used for filling a matrix.
|
|
160
158
|
*/
|
|
161
|
-
static readonly ONES =
|
|
159
|
+
static readonly ONES = '1111111111111111111111111'
|
|
162
160
|
|
|
163
161
|
/**
|
|
164
162
|
* Called when the field is placed on a block.
|
|
165
163
|
*/
|
|
166
164
|
initView() {
|
|
167
165
|
// Build the DOM.
|
|
168
|
-
this.updateSize_()
|
|
169
|
-
const dropdownArrowPadding =
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
const thumbY = (this.size_.height - FieldMatrix.THUMBNAIL_SIZE) / 2;
|
|
166
|
+
this.updateSize_()
|
|
167
|
+
const dropdownArrowPadding = (this.getConstants() as Blockly.zelos.ConstantProvider).GRID_UNIT * 2
|
|
168
|
+
const thumbX = dropdownArrowPadding / 2
|
|
169
|
+
const thumbY = (this.size_.height - FieldMatrix.THUMBNAIL_SIZE) / 2
|
|
173
170
|
const thumbnail = Blockly.utils.dom.createSvgElement(
|
|
174
|
-
|
|
171
|
+
'g',
|
|
175
172
|
{
|
|
176
|
-
transform:
|
|
177
|
-
|
|
178
|
-
cursor:
|
|
173
|
+
transform: 'translate(' + thumbX + ', ' + thumbY + ')',
|
|
174
|
+
'pointer-events': 'bounding-box',
|
|
175
|
+
cursor: 'pointer',
|
|
179
176
|
},
|
|
180
|
-
this.fieldGroup_
|
|
181
|
-
)
|
|
182
|
-
this.ledThumbNodes_ = []
|
|
183
|
-
const nodeSize = FieldMatrix.THUMBNAIL_NODE_SIZE
|
|
184
|
-
const nodePad = FieldMatrix.THUMBNAIL_NODE_PAD
|
|
177
|
+
this.fieldGroup_,
|
|
178
|
+
)
|
|
179
|
+
this.ledThumbNodes_ = []
|
|
180
|
+
const nodeSize = FieldMatrix.THUMBNAIL_NODE_SIZE
|
|
181
|
+
const nodePad = FieldMatrix.THUMBNAIL_NODE_PAD
|
|
185
182
|
for (let i = 0; i < 5; i++) {
|
|
186
183
|
for (let n = 0; n < 5; n++) {
|
|
187
184
|
const attr = {
|
|
@@ -191,46 +188,42 @@ class FieldMatrix extends Blockly.Field<string> {
|
|
|
191
188
|
height: nodeSize,
|
|
192
189
|
rx: nodePad,
|
|
193
190
|
ry: nodePad,
|
|
194
|
-
}
|
|
195
|
-
this.ledThumbNodes_.push(
|
|
196
|
-
Blockly.utils.dom.createSvgElement("rect", attr, thumbnail)
|
|
197
|
-
);
|
|
191
|
+
}
|
|
192
|
+
this.ledThumbNodes_.push(Blockly.utils.dom.createSvgElement('rect', attr, thumbnail))
|
|
198
193
|
}
|
|
199
|
-
thumbnail.style.cursor =
|
|
200
|
-
this.updateMatrix_()
|
|
194
|
+
thumbnail.style.cursor = 'default'
|
|
195
|
+
this.updateMatrix_()
|
|
201
196
|
}
|
|
202
197
|
|
|
203
198
|
if (!this.arrow_) {
|
|
204
|
-
const arrowX = FieldMatrix.THUMBNAIL_SIZE + dropdownArrowPadding * 1.5
|
|
205
|
-
const arrowY = (this.size_.height - FieldMatrix.ARROW_SIZE) / 2
|
|
199
|
+
const arrowX = FieldMatrix.THUMBNAIL_SIZE + dropdownArrowPadding * 1.5
|
|
200
|
+
const arrowY = (this.size_.height - FieldMatrix.ARROW_SIZE) / 2
|
|
206
201
|
this.arrow_ = Blockly.utils.dom.createSvgElement(
|
|
207
|
-
|
|
202
|
+
'image',
|
|
208
203
|
{
|
|
209
|
-
height: FieldMatrix.ARROW_SIZE +
|
|
210
|
-
width: FieldMatrix.ARROW_SIZE +
|
|
211
|
-
transform:
|
|
204
|
+
height: FieldMatrix.ARROW_SIZE + 'px',
|
|
205
|
+
width: FieldMatrix.ARROW_SIZE + 'px',
|
|
206
|
+
transform: 'translate(' + arrowX + ', ' + arrowY + ')',
|
|
212
207
|
},
|
|
213
|
-
this.fieldGroup_
|
|
214
|
-
)
|
|
208
|
+
this.fieldGroup_,
|
|
209
|
+
)
|
|
215
210
|
this.arrow_.setAttributeNS(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_DATAURI
|
|
219
|
-
)
|
|
220
|
-
this.arrow_.style.cursor =
|
|
211
|
+
'http://www.w3.org/1999/xlink',
|
|
212
|
+
'xlink:href',
|
|
213
|
+
this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_DATAURI,
|
|
214
|
+
)
|
|
215
|
+
this.arrow_.style.cursor = 'default'
|
|
221
216
|
}
|
|
222
217
|
}
|
|
223
218
|
|
|
224
219
|
doClassValidation_(matrix: string) {
|
|
225
|
-
return matrix
|
|
226
|
-
? matrix + FieldMatrix.ZEROS.substr(0, 25 - matrix.length)
|
|
227
|
-
: matrix;
|
|
220
|
+
return matrix ? matrix + FieldMatrix.ZEROS.substr(0, 25 - matrix.length) : matrix
|
|
228
221
|
}
|
|
229
222
|
|
|
230
223
|
doValueUpdate_(newValue: string) {
|
|
231
|
-
super.doValueUpdate_(newValue)
|
|
224
|
+
super.doValueUpdate_(newValue)
|
|
232
225
|
if (newValue) {
|
|
233
|
-
this.updateMatrix_()
|
|
226
|
+
this.updateMatrix_()
|
|
234
227
|
}
|
|
235
228
|
}
|
|
236
229
|
|
|
@@ -238,144 +231,110 @@ class FieldMatrix extends Blockly.Field<string> {
|
|
|
238
231
|
* Show the drop-down menu for editing this field.
|
|
239
232
|
*/
|
|
240
233
|
showEditor_() {
|
|
241
|
-
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
242
|
-
Blockly.DropDownDiv.setColour(
|
|
243
|
-
sourceBlock.getColour(),
|
|
244
|
-
sourceBlock.getColourTertiary()
|
|
245
|
-
);
|
|
234
|
+
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|
|
235
|
+
Blockly.DropDownDiv.setColour(sourceBlock.getColour(), sourceBlock.getColourTertiary())
|
|
246
236
|
|
|
247
|
-
const style = sourceBlock.style
|
|
237
|
+
const style = sourceBlock.style
|
|
248
238
|
if (sourceBlock.isShadow()) {
|
|
249
|
-
this.originalStyle = sourceBlock.getStyleName()
|
|
250
|
-
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
239
|
+
this.originalStyle = sourceBlock.getStyleName()
|
|
240
|
+
sourceBlock.setStyle(`${this.originalStyle}_selected`)
|
|
251
241
|
} else if (this.borderRect_) {
|
|
252
242
|
this.borderRect_.setAttribute(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
: style.colourTertiary
|
|
257
|
-
);
|
|
243
|
+
'fill',
|
|
244
|
+
'colourQuaternary' in style ? `${style.colourQuaternary}` : style.colourTertiary,
|
|
245
|
+
)
|
|
258
246
|
}
|
|
259
247
|
|
|
260
|
-
const div = Blockly.DropDownDiv.getContentDiv()
|
|
248
|
+
const div = Blockly.DropDownDiv.getContentDiv()
|
|
261
249
|
// Build the SVG DOM.
|
|
262
|
-
const matrixSize =
|
|
263
|
-
FieldMatrix.MATRIX_NODE_SIZE * 5 + FieldMatrix.MATRIX_NODE_PAD * 6;
|
|
250
|
+
const matrixSize = FieldMatrix.MATRIX_NODE_SIZE * 5 + FieldMatrix.MATRIX_NODE_PAD * 6
|
|
264
251
|
this.matrixStage_ = Blockly.utils.dom.createSvgElement(
|
|
265
|
-
|
|
252
|
+
'svg',
|
|
266
253
|
{
|
|
267
|
-
xmlns:
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
version:
|
|
271
|
-
height: matrixSize +
|
|
272
|
-
width: matrixSize +
|
|
254
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
255
|
+
'xmlns:html': 'http://www.w3.org/1999/xhtml',
|
|
256
|
+
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
|
257
|
+
version: '1.1',
|
|
258
|
+
height: matrixSize + 'px',
|
|
259
|
+
width: matrixSize + 'px',
|
|
273
260
|
},
|
|
274
|
-
div
|
|
275
|
-
)
|
|
261
|
+
div,
|
|
262
|
+
)
|
|
276
263
|
// Create the 5x5 matrix
|
|
277
|
-
this.ledButtons_ = []
|
|
264
|
+
this.ledButtons_ = []
|
|
278
265
|
for (let i = 0; i < 5; i++) {
|
|
279
266
|
for (let n = 0; n < 5; n++) {
|
|
280
|
-
const x =
|
|
281
|
-
|
|
282
|
-
FieldMatrix.MATRIX_NODE_PAD * (n + 1);
|
|
283
|
-
const y =
|
|
284
|
-
FieldMatrix.MATRIX_NODE_SIZE * i +
|
|
285
|
-
FieldMatrix.MATRIX_NODE_PAD * (i + 1);
|
|
267
|
+
const x = FieldMatrix.MATRIX_NODE_SIZE * n + FieldMatrix.MATRIX_NODE_PAD * (n + 1)
|
|
268
|
+
const y = FieldMatrix.MATRIX_NODE_SIZE * i + FieldMatrix.MATRIX_NODE_PAD * (i + 1)
|
|
286
269
|
const attr = {
|
|
287
|
-
x: x +
|
|
288
|
-
y: y +
|
|
270
|
+
x: x + 'px',
|
|
271
|
+
y: y + 'px',
|
|
289
272
|
width: FieldMatrix.MATRIX_NODE_SIZE,
|
|
290
273
|
height: FieldMatrix.MATRIX_NODE_SIZE,
|
|
291
274
|
rx: FieldMatrix.MATRIX_NODE_RADIUS,
|
|
292
275
|
ry: FieldMatrix.MATRIX_NODE_RADIUS,
|
|
293
|
-
}
|
|
294
|
-
const led = Blockly.utils.dom.createSvgElement(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this.matrixStage_
|
|
298
|
-
);
|
|
299
|
-
this.matrixStage_.appendChild(led);
|
|
300
|
-
this.ledButtons_.push(led);
|
|
276
|
+
}
|
|
277
|
+
const led = Blockly.utils.dom.createSvgElement('rect', attr, this.matrixStage_)
|
|
278
|
+
this.matrixStage_.appendChild(led)
|
|
279
|
+
this.ledButtons_.push(led)
|
|
301
280
|
}
|
|
302
281
|
}
|
|
303
282
|
// Div for lower button menu
|
|
304
|
-
const buttonDiv = document.createElement(
|
|
283
|
+
const buttonDiv = document.createElement('div')
|
|
305
284
|
// Button to clear matrix
|
|
306
|
-
const clearButtonDiv = document.createElement(
|
|
307
|
-
clearButtonDiv.className =
|
|
285
|
+
const clearButtonDiv = document.createElement('div')
|
|
286
|
+
clearButtonDiv.className = 'scratchMatrixButtonDiv'
|
|
308
287
|
|
|
309
|
-
const clearButton = this.createButton_(sourceBlock.getColourSecondary())
|
|
310
|
-
clearButtonDiv.appendChild(clearButton)
|
|
288
|
+
const clearButton = this.createButton_(sourceBlock.getColourSecondary())
|
|
289
|
+
clearButtonDiv.appendChild(clearButton)
|
|
311
290
|
// Button to fill matrix
|
|
312
|
-
const fillButtonDiv = document.createElement(
|
|
313
|
-
fillButtonDiv.className =
|
|
314
|
-
const fillButton = this.createButton_(
|
|
315
|
-
fillButtonDiv.appendChild(fillButton)
|
|
316
|
-
|
|
317
|
-
buttonDiv.appendChild(clearButtonDiv)
|
|
318
|
-
buttonDiv.appendChild(fillButtonDiv)
|
|
319
|
-
div.appendChild(buttonDiv)
|
|
320
|
-
|
|
321
|
-
Blockly.DropDownDiv.showPositionedByBlock(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
this.matrixTouchWrapper_ = Blockly.browserEvents.bind(
|
|
328
|
-
this.matrixStage_,
|
|
329
|
-
"mousedown",
|
|
330
|
-
this,
|
|
331
|
-
this.onMouseDown
|
|
332
|
-
);
|
|
333
|
-
this.clearButtonWrapper_ = Blockly.browserEvents.bind(
|
|
334
|
-
clearButton,
|
|
335
|
-
"click",
|
|
336
|
-
this,
|
|
337
|
-
this.clearMatrix_
|
|
338
|
-
);
|
|
339
|
-
this.fillButtonWrapper_ = Blockly.browserEvents.bind(
|
|
340
|
-
fillButton,
|
|
341
|
-
"click",
|
|
342
|
-
this,
|
|
343
|
-
this.fillMatrix_
|
|
344
|
-
);
|
|
291
|
+
const fillButtonDiv = document.createElement('div')
|
|
292
|
+
fillButtonDiv.className = 'scratchMatrixButtonDiv'
|
|
293
|
+
const fillButton = this.createButton_('var(--colour-text)')
|
|
294
|
+
fillButtonDiv.appendChild(fillButton)
|
|
295
|
+
|
|
296
|
+
buttonDiv.appendChild(clearButtonDiv)
|
|
297
|
+
buttonDiv.appendChild(fillButtonDiv)
|
|
298
|
+
div.appendChild(buttonDiv)
|
|
299
|
+
|
|
300
|
+
Blockly.DropDownDiv.showPositionedByBlock(this, sourceBlock, this.dropdownDispose_.bind(this))
|
|
301
|
+
|
|
302
|
+
this.matrixTouchWrapper_ = Blockly.browserEvents.bind(this.matrixStage_, 'mousedown', this, this.onMouseDown)
|
|
303
|
+
this.clearButtonWrapper_ = Blockly.browserEvents.bind(clearButton, 'click', this, this.clearMatrix_)
|
|
304
|
+
this.fillButtonWrapper_ = Blockly.browserEvents.bind(fillButton, 'click', this, this.fillMatrix_)
|
|
345
305
|
|
|
346
306
|
// Update the matrix for the current value
|
|
347
|
-
this.updateMatrix_()
|
|
307
|
+
this.updateMatrix_()
|
|
348
308
|
}
|
|
349
309
|
|
|
350
310
|
dropdownDispose_() {
|
|
351
|
-
const sourceBlock = this.getSourceBlock()
|
|
311
|
+
const sourceBlock = this.getSourceBlock()!
|
|
352
312
|
if (sourceBlock.isShadow()) {
|
|
353
|
-
sourceBlock.setStyle(this.originalStyle)
|
|
313
|
+
sourceBlock.setStyle(this.originalStyle)
|
|
354
314
|
}
|
|
355
|
-
this.updateMatrix_()
|
|
315
|
+
this.updateMatrix_()
|
|
356
316
|
}
|
|
357
317
|
|
|
358
318
|
/**
|
|
359
319
|
* Make an svg object that resembles a 3x3 matrix to be used as a button.
|
|
360
|
-
*
|
|
361
320
|
* @param fill The color to fill the matrix nodes.
|
|
362
321
|
* @returns The button svg element.
|
|
363
322
|
*/
|
|
364
323
|
createButton_(fill: string): SVGElement {
|
|
365
|
-
const button = Blockly.utils.dom.createSvgElement(
|
|
366
|
-
xmlns:
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
version:
|
|
370
|
-
height: FieldMatrix.MATRIX_NODE_SIZE +
|
|
371
|
-
width: FieldMatrix.MATRIX_NODE_SIZE +
|
|
372
|
-
})
|
|
373
|
-
const nodeSize = FieldMatrix.MATRIX_NODE_SIZE / 4
|
|
374
|
-
const nodePad = FieldMatrix.MATRIX_NODE_SIZE / 16
|
|
324
|
+
const button = Blockly.utils.dom.createSvgElement('svg', {
|
|
325
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
326
|
+
'xmlns:html': 'http://www.w3.org/1999/xhtml',
|
|
327
|
+
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
|
328
|
+
version: '1.1',
|
|
329
|
+
height: FieldMatrix.MATRIX_NODE_SIZE + 'px',
|
|
330
|
+
width: FieldMatrix.MATRIX_NODE_SIZE + 'px',
|
|
331
|
+
})
|
|
332
|
+
const nodeSize = FieldMatrix.MATRIX_NODE_SIZE / 4
|
|
333
|
+
const nodePad = FieldMatrix.MATRIX_NODE_SIZE / 16
|
|
375
334
|
for (let i = 0; i < 3; i++) {
|
|
376
335
|
for (let n = 0; n < 3; n++) {
|
|
377
336
|
Blockly.utils.dom.createSvgElement(
|
|
378
|
-
|
|
337
|
+
'rect',
|
|
379
338
|
{
|
|
380
339
|
x: (nodeSize + nodePad) * n + nodePad,
|
|
381
340
|
y: (nodeSize + nodePad) * i + nodePad,
|
|
@@ -385,126 +344,103 @@ class FieldMatrix extends Blockly.Field<string> {
|
|
|
385
344
|
ry: nodePad,
|
|
386
345
|
fill: fill,
|
|
387
346
|
},
|
|
388
|
-
button
|
|
389
|
-
)
|
|
347
|
+
button,
|
|
348
|
+
)
|
|
390
349
|
}
|
|
391
350
|
}
|
|
392
|
-
return button
|
|
351
|
+
return button
|
|
393
352
|
}
|
|
394
353
|
|
|
395
354
|
/**
|
|
396
355
|
* Redraw the matrix with the current value.
|
|
397
356
|
*/
|
|
398
357
|
private updateMatrix_() {
|
|
399
|
-
const matrix = this.getValue()
|
|
400
|
-
const sourceBlock = this.getSourceBlock()! as Blockly.BlockSvg
|
|
358
|
+
const matrix = this.getValue()!
|
|
359
|
+
const sourceBlock = this.getSourceBlock()! as Blockly.BlockSvg
|
|
401
360
|
for (let i = 0; i < matrix.length; i++) {
|
|
402
361
|
if (matrix[i] === LEDState.OFF) {
|
|
403
|
-
this.fillMatrixNode_(
|
|
404
|
-
|
|
405
|
-
i,
|
|
406
|
-
sourceBlock.getColourTertiary()
|
|
407
|
-
);
|
|
408
|
-
this.fillMatrixNode_(
|
|
409
|
-
this.ledThumbNodes_,
|
|
410
|
-
i,
|
|
411
|
-
sourceBlock.getColourSecondary()
|
|
412
|
-
);
|
|
362
|
+
this.fillMatrixNode_(this.ledButtons_, i, sourceBlock.getColourTertiary())
|
|
363
|
+
this.fillMatrixNode_(this.ledThumbNodes_, i, sourceBlock.getColourSecondary())
|
|
413
364
|
} else {
|
|
414
|
-
this.fillMatrixNode_(this.ledButtons_, i,
|
|
415
|
-
this.fillMatrixNode_(this.ledThumbNodes_, i,
|
|
365
|
+
this.fillMatrixNode_(this.ledButtons_, i, 'var(--colour-text)')
|
|
366
|
+
this.fillMatrixNode_(this.ledThumbNodes_, i, 'var(--colour-text)')
|
|
416
367
|
}
|
|
417
368
|
}
|
|
418
369
|
}
|
|
419
370
|
|
|
420
371
|
/**
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
* @param e Mouse event.
|
|
372
|
+
* Resets all LED values to zero.
|
|
373
|
+
* @param e Checked to allow only left-button clicks (button 0).
|
|
424
374
|
*/
|
|
425
375
|
clearMatrix_(e: PointerEvent) {
|
|
426
|
-
if (e.button != 0) return
|
|
427
|
-
this.setValue(FieldMatrix.ZEROS)
|
|
376
|
+
if (e.button != 0) return
|
|
377
|
+
this.setValue(FieldMatrix.ZEROS)
|
|
428
378
|
}
|
|
429
379
|
|
|
430
380
|
/**
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
* @param e Mouse event.
|
|
381
|
+
* Sets all LED values to one.
|
|
382
|
+
* @param e Checked to allow only left-button clicks (button 0).
|
|
434
383
|
*/
|
|
435
384
|
fillMatrix_(e: PointerEvent) {
|
|
436
|
-
if (e.button != 0) return
|
|
437
|
-
this.setValue(FieldMatrix.ONES)
|
|
385
|
+
if (e.button != 0) return
|
|
386
|
+
this.setValue(FieldMatrix.ONES)
|
|
438
387
|
}
|
|
439
388
|
|
|
440
389
|
/**
|
|
441
390
|
* Fill matrix node with specified colour.
|
|
442
|
-
*
|
|
443
391
|
* @param node The array of matrix nodes.
|
|
444
392
|
* @param index The index of the matrix node.
|
|
445
393
|
* @param fill The fill colour in '#rrggbb' format.
|
|
446
394
|
*/
|
|
447
395
|
fillMatrixNode_(node: SVGElement[], index: number, fill: string) {
|
|
448
|
-
if (!node
|
|
449
|
-
node[index].setAttribute(
|
|
396
|
+
if (!node?.[index] || !fill) return
|
|
397
|
+
node[index].setAttribute('fill', fill)
|
|
450
398
|
}
|
|
451
399
|
|
|
452
400
|
setLEDNode_(led: number, state: LEDState) {
|
|
453
|
-
if (led < 0 || led > 24) return
|
|
454
|
-
const oldMatrix = this.getValue()
|
|
455
|
-
const newMatrix =
|
|
456
|
-
|
|
457
|
-
this.setValue(newMatrix);
|
|
401
|
+
if (led < 0 || led > 24) return
|
|
402
|
+
const oldMatrix = this.getValue()!
|
|
403
|
+
const newMatrix = oldMatrix.substr(0, led) + state + oldMatrix.substr(led + 1)
|
|
404
|
+
this.setValue(newMatrix)
|
|
458
405
|
}
|
|
459
406
|
|
|
460
407
|
fillLEDNode_(led: number) {
|
|
461
|
-
if (led < 0 || led > 24) return
|
|
462
|
-
this.setLEDNode_(led, LEDState.ON)
|
|
408
|
+
if (led < 0 || led > 24) return
|
|
409
|
+
this.setLEDNode_(led, LEDState.ON)
|
|
463
410
|
}
|
|
464
411
|
|
|
465
412
|
clearLEDNode_(led: number) {
|
|
466
|
-
if (led < 0 || led > 24) return
|
|
467
|
-
this.setLEDNode_(led, LEDState.OFF)
|
|
413
|
+
if (led < 0 || led > 24) return
|
|
414
|
+
this.setLEDNode_(led, LEDState.OFF)
|
|
468
415
|
}
|
|
469
416
|
|
|
470
417
|
toggleLEDNode_(led: number) {
|
|
471
|
-
if (led < 0 || led > 24) return
|
|
418
|
+
if (led < 0 || led > 24) return
|
|
472
419
|
if (this.getValue()!.charAt(led) === LEDState.OFF) {
|
|
473
|
-
this.setLEDNode_(led, LEDState.ON)
|
|
420
|
+
this.setLEDNode_(led, LEDState.ON)
|
|
474
421
|
} else {
|
|
475
|
-
this.setLEDNode_(led, LEDState.OFF)
|
|
422
|
+
this.setLEDNode_(led, LEDState.OFF)
|
|
476
423
|
}
|
|
477
424
|
}
|
|
478
425
|
|
|
479
426
|
/**
|
|
480
427
|
* Toggle matrix nodes on and off.
|
|
481
|
-
*
|
|
482
428
|
* @param e Mouse event.
|
|
483
429
|
*/
|
|
484
430
|
onMouseDown(e: PointerEvent) {
|
|
485
|
-
this.matrixMoveWrapper_ = Blockly.browserEvents.bind(
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
this,
|
|
489
|
-
this.onMouseMove
|
|
490
|
-
);
|
|
491
|
-
this.matrixReleaseWrapper_ = Blockly.browserEvents.bind(
|
|
492
|
-
document.body,
|
|
493
|
-
"mouseup",
|
|
494
|
-
this,
|
|
495
|
-
this.onMouseUp
|
|
496
|
-
);
|
|
497
|
-
const ledHit = this.checkForLED_(e);
|
|
431
|
+
this.matrixMoveWrapper_ = Blockly.browserEvents.bind(document.body, 'mousemove', this, this.onMouseMove)
|
|
432
|
+
this.matrixReleaseWrapper_ = Blockly.browserEvents.bind(document.body, 'mouseup', this, this.onMouseUp)
|
|
433
|
+
const ledHit = this.checkForLED_(e)
|
|
498
434
|
if (ledHit > -1) {
|
|
499
435
|
if (this.getValue()!.charAt(ledHit) === LEDState.OFF) {
|
|
500
|
-
this.paintStyle_ = PaintStyle.FILL
|
|
436
|
+
this.paintStyle_ = PaintStyle.FILL
|
|
501
437
|
} else {
|
|
502
|
-
this.paintStyle_ = PaintStyle.CLEAR
|
|
438
|
+
this.paintStyle_ = PaintStyle.CLEAR
|
|
503
439
|
}
|
|
504
|
-
this.toggleLEDNode_(ledHit)
|
|
505
|
-
this.updateMatrix_()
|
|
440
|
+
this.toggleLEDNode_(ledHit)
|
|
441
|
+
this.updateMatrix_()
|
|
506
442
|
} else {
|
|
507
|
-
this.paintStyle_ = null
|
|
443
|
+
this.paintStyle_ = null
|
|
508
444
|
}
|
|
509
445
|
}
|
|
510
446
|
|
|
@@ -513,108 +449,103 @@ class FieldMatrix extends Blockly.Field<string> {
|
|
|
513
449
|
*/
|
|
514
450
|
onMouseUp() {
|
|
515
451
|
if (this.matrixMoveWrapper_) {
|
|
516
|
-
Blockly.browserEvents.unbind(this.matrixMoveWrapper_)
|
|
517
|
-
this.matrixMoveWrapper_ = null
|
|
452
|
+
Blockly.browserEvents.unbind(this.matrixMoveWrapper_)
|
|
453
|
+
this.matrixMoveWrapper_ = null
|
|
518
454
|
}
|
|
519
455
|
if (this.matrixReleaseWrapper_) {
|
|
520
|
-
Blockly.browserEvents.unbind(this.matrixReleaseWrapper_)
|
|
521
|
-
this.matrixReleaseWrapper_ = null
|
|
456
|
+
Blockly.browserEvents.unbind(this.matrixReleaseWrapper_)
|
|
457
|
+
this.matrixReleaseWrapper_ = null
|
|
522
458
|
}
|
|
523
|
-
this.paintStyle_ = null
|
|
459
|
+
this.paintStyle_ = null
|
|
524
460
|
}
|
|
525
461
|
|
|
526
462
|
/**
|
|
527
463
|
* Toggle matrix nodes on and off by dragging mouse.
|
|
528
|
-
*
|
|
529
464
|
* @param e Mouse move event.
|
|
530
465
|
*/
|
|
531
466
|
onMouseMove(e: PointerEvent) {
|
|
532
|
-
e.preventDefault()
|
|
467
|
+
e.preventDefault()
|
|
533
468
|
if (this.paintStyle_) {
|
|
534
|
-
const led = this.checkForLED_(e)
|
|
535
|
-
if (led < 0) return
|
|
469
|
+
const led = this.checkForLED_(e)
|
|
470
|
+
if (led < 0) return
|
|
536
471
|
if (this.paintStyle_ === PaintStyle.CLEAR) {
|
|
537
|
-
this.clearLEDNode_(led)
|
|
472
|
+
this.clearLEDNode_(led)
|
|
538
473
|
} else if (this.paintStyle_ === PaintStyle.FILL) {
|
|
539
|
-
this.fillLEDNode_(led)
|
|
474
|
+
this.fillLEDNode_(led)
|
|
540
475
|
}
|
|
541
476
|
}
|
|
542
477
|
}
|
|
543
478
|
|
|
544
479
|
/**
|
|
545
480
|
* Check if mouse coordinates collide with a matrix node.
|
|
546
|
-
*
|
|
547
481
|
* @param e Mouse move event.
|
|
548
482
|
* @returns The matching matrix node or -1 for none.
|
|
549
483
|
*/
|
|
550
484
|
checkForLED_(e: PointerEvent): number {
|
|
551
|
-
if (!this.matrixStage_) return -1
|
|
552
|
-
const bBox = this.matrixStage_.getBoundingClientRect()
|
|
553
|
-
const nodeSize = FieldMatrix.MATRIX_NODE_SIZE
|
|
554
|
-
const nodePad = FieldMatrix.MATRIX_NODE_PAD
|
|
555
|
-
const dx = e.clientX - bBox.left
|
|
556
|
-
const dy = e.clientY - bBox.top
|
|
557
|
-
const min = nodePad / 2
|
|
558
|
-
const max = bBox.width - nodePad / 2
|
|
485
|
+
if (!this.matrixStage_) return -1
|
|
486
|
+
const bBox = this.matrixStage_.getBoundingClientRect()
|
|
487
|
+
const nodeSize = FieldMatrix.MATRIX_NODE_SIZE
|
|
488
|
+
const nodePad = FieldMatrix.MATRIX_NODE_PAD
|
|
489
|
+
const dx = e.clientX - bBox.left
|
|
490
|
+
const dy = e.clientY - bBox.top
|
|
491
|
+
const min = nodePad / 2
|
|
492
|
+
const max = bBox.width - nodePad / 2
|
|
559
493
|
if (dx < min || dx > max || dy < min || dy > max) {
|
|
560
|
-
return -1
|
|
494
|
+
return -1
|
|
561
495
|
}
|
|
562
|
-
const xDiv = Math.trunc((dx - nodePad / 2) / (nodeSize + nodePad))
|
|
563
|
-
const yDiv = Math.trunc((dy - nodePad / 2) / (nodeSize + nodePad))
|
|
564
|
-
return xDiv + yDiv * nodePad
|
|
496
|
+
const xDiv = Math.trunc((dx - nodePad / 2) / (nodeSize + nodePad))
|
|
497
|
+
const yDiv = Math.trunc((dy - nodePad / 2) / (nodeSize + nodePad))
|
|
498
|
+
return xDiv + yDiv * nodePad
|
|
565
499
|
}
|
|
566
500
|
|
|
567
501
|
/**
|
|
568
502
|
* Clean up this FieldMatrix, as well as the inherited Field.
|
|
569
503
|
*/
|
|
570
504
|
dispose() {
|
|
571
|
-
super.dispose()
|
|
572
|
-
this.matrixStage_ = null
|
|
505
|
+
super.dispose()
|
|
506
|
+
this.matrixStage_ = null
|
|
573
507
|
if (this.mouseDownWrapper_) {
|
|
574
|
-
Blockly.browserEvents.unbind(this.mouseDownWrapper_)
|
|
508
|
+
Blockly.browserEvents.unbind(this.mouseDownWrapper_)
|
|
575
509
|
}
|
|
576
510
|
if (this.matrixTouchWrapper_) {
|
|
577
|
-
Blockly.browserEvents.unbind(this.matrixTouchWrapper_)
|
|
511
|
+
Blockly.browserEvents.unbind(this.matrixTouchWrapper_)
|
|
578
512
|
}
|
|
579
513
|
if (this.matrixReleaseWrapper_) {
|
|
580
|
-
Blockly.browserEvents.unbind(this.matrixReleaseWrapper_)
|
|
514
|
+
Blockly.browserEvents.unbind(this.matrixReleaseWrapper_)
|
|
581
515
|
}
|
|
582
516
|
if (this.matrixMoveWrapper_) {
|
|
583
|
-
Blockly.browserEvents.unbind(this.matrixMoveWrapper_)
|
|
517
|
+
Blockly.browserEvents.unbind(this.matrixMoveWrapper_)
|
|
584
518
|
}
|
|
585
519
|
if (this.clearButtonWrapper_) {
|
|
586
|
-
Blockly.browserEvents.unbind(this.clearButtonWrapper_)
|
|
520
|
+
Blockly.browserEvents.unbind(this.clearButtonWrapper_)
|
|
587
521
|
}
|
|
588
522
|
if (this.fillButtonWrapper_) {
|
|
589
|
-
Blockly.browserEvents.unbind(this.fillButtonWrapper_)
|
|
523
|
+
Blockly.browserEvents.unbind(this.fillButtonWrapper_)
|
|
590
524
|
}
|
|
591
525
|
}
|
|
592
526
|
|
|
593
527
|
updateSize_() {
|
|
594
|
-
const constants = this.getConstants() as Blockly.zelos.ConstantProvider
|
|
595
|
-
|
|
528
|
+
const constants = this.getConstants() as Blockly.zelos.ConstantProvider
|
|
529
|
+
const totalHeight = constants.FIELD_TEXT_HEIGHT
|
|
596
530
|
|
|
597
|
-
this.size_.height = totalHeight
|
|
598
|
-
this.size_.width =
|
|
599
|
-
FieldMatrix.THUMBNAIL_SIZE +
|
|
600
|
-
FieldMatrix.ARROW_SIZE +
|
|
601
|
-
constants.GRID_UNIT * 2 * 1.5;
|
|
531
|
+
this.size_.height = totalHeight
|
|
532
|
+
this.size_.width = FieldMatrix.THUMBNAIL_SIZE + FieldMatrix.ARROW_SIZE + constants.GRID_UNIT * 2 * 1.5
|
|
602
533
|
|
|
603
|
-
this.positionBorderRect_()
|
|
534
|
+
this.positionBorderRect_()
|
|
604
535
|
}
|
|
605
536
|
|
|
606
537
|
getClickTarget_() {
|
|
607
|
-
return (this.getSourceBlock() as Blockly.BlockSvg).getSvgRoot()
|
|
538
|
+
return (this.getSourceBlock() as Blockly.BlockSvg).getSvgRoot()
|
|
608
539
|
}
|
|
609
540
|
}
|
|
610
541
|
|
|
611
542
|
interface FieldMatrixConfig extends Blockly.FieldConfig {
|
|
612
|
-
matrix: string
|
|
543
|
+
matrix: string
|
|
613
544
|
}
|
|
614
545
|
|
|
615
546
|
/**
|
|
616
547
|
* Register the field and any dependencies.
|
|
617
548
|
*/
|
|
618
549
|
export function registerFieldMatrix() {
|
|
619
|
-
Blockly.fieldRegistry.register(
|
|
550
|
+
Blockly.fieldRegistry.register('field_matrix', FieldMatrix)
|
|
620
551
|
}
|