-
Notifications
You must be signed in to change notification settings - Fork 822
/
basicblocks.js
119 lines (110 loc) · 3.6 KB
/
basicblocks.js
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
// Copyright (c) 2014-21 Walter Bender
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
// Definition of basic blocks common to all branches
// Some names changed between the Python verison and the
// JS version so look up name in the conversion dictionary.
/*
global
setupRhythmBlockPaletteBlocks, setupRhythmBlocks, setupMeterBlocks,
setupPitchBlocks, setupIntervalsBlocks, setupToneBlocks,
setupOrnamentBlocks, setupVolumeBlocks, setupDrumBlocks,
setupWidgetBlocks, setupFlowBlocks, setupNumberBlocks,
setupActionBlocks, setupBoxesBlocks, setupBooleanBlocks,
setupHeapBlocks, setupDictBlocks, setupExtrasBlocks,
setupProgramBlocks, setupGraphicsBlocks setupPenBlocks,
setupMediaBlocks, setupSensorsBlocks, setupEnsembleBlocks
*/
/*
exported
initBasicProtoBlocks, BACKWARDCOMPATIBILIYDICT
*/
/**
* Dictionary mapping old block names to their corresponding new block names for backward compatibility.
* @constant {Object<string, string>}
*/
const BACKWARDCOMPATIBILIYDICT = {
fullscreen: "vspace",
fillscreen2: "fillscreen",
sandwichclampcollapsed: "clamp",
ifelse: "ifthenelse",
xcor: "x",
ycor: "y",
seth: "setheading",
remainder2: "mod",
plus2: "plus",
product2: "multiply",
division2: "divide",
minus2: "minus",
stack: "do",
hat: "action",
stopstack: "break",
clean: "clear",
setxy2: "setxy",
greater2: "greater",
less2: "less",
equal2: "equal",
random2: "random",
setvalue: "setshade",
setchroma: "setgrey",
setgray: "setgrey",
gray: "grey",
chroma: "grey",
value: "shade",
hue: "color",
startfill: "beginfill",
stopfill: "endfill",
string: "text",
shell: "turtleshell"
};
// Define blocks here. Note: The blocks are placed on the palettes
// from bottom to top, i.e., the block at the top of a palette will be
// the last block added to a palette.
/**
* @public
* @param {Object} palettes
* @param {Object} blocks
* @returns {void}
*/
const initBasicProtoBlocks = (activity) => {
activity.blocks.palettes = activity.palettes;
setupRhythmBlockPaletteBlocks(activity);
setupRhythmBlocks(activity);
setupMeterBlocks(activity);
setupPitchBlocks(activity);
setupIntervalsBlocks(activity);
setupToneBlocks(activity);
setupOrnamentBlocks(activity);
setupVolumeBlocks(activity);
setupDrumBlocks(activity);
setupWidgetBlocks(activity);
setupFlowBlocks(activity);
setupNumberBlocks(activity);
setupActionBlocks(activity);
setupBoxesBlocks(activity);
setupBooleanBlocks(activity);
setupHeapBlocks(activity);
setupDictBlocks(activity);
setupExtrasBlocks(activity);
setupProgramBlocks(activity);
setupGraphicsBlocks(activity);
setupPenBlocks(activity);
setupMediaBlocks(activity);
setupSensorsBlocks(activity);
setupEnsembleBlocks(activity);
// Push protoblocks onto their palettes.
for (const protoblock in activity.blocks.protoBlockDict) {
if (activity.blocks.protoBlockDict[protoblock].palette != null) {
activity.blocks.protoBlockDict[protoblock].palette.add(
activity.blocks.protoBlockDict[protoblock]
);
}
}
};