-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathplayground.html
574 lines (538 loc) · 17.2 KB
/
playground.html
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blockly Playground</title>
<script type="text/javascript" src="../node_modules/google-closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="./test_dependency_map.js"></script>
<script type="text/javascript">
'use strict';
goog.require('Blockly.Playground');
goog.require('goog.tweak');
goog.require('goog.tweak.TweakUi');
var block = null;
</script>
<script type="text/javascript" src="../msg/js/en_us.js"></script>
<script type="text/javascript">
function start() {
goog.tweak.registerBoolean('RTL', 'run in right-to-left mode', false);
goog.tweak.registerBoolean('editBlocks', 'opens with level builder mode enabled', false);
goog.tweak.registerBoolean('nonCategoryMode', 'opens blockly with blocks in categories', false);
goog.tweak.registerBoolean('openContractEditor', 'pre-opens contract editor', false);
goog.tweak.registerBoolean('toggleScrollDragDebug', 'enables autoscroll debugging', false);
goog.tweak.registerBoolean('openFunctionEditor', 'pre-opens function editor', false);
goog.tweak.registerBoolean('openCustomizedFunctionEditor', 'pre-opens customized function editor', false);
goog.tweak.registerBoolean('enableExampleRunning', 'enables running of examples', false);
goog.tweak.registerBoolean('typeHints', 'glow typed inputs based on what color of block they expect', false);
goog.tweak.registerNumber('addContractDomains', 'adds a given number of domain parameters to the auto-opened contract editor', 0);
Blockly.inject(document.getElementById('blocklyDiv'), {
rtl: goog.tweak.getBoolean('RTL'),
path: '../',
toolbox: getToolboxElement(),
hasVerticalScrollbars: true,
assetUrl: function(path) { return '../' + path; },
customSimpleDialog: Blockly.Playground.customSimpleDialog,
valueTypeTabShapeMap: { Sprite: 'angle', Behavior: 'rounded', Location: 'square' },
typeHints: goog.tweak.getBoolean('typeHints')
});
if (goog.tweak.getBoolean('enableExampleRunning')) {
Blockly.showExampleTestButtons = true;
}
if (goog.tweak.getBoolean('editBlocks')) {
Blockly.editBlocks = true;
}
if (goog.tweak.getBoolean('openContractEditor')) {
newContractEditor();
} else if (goog.tweak.getBoolean('openFunctionEditor')) {
newFunctionEditor();
} else if (goog.tweak.getBoolean('openCustomizedFunctionEditor')) {
newCustomizedFunctionEditor();
}
if (goog.tweak.getBoolean('toggleScrollDragDebug')) {
Blockly.ScrollOnBlockDragHandler.DEBUG = true;
}
}
function getToolboxElement() {
return goog.tweak.getBoolean('nonCategoryMode') ?
document.getElementById('non-category-toolbox') :
document.getElementById('toolbox');
}
/**
* @param {Element} checkboxElement
*/
function toggleFullBump(checkboxElement) {
Blockly.BlockSpaceEditor.BUMP_ENTIRE_BLOCK = checkboxElement.checked;
goog.style.setElementShown(document.getElementById('bump-debug-checkbox'),
checkboxElement.checked);
}
/**
* @param {Element} checkboxElement
*/
function toggleBumpDebug(checkboxElement) {
Blockly.BlockSpaceEditor.BUMP_DEBUG = checkboxElement.checked;
}
/**
* @param {Element} checkboxElement
*/
function toggleScrollDragDebug(checkboxElement) {
Blockly.ScrollOnBlockDragHandler.DEBUG = checkboxElement.checked;
}
function newContractEditor() {
Blockly.defaultNumExampleBlocks = 2;
Blockly.useContractEditor = true;
Blockly.functionEditor = Blockly.contractEditor = new Blockly.ContractEditor({
disableExamples: false
});
Blockly.contractEditor.openWithNewFunction();
var numberContractDomains = goog.tweak.getNumber('addContractDomains');
if (numberContractDomains) {
for (var i = 0; i < numberContractDomains; i++) {
Blockly.contractEditor.addParameter('param' + i);
}
Blockly.contractEditor.refreshParamsEverywhere();
Blockly.contractEditor.layOutBlockSpaceItems_();
}
}
function newVariableEditor() {
Blockly.useContractEditor = true;
Blockly.functionEditor = Blockly.contractEditor = new Blockly.ContractEditor({
disableExamples: false
});
Blockly.contractEditor.openWithNewFunction(true);
}
function newFunctionEditor() {
Blockly.defaultNumExampleBlocks = 2;
Blockly.functionEditor = new Blockly.FunctionEditor({
});
Blockly.functionEditor.openWithNewFunction();
}
function newCustomizedFunctionEditor() {
Blockly.oceanBoilerEditor = new Blockly.FunctionEditor(
{
FUNCTION_HEADER: 'Ocean Boiler',
FUNCTION_NAME_LABEL: 'Name your ocean boiler:',
FUNCTION_DESCRIPTION_LABEL: 'What kind of ocean is this supposed to boil?',
},
'ocean_boiler_definition',
null,
false,
[
Blockly.BlockValueType.NUMBER,
Blockly.BlockValueType.STRING,
Blockly.BlockValueType.COLOUR,
Blockly.BlockValueType.BOOLEAN,
Blockly.BlockValueType.SPRITE,
Blockly.BlockValueType.LOCATION
]
);
Blockly.oceanBoilerEditor.openWithNewFunction();
}
function toXml() {
var output = document.getElementById('importExport');
var xml = Blockly.Xml.blockSpaceToDom(Blockly.mainBlockSpace);
output.value = Blockly.Xml.domToText(xml);
output.focus();
output.select();
}
function fromXml() {
var input = document.getElementById('importExport');
var xml = Blockly.Xml.textToDom(input.value);
Blockly.Xml.domToBlockSpace(Blockly.mainBlockSpace, xml);
}
function toCode(lang) {
var output = document.getElementById('importExport');
output.value = Blockly.Generator.blockSpaceToCode(lang);
}
function airstrike(n) {
var prototypes = [];
var toolbox = getToolboxElement();
var blocks = toolbox.getElementsByTagName('block');
for (var x = 0, block; block = blocks[x]; x++) {
prototypes.push(block.getAttribute('type'));
}
for (var x = 0; x < n; x++) {
var prototype = prototypes[Math.floor(Math.random() * prototypes.length)];
var block = new Blockly.Block(Blockly.mainBlockSpace, prototype);
block.initSvg();
block.getSvgRoot().setAttribute('transform', 'translate(' +
Math.round(Math.random() * 450 + 40) + ', ' +
Math.round(Math.random() * 600 + 40) + ')');
block.render();
}
}
function sizeTo(sizeString) {
document.getElementById('blocklyDiv').style.height = sizeString;
var ev = document.createEvent('Event');
ev.initEvent('resize', true, true);
window.dispatchEvent(ev);
}
</script>
<style>
html, body {
height: 100%;
}
body {
background-color: #fff;
font-family: sans-serif;
overflow: hidden;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
h1 {
font-weight: normal;
font-size: 140%;
}
#blocklyDiv {
position: absolute;
left: calc(30% + 4px);
height: 95%;
width: calc(70% - 8px);
}
#controls-section {
position: absolute;
width: calc(30% - 4px);
left: 0;
top: 0;
}
#controls {
margin: 5px;
}
/*
* Standard styling for goog.ui.Dialog.
*
* @author [email protected] (Steven Saviano)
* @author [email protected] (Attila Bodis)
*/
.modal-dialog {
background: #c1d9ff;
border: 1px solid #3a5774;
color: #000;
padding: 4px;
position: absolute;
}
.modal-dialog a,
.modal-dialog a:link,
.modal-dialog a:visited {
color: #06c;
cursor: pointer;
}
.modal-dialog-bg {
background: #666;
left: 0;
position: absolute;
top: 0;
}
.modal-dialog-title {
background: #e0edfe;
color: #000;
cursor: pointer;
font-size: 120%;
font-weight: bold;
/* Add padding on the right to ensure the close button has room. */
padding: 8px 31px 8px 8px;
position: relative;
_zoom: 1; /* Ensures proper width in IE6 RTL. */
}
.modal-dialog-title-close {
/* Client apps may override the URL at which they serve the sprite. */
background: #e0edfe;
cursor: default;
height: 15px;
position: absolute;
right: 10px;
top: 8px;
width: 15px;
vertical-align: middle;
}
.modal-dialog-buttons,
.modal-dialog-content {
background-color: #fff;
padding: 8px;
}
.goog-buttonset-default {
font-weight: bold;
}
/*
* End standard styling for goog.ui.Dialog.
*/
</style>
</head>
<body onload="start()">
<div id="blocklyDiv"></div>
<xml id="toolbox" style="display: none">
<category name="Logic">
<block type="controls_if"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block>
<block type="logic_null"></block>
<block type="logic_ternary"></block>
</category>
<category name="Loops">
<block type="controls_repeat_ext">
<value name="TIMES">
<block type="math_number">
<title name="NUM">10</title>
</block>
</value>
</block>
<block type="controls_whileUntil"></block>
<block type="controls_for">
<value name="FROM">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
<value name="TO">
<block type="math_number">
<title name="NUM">10</title>
</block>
</value>
<value name="BY">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
</block>
<block type="controls_forEach"></block>
<block type="controls_flow_statements"></block>
</category>
<category name="Math">
<block type="math_number"></block>
<block type="math_arithmetic"></block>
<block type="math_single"></block>
<block type="math_trig"></block>
<block type="math_constant"></block>
<block type="math_number_property"></block>
<block type="math_change">
<value name="DELTA">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
</block>
<block type="math_round"></block>
<block type="math_on_list"></block>
<block type="math_modulo"></block>
<block type="math_constrain">
<value name="LOW">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
<value name="HIGH">
<block type="math_number">
<title name="NUM">100</title>
</block>
</value>
</block>
<block type="math_random_int">
<value name="FROM">
<block type="math_number">
<title name="NUM">1</title>
</block>
</value>
<value name="TO">
<block type="math_number">
<title name="NUM">100</title>
</block>
</value>
</block>
<block type="math_random_float"></block>
</category>
<category name="Text">
<block type="text"></block>
<block type="text_join"></block>
<block type="text_append">
<value name="TEXT">
<block type="text"></block>
</value>
</block>
<block type="text_length"></block>
<block type="text_isEmpty"></block>
<block type="text_indexOf">
<value name="VALUE">
<block type="variables_get">
<title name="VAR">text</title>
</block>
</value>
</block>
<block type="text_charAt">
<value name="VALUE">
<block type="variables_get">
<title name="VAR">text</title>
</block>
</value>
</block>
<block type="text_getSubstring">
<value name="STRING">
<block type="variables_get">
<title name="VAR">text</title>
</block>
</value>
</block>
<block type="text_changeCase"></block>
<block type="text_trim"></block>
<block type="text_print"></block>
<block type="text_prompt"></block>
</category>
<category name="Lists">
<block type="lists_create_empty"></block>
<block type="lists_create_with"></block>
<block type="lists_repeat">
<value name="NUM">
<block type="math_number">
<title name="NUM">5</title>
</block>
</value>
</block>
<block type="lists_length"></block>
<block type="lists_isEmpty"></block>
<block type="lists_indexOf">
<value name="VALUE">
<block type="variables_get">
<title name="VAR">list</title>
</block>
</value>
</block>
<block type="lists_getIndex">
<value name="VALUE">
<block type="variables_get">
<title name="VAR">list</title>
</block>
</value>
</block>
<block type="lists_setIndex">
<value name="LIST">
<block type="variables_get">
<title name="VAR">list</title>
</block>
</value>
</block>
<block type="lists_getSublist">
<value name="LIST">
<block type="variables_get">
<title name="VAR">list</title>
</block>
</value>
</block>
</category>
<category name="Colour">
<block type="colour_picker"></block>
<block type="colour_random"></block>
<block type="colour_rgb"></block>
<block type="colour_blend"></block>
<block limit="3" type="colour_blend"></block>
</category>
<category name="Variables" custom="VARIABLE"></category>
<category name="Functions" custom="PROCEDURE"></category>
<category name="Sprites">
<block type="sprite_variables_get"></block>
<block type="sprite_variables_set"></block>
<block type="sprite_variables_set" inline="true"></block>
<block type="behavior_variables_get"></block>
<block type="behavior_variables_set"></block>
<block type="behavior_variables_set" inline="true"></block>
<block type="location_variables_get"></block>
<block type="location_variables_set"></block>
<block type="location_variables_set" inline="true"></block>
<block type="dropdown_with_button_block" inline="true"></block>
</category>
<category name="Events">
<block type="parent">
<value name="COLOUR">
<block type="colour_picker">
<title name="COLOUR">#ff0000</title>
</block>
</value>
<value name="TEXT">
<block type="text">
<title name="TEXT">hello</title>
</block>
</value>
</block>
</category>
<category name="CSinA Vars" custom="FUNCTIONAL_VARIABLE" />
</xml>
<xml id="non-category-toolbox" style="display: none">
<block type="button_block"></block>
<block type="variables_get"></block>
<block type="variables_set"></block>
<block type="variables_set" inline="true"></block>
<block type="sprite_variables_get"></block>
<block type="sprite_variables_set"></block>
<block type="sprite_variables_set" inline="true"></block>
<block type="controls_if"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block>
<block type="logic_null"></block>
<block limit="3" type="logic_ternary"></block>
</xml>
<div id="controls-section">
<div id="controls">
<h1>Blockly Playground</h1>
<p><a href="javascript:void([document.getElementById('blocklyDiv').style.display = 'block', Blockly.mainBlockSpace.render()])">Show</a>
- <a href="javascript:void(document.getElementById('blocklyDiv').style.display = 'none')">Hide</a></p>
<p>
<input type="button" value="Create Contract Editor" onclick="newContractEditor()">
<input type="button" value="Create Variable Editor" onclick="newVariableEditor()">
<input type="button" value="Create Function Editor" onclick="newFunctionEditor()">
<input type="button" value="Export to XML" onclick="toXml()">
<input type="button" value="Import from XML" onclick="fromXml()">
<br>
<input type="button" value="Generate JavaScript" onclick="toCode('JavaScript')">
<input type="button" value="Generate Python" onclick="toCode('Python')">
<br>
<textarea id="importExport" style="width: 100%; height: 12em"></textarea>
</p>
<hr>
<p>
<input type="button" value="Size: 100px" onclick="sizeTo('100px')">
<br>
<input type="button" value="Size: 95%" onclick="sizeTo('95%')">
<br>
</p>
<hr>
<p>
Toggle entire block bumping <input type="checkbox" value="false" onclick="toggleFullBump(this)">
<br>
<span id="bump-debug-checkbox" style="display: none">
Toggle block bump debug drawing <input type="checkbox" value="false" onclick="toggleBumpDebug(this)">
<br>
</span>
Toggle scroll-on-drag debug drawing <input type="checkbox" value="false" onclick="toggleScrollDragDebug(this)">
<br>
<input type="button" value="Clear Debug Drawings" onclick="Blockly.focusedBlockSpace.clearDebugDrawings()">
<br>
</p>
<hr>
<p>
Stress test with an <input type="button" value="Airstrike!" onclick="airstrike(100)">
</p>
<hr>
<p>
<h3>URL Parameter Tweaks</h3>
<div id="tweak-menu"></div>
<script>
document.getElementById('tweak-menu').appendChild(goog.tweak.TweakUi.create());
</script>
</p>
</div>
</div>
</body>
</html>