-
Notifications
You must be signed in to change notification settings - Fork 3
/
exampleBlocks.js
157 lines (142 loc) · 4.38 KB
/
exampleBlocks.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
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
var mathChangeJson = {
"message0": "change %1 by %2",
"args0": [
{"type": "field_variable", "name": "VAR", "variable": "item", "variableTypes": [""]},
{"type": "input_value", "name": "DELTA", "check": "Number"}
],
"previousStatement": null,
"nextStatement": null,
"colour": 230
};
Blockly.Blocks['math_change'] = {
init: function() {
this.jsonInit(mathChangeJson);
// Assign 'this' to a variable for use in the tooltip closure below.
var thisBlock = this;
this.setTooltip(function() {
return 'Add a number to variable "%1".'.replace('%1',
thisBlock.getFieldValue('VAR'));
});
}
};
Blockly.Blocks['input'] = {
init: function() {
this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(new Blockly.FieldTextInput(""), "intromessage")
.appendField("introduction ");
this.setNextStatement(true, "String");
this.setColour(120);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['response'] = {
init: function() {
this.appendDummyInput()
.appendField("response")
.appendField(new Blockly.FieldTextInput("default"), "userResponse");
this.setNextStatement(true, "String");
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['output'] = {
init: function() {
this.appendValueInput("NAME")
.setCheck("String")
.appendField("output")
.appendField(new Blockly.FieldTextInput(""), "ClientResponse");
this.setNextStatement(true, null);
this.setColour(0);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['get_user_resopnse'] = {
init: function() {
this.appendDummyInput()
.appendField("get user response");
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['userresponsevarable'] = {
init: function() {
this.appendValueInput("UserResponse")
.setCheck("String")
.appendField("User ResponseChecker");
this.setOutput(true, "Boolean");
this.setColour(120);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['question_block'] = {
init: function() {
this.appendDummyInput()
.appendField("Question ")
.appendField(new Blockly.FieldTextInput(""), "Question they want to ask");
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['question_input_block'] = {
init: function() {
this.appendValueInput("NAME")
.setCheck("String")
.appendField("ask question");
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['input'] = function(block) {
var text_intromessage = block.getFieldValue('intromessage');
// TODO: Assemble JavaScript into code variable.
var code = '...;\n';
return code;
};
Blockly.JavaScript['response'] = function(block) {
var text_userresponse = block.getFieldValue('userResponse');
// TODO: Assemble JavaScript into code variable.
var code = '...;\n';
return code;
};
Blockly.JavaScript['output'] = function(block) {
var text_clientresponse = block.getFieldValue('ClientResponse');
var value_name = Blockly.JavaScript.valueToCode(block, 'NAME', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var code = '...;\n';
return code;
};
Blockly.JavaScript['get_user_resopnse'] = function(block) {
// TODO: Assemble JavaScript into code variable.
var code = '...;\n';
return code;
};
Blockly.JavaScript['userresponsevarable'] = function(block) {
var value_userresponse = Blockly.JavaScript.valueToCode(block, 'UserResponse', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var code = '...';
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.JavaScript['question_block'] = function(block) {
var text_question_they_want_to_ask = block.getFieldValue('Question they want to ask');
// TODO: Assemble JavaScript into code variable.
var code = '...;\n';
return code;
};
Blockly.JavaScript['question_input_block'] = function(block) {
var value_name = Blockly.JavaScript.valueToCode(block, 'NAME', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var code = '...;\n';
return code;
};