@@ -26,6 +26,158 @@ const sbsPrefix = '';
26
26
27
27
Blockly . Blocks . CoderBotSettings = { } ;
28
28
29
+ Blockly . Blocks . coderbot_basic_repeat = {
30
+ /**
31
+ * Block for repeat n times (internal number).
32
+ * @this Blockly.Block
33
+ */
34
+ init ( self ) {
35
+ this . setHelpUrl ( Blockly . Msg . CONTROLS_REPEAT_HELPURL ) ;
36
+ this . setColour ( 120 ) ;
37
+ const di = this . appendDummyInput ( ) ;
38
+ di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/loop_repeat.png' , 32 , 32 , '*' ) ) ;
39
+ di . appendField ( new Blockly . FieldTextInput ( '10' ,
40
+ Blockly . FieldTextInput . nonnegativeIntegerValidator ) , 'TIMES' ) ;
41
+ const si = this . appendStatementInput ( 'DO' ) ;
42
+ this . setPreviousStatement ( true ) ;
43
+ this . setNextStatement ( true ) ;
44
+ this . setTooltip ( Blockly . Msg . CONTROLS_REPEAT_TOOLTIP ) ;
45
+ } ,
46
+ } ;
47
+
48
+ Blockly . Python . coderbot_basic_repeat = function ( block ) {
49
+ // Repeat n times (internal number).
50
+ const repeats = parseInt ( block . getFieldValue ( 'TIMES' ) , 10 ) ;
51
+ let branch = Blockly . Python . statementToCode ( block , 'DO' ) ;
52
+ branch = Blockly . Python . addLoopTrap ( branch , block . id ) ||
53
+ Blockly . Python . LOOP_PASS ;
54
+ const loopVar = Blockly . Python . variableDB_ . getDistinctName (
55
+ 'count' , Blockly . Variables . NAME_TYPE ,
56
+ ) ;
57
+ const code = `for ${ loopVar } in range(${ repeats } ):\n${ branch } ` ;
58
+ return code ;
59
+ } ;
60
+
61
+ Blockly . Blocks . coderbot_basic_moveForward = {
62
+ // Block for moving forward.
63
+ init ( ) {
64
+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Move' ) ;
65
+ this . setColour ( 40 ) ;
66
+ const di = this . appendDummyInput ( ) ;
67
+ di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_forward.png' , 32 , 32 , '*' ) ) ;
68
+ this . setPreviousStatement ( true ) ;
69
+ this . setNextStatement ( true ) ;
70
+ this . setTooltip ( 'CoderBot_moveForwardTooltip' ) ;
71
+ } ,
72
+ } ;
73
+
74
+ Blockly . Python . coderbot_basic_moveForward = function ( block ) {
75
+ // Generate Python for moving forward.
76
+ if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_MOVE_MOTION ) {
77
+ return `${ sbsPrefix } get_motion().move(dist=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_FW_DEF_ELAPSE } )\n` ;
78
+ }
79
+ return `${ sbsPrefix } get_bot().forward(speed=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_FW_DEF_SPEED } , elapse=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_FW_DEF_ELAPSE } )\n` ;
80
+ } ;
81
+
82
+ Blockly . Blocks . coderbot_basic_moveBackward = {
83
+ // Block for moving forward.
84
+ init ( ) {
85
+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Move' ) ;
86
+ this . setColour ( 40 ) ;
87
+ const di = this . appendDummyInput ( ) ;
88
+ di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_backward.png' , 32 , 32 , '*' ) ) ;
89
+ this . setPreviousStatement ( true ) ;
90
+ this . setNextStatement ( true ) ;
91
+ this . setTooltip ( 'CoderBot_moveBackwardTooltip' ) ;
92
+ } ,
93
+ } ;
94
+
95
+ Blockly . Python . coderbot_basic_moveBackward = function ( block ) {
96
+ // Generate Python for moving forward.
97
+ if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_MOVE_MOTION ) {
98
+ return `${ sbsPrefix } get_motion().move(dist=${ - Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_FW_DEF_ELAPSE } )\n` ;
99
+ }
100
+ return `${ sbsPrefix } get_bot().backward(speed=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_FW_DEF_SPEED } , elapse=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_FW_DEF_ELAPSE } )\n` ;
101
+ } ;
102
+
103
+ Blockly . Blocks . coderbot_basic_turnLeft = {
104
+ // Block for turning left.
105
+ init ( ) {
106
+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Turn' ) ;
107
+ this . setColour ( 40 ) ;
108
+ const di = this . appendDummyInput ( ) ;
109
+ di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_left.png' , 32 , 32 , '*' ) ) ;
110
+ this . setPreviousStatement ( true ) ;
111
+ this . setNextStatement ( true ) ;
112
+ this . setTooltip ( ( 'CoderBot_turnTooltip' ) ) ;
113
+ } ,
114
+ } ;
115
+
116
+ Blockly . Python . coderbot_basic_turnLeft = function ( block ) {
117
+ // Generate Python for turning left.
118
+ if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_MOVE_MOTION ) {
119
+ return `${ sbsPrefix } get_motion().turn(angle=${ - Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_ELAPSE } )\n` ;
120
+ }
121
+ if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_MOVE_MPU ) {
122
+ return `${ sbsPrefix } get_bot().turn_angle(speed=${ - Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_SPEED } , angle=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_ELAPSE } )\n` ;
123
+ }
124
+ return `${ sbsPrefix } get_bot().left(speed=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_SPEED } , elapse=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_ELAPSE } )\n` ;
125
+ } ;
126
+
127
+ Blockly . Blocks . coderbot_basic_turnRight = {
128
+ // Block for turning right.
129
+ init ( ) {
130
+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Turn' ) ;
131
+ this . setColour ( 40 ) ;
132
+ const di = this . appendDummyInput ( ) ;
133
+ di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_right.png' , 32 , 32 , '*' ) ) ;
134
+ this . setPreviousStatement ( true ) ;
135
+ this . setNextStatement ( true ) ;
136
+ this . setTooltip ( ( 'CoderBot_turnTooltip' ) ) ;
137
+ } ,
138
+ } ;
139
+
140
+ Blockly . Python . coderbot_basic_turnRight = function ( block ) {
141
+ // Generate Python for turning left or right.
142
+ if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_MOVE_MOTION ) {
143
+ return `${ sbsPrefix } get_motion().turn(angle=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_ELAPSE } )\n` ;
144
+ }
145
+ if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_MOVE_MPU ) {
146
+ return `${ sbsPrefix } get_bot().turn_angle(speed=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_SPEED } , angle=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_ELAPSE } )\n` ;
147
+ }
148
+ return `${ sbsPrefix } get_bot().right(speed=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_SPEED } , elapse=${ Blockly . Blocks . CoderBotSettings . CODERBOT_MOV_TR_DEF_ELAPSE } )\n` ;
149
+ } ;
150
+
151
+ Blockly . Blocks . coderbot_basic_audio_say = {
152
+ // Block for text to speech.
153
+ init ( ) {
154
+ this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Say' ) ;
155
+ this . setColour ( 220 ) ;
156
+ const vi = this . appendValueInput ( 'TEXT' ) ;
157
+ vi . setCheck ( [ 'String' , 'Number' , 'Date' ] ) ;
158
+ vi . appendField ( new Blockly . FieldImage ( '/static/images/blocks/say.png' , 32 , 32 , '*' ) ) ;
159
+ vi . appendField ( new Blockly . FieldDropdown ( [
160
+ [ Blockly . Msg . CODERBOT_LOCALE_EN , 'en' ] ,
161
+ [ Blockly . Msg . CODERBOT_LOCALE_IT , 'it' ] ,
162
+ [ Blockly . Msg . CODERBOT_LOCALE_FR , 'fr' ] ,
163
+ [ Blockly . Msg . CODERBOT_LOCALE_ES , 'es' ] ,
164
+ ] ) , 'LOCALE' ) ;
165
+
166
+ this . setPreviousStatement ( true ) ;
167
+ this . setNextStatement ( true ) ;
168
+ this . setTooltip ( ( 'CoderBot_sayTooltip' ) ) ;
169
+ } ,
170
+ } ;
171
+
172
+ Blockly . Python . coderbot_basic_audio_say = function ( block ) {
173
+ // Generate Python for turning left or right.
174
+ const text = Blockly . Python . valueToCode ( block , 'TEXT' ,
175
+ Blockly . Python . ORDER_NONE ) || '\'\'' ;
176
+ const locale = block . getFieldValue ( 'LOCALE' ) ;
177
+ return `${ sbsPrefix } get_audio().say(${ text } , locale="${ locale } ")\n` ;
178
+ } ;
179
+
180
+
29
181
Blockly . Blocks . coderbot_repeat = {
30
182
/**
31
183
* Block for repeat n times (internal number).
@@ -81,11 +233,7 @@ Blockly.Blocks.coderbot_moveForward = {
81
233
this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Move' ) ;
82
234
this . setColour ( 40 ) ;
83
235
const di = this . appendDummyInput ( ) ;
84
- if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_LEVEL . indexOf ( 'basic' ) >= 0 ) {
85
- di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_forward.png' , 32 , 32 , '*' ) ) ;
86
- } else {
87
- di . appendField ( Blockly . Msg . CODERBOT_MOVE_FORWARD ) ;
88
- }
236
+ di . appendField ( Blockly . Msg . CODERBOT_MOVE_FORWARD ) ;
89
237
this . setPreviousStatement ( true ) ;
90
238
this . setNextStatement ( true ) ;
91
239
this . setTooltip ( 'CoderBot_moveForwardTooltip' ) ;
@@ -106,11 +254,7 @@ Blockly.Blocks.coderbot_moveBackward = {
106
254
this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Move' ) ;
107
255
this . setColour ( 40 ) ;
108
256
const di = this . appendDummyInput ( ) ;
109
- if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_LEVEL . indexOf ( 'basic' ) >= 0 ) {
110
- di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_backward.png' , 32 , 32 , '*' ) ) ;
111
- } else {
112
- di . appendField ( Blockly . Msg . CODERBOT_MOVE_BACKWARD ) ;
113
- }
257
+ di . appendField ( Blockly . Msg . CODERBOT_MOVE_BACKWARD ) ;
114
258
this . setPreviousStatement ( true ) ;
115
259
this . setNextStatement ( true ) ;
116
260
this . setTooltip ( 'CoderBot_moveBackwardTooltip' ) ;
@@ -131,11 +275,7 @@ Blockly.Blocks.coderbot_turnLeft = {
131
275
this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Turn' ) ;
132
276
this . setColour ( 40 ) ;
133
277
const di = this . appendDummyInput ( ) ;
134
- if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_LEVEL . indexOf ( 'basic' ) >= 0 ) {
135
- di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_left.png' , 32 , 32 , '*' ) ) ;
136
- } else {
137
- di . appendField ( Blockly . Msg . CODERBOT_MOVE_LEFT ) ;
138
- }
278
+ di . appendField ( Blockly . Msg . CODERBOT_MOVE_LEFT ) ;
139
279
this . setPreviousStatement ( true ) ;
140
280
this . setNextStatement ( true ) ;
141
281
this . setTooltip ( ( 'CoderBot_turnTooltip' ) ) ;
@@ -159,11 +299,7 @@ Blockly.Blocks.coderbot_turnRight = {
159
299
this . setHelpUrl ( 'http://code.google.com/p/blockly/wiki/Turn' ) ;
160
300
this . setColour ( 40 ) ;
161
301
const di = this . appendDummyInput ( ) ;
162
- if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_LEVEL . indexOf ( 'basic' ) >= 0 ) {
163
- di . appendField ( new Blockly . FieldImage ( '/static/images/blocks/move_right.png' , 32 , 32 , '*' ) ) ;
164
- } else {
165
- di . appendField ( Blockly . Msg . CODERBOT_MOVE_RIGHT ) ;
166
- }
302
+ di . appendField ( Blockly . Msg . CODERBOT_MOVE_RIGHT ) ;
167
303
this . setPreviousStatement ( true ) ;
168
304
this . setNextStatement ( true ) ;
169
305
this . setTooltip ( ( 'CoderBot_turnTooltip' ) ) ;
@@ -188,11 +324,7 @@ Blockly.Blocks.coderbot_audio_say = {
188
324
this . setColour ( 220 ) ;
189
325
const vi = this . appendValueInput ( 'TEXT' ) ;
190
326
vi . setCheck ( [ 'String' , 'Number' , 'Date' ] ) ;
191
- if ( Blockly . Blocks . CoderBotSettings . CODERBOT_PROG_LEVEL . indexOf ( 'basic' ) >= 0 ) {
192
- vi . appendField ( new Blockly . FieldImage ( '/static/images/blocks/say.png' , 32 , 32 , '*' ) ) ;
193
- } else {
194
- vi . appendField ( Blockly . Msg . CODERBOT_SAY ) ;
195
- }
327
+ vi . appendField ( Blockly . Msg . CODERBOT_SAY ) ;
196
328
vi . appendField ( new Blockly . FieldDropdown ( [
197
329
[ Blockly . Msg . CODERBOT_LOCALE_EN , 'en' ] ,
198
330
[ Blockly . Msg . CODERBOT_LOCALE_IT , 'it' ] ,
0 commit comments