Repository navigation
Expand file tree
/
Copy pathgenerators.ts
More file actions
261 lines (227 loc) · 9.31 KB
/
Copy pathgenerators.ts
File metadata and controls
261 lines (227 loc) · 9.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
export default function define(Python: Blockly.BlockGenerators) {
Python['import_board'] = function (block) {
const code = 'from board import *\n';
return code;
};
Python['import_digitalio'] = function (block) {
const code = 'import digitalio\n';
return code;
};
Python['importneo'] = function(block) {
let code = 'import neopixel\n';
return code;
};
Python['import_time'] = function (block) {
const code = 'import time\n';
return code;
};
Python['pause_s'] = function (block) {
const code = 'pause()\n';
return code;
};
Python['random'] = function (block) {
const code = 'import random\n';
return code;
};
Python['while_true'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
return 'while True:\n' + branch;
};
Python['pass'] = function (block) {
const code = 'pass \n';
return code;
};
Python['if'] = function (block) {
const text_const = block.getFieldValue('var');
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
return 'if ' + text_const + ':\n' + branch;
};
Python['class'] = function (block) {
const text_const = block.getFieldValue('var');
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
return 'class ' + text_const + ':\n' + branch;
};
Python['varprint'] = function (block) {
const text_const = block.getFieldValue('var');
// TODO: Assemble Python into code variable.
const code = 'print(' + text_const + ')\n';
return code;
};
Python['ifcroc'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
const text_this = block.getFieldValue('this');
const dropdown_crocsigns = block.getFieldValue('crocsigns');
const text_that = block.getFieldValue('that');
// const statements_name = Blockly.Python.statementToCode(block, 'DO');
// TODO: Assemble Python into code variable.
const code = 'if ' + text_this + ' ' + dropdown_crocsigns + ' ' + text_that + ':\n' + branch;
return code;
};
Python['varminus'] = function (block) {
const text_1 = block.getFieldValue('1');
const text_2 = block.getFieldValue('2');
// TODO: Assemble Python into code variable.
const code = text_1 + ' -= ' + text_2 + '\n';
return code;
};
Python['for'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
const text_letter = block.getFieldValue('letter');
const text_no = block.getFieldValue('no');
// const statements_name = Blockly.Python.statementToCode(block, 'DO');
// TODO: Assemble Python into code variable.
const code = 'for ' + text_letter + ' in range(' + text_no + '):\n' + branch;
return code;
};
Python['advancedforloops'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
const text_x = block.getFieldValue('x');
const text_y = block.getFieldValue('y');
// const statements_do = Blockly.Python.statementToCode(block, 'DO');
// TODO: Assemble Python into code variable.
const code = 'for ' + text_x + ' in ' + text_y + ':\n' + branch;
return code;
};
Python['ifequals'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
const text_this = block.getFieldValue('this');
const text_that = block.getFieldValue('that');
// const statements_do = Blockly.Python.statementToCode(block, 'DO');
// TODO: Assemble Python into code variable.
const code = 'if ' + text_this + ' == ' + text_that + ':\n' + branch;
return code;
};
Python['importinputs'] = function (block) {
// TODO: Assemble Python into code variable.
const code = 'import inputs\n';
return code;
};
Python['return2'] = function (block) {
const text_return = block.getFieldValue('return');
// TODO: Assemble Python into code variable.
const code = 'return ' + text_return + '\n';
return code;
};
Python['elif'] = function (block) {
const text_const = block.getFieldValue('var');
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
return 'elif ' + text_const + ':\n' + branch;
};
Python['else'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
return 'else:\n' + branch;
};
Python['df'] = function (block) {
const text_def = block.getFieldValue('def');
// TODO: Assemble Python into code variable.
const code = text_def + '()\n';
return code;
};
Python['whileout'] = function (block) {
const text_1 = block.getFieldValue('1');
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
// TODO: Assemble Python into code variable.
const code = 'while ' + text_1 + ':\n' + branch;
return code;
};
Python['time'] = function (block) {
// TODO: Assemble Python into code variable.
const code = 'import time\n';
return code;
};
Python['import_math'] = function (block) {
const code = 'import math\n';
return code;
};
Python['import_audio'] = function (block) {
const code = 'import audio\n';
return code;
};
Python['sleep'] = function (block) {
const text_sleeptime = block.getFieldValue('sleep');
const code = 'time.sleep(' + text_sleeptime + ')\n';
return code;
};
Python['print'] = function (block) {
const text_print = block.getFieldValue('print');
// TODO: Assemble Python into code variable.
const code = 'print("' + text_print + '")\n';
return code;
};
Python['equalsblock'] = function (block) {
const text_1 = block.getFieldValue('1');
const text_2 = block.getFieldValue('2');
// TODO: Assemble Python into code variable.
const code = text_1 + '=' + text_2 + '\n';
return code;
};
Python['define'] = function (block) {
const text_1 = block.getFieldValue('1');
const text_2 = block.getFieldValue('2');
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
// const statements_name = Blockly.Python.statementToCode(block, 'NAME');
// TODO: Assemble Python into code variable.
const code = 'def ' + text_1 + '(' + text_2 + '):\n' + branch;
return code;
};
Python['greater'] = function (block) {
const text_1 = block.getFieldValue('1');
const text_v = block.getFieldValue('v');
let branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
// TODO: Assemble Python into code variable.
const code = 'while ' + text_1 + ' > ' + text_v + ':\n' + branch;
return code;
};
Python['buttonapressed'] = function (block) {
const dropdown_name = block.getFieldValue('NAME');
// TODO: Assemble Python into code variable.
const code = 'button_' + dropdown_name + '.is_pressed()';
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.Python.ORDER_ATOMIC];
};
Python['ifinline'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'ifstate');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
const value_iftext = Blockly.Python.valueToCode(block, 'iftext', Blockly.Python.ORDER_ATOMIC);
// const statements_ifstate = Blockly.Python.statementToCode(block, 'ifstate');
// TODO: Assemble Python into code variable.
const code = 'if ' + value_iftext + ':\n' + branch;
return code;
};
Python['typeanything'] = function(block) {
var text_stuff = block.getFieldValue('stuff');
// TODO: Assemble Python into code variable.
var code = text_stuff+ '\n';
return code;
};
Python['elifinline'] = function (block) {
let branch = Blockly.Python.statementToCode(block, 'ifstate');
branch = Blockly.Python.addLoopTrap(branch, block.id) || Blockly.Python.PASS;
const value_iftext = Blockly.Python.valueToCode(block, 'iftext', Blockly.Python.ORDER_ATOMIC);
// const statements_ifstate = Blockly.Python.statementToCode(block, 'ifstate');
// TODO: Assemble Python into code variable.
const code = 'elif ' + value_iftext + ':\n' + branch;
return code;
};
Python['internal'] = function(block) {
var value_first = Blockly.Python.valueToCode(block, 'first', Blockly.Python.ORDER_ATOMIC);
var text_choose = block.getFieldValue('choose');
var value_last = Blockly.Python.valueToCode(block, 'last', Blockly.Python.ORDER_ATOMIC);
// TODO: Assemble Python into code variable.
var code = value_first+ ' ' +text_choose+ ' ' +value_last;
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.Python.ORDER_ATOMIC];
};
}