2016-05-05 16:13:43 -04:00
|
|
|
/**
|
2016-07-11 11:00:33 -04:00
|
|
|
* @license
|
|
|
|
* Visual Blocks Editor
|
|
|
|
*
|
|
|
|
* Copyright 2016 Massachusetts Institute of Technology
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2016-05-05 16:13:43 -04:00
|
|
|
*/
|
2016-08-23 17:50:41 -04:00
|
|
|
|
2016-05-05 16:13:43 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
goog.provide('Blockly.Blocks.event');
|
|
|
|
|
|
|
|
goog.require('Blockly.Blocks');
|
|
|
|
goog.require('Blockly.Colours');
|
2016-07-05 10:05:56 -04:00
|
|
|
goog.require('Blockly.constants');
|
|
|
|
|
|
|
|
|
2016-05-05 16:13:43 -04:00
|
|
|
Blockly.Blocks['event_whenflagclicked'] = {
|
|
|
|
/**
|
|
|
|
* Block for when flag clicked.
|
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
|
|
|
"id": "event_whenflagclicked",
|
|
|
|
"message0": "when %1 clicked",
|
|
|
|
"args0": [
|
|
|
|
{
|
|
|
|
"type": "field_image",
|
|
|
|
"src": Blockly.mainWorkspace.options.pathToMedia + "icons/event_whenflagclicked.svg",
|
2016-05-27 13:21:40 -04:00
|
|
|
"width": 24,
|
|
|
|
"height": 24,
|
2016-05-05 16:13:43 -04:00
|
|
|
"alt": "flag",
|
|
|
|
"flip_rtl": true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"inputsInline": true,
|
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-08 09:48:01 -03:00
|
|
|
Blockly.Blocks['event_whenthisspriteclicked'] = {
|
|
|
|
/**
|
|
|
|
* Block for when this sprite clicked.
|
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
|
|
|
"message0": "when this sprite clicked",
|
|
|
|
"inputsInline": true,
|
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-05 16:13:43 -04:00
|
|
|
Blockly.Blocks['event_whenbroadcastreceived'] = {
|
|
|
|
/**
|
|
|
|
* Block for when broadcast received.
|
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
|
|
|
"id": "event_whenbroadcastreceived",
|
2016-06-13 12:12:33 -04:00
|
|
|
"message0": "when I receive %1",
|
2016-05-05 16:13:43 -04:00
|
|
|
"args0": [
|
2016-06-13 12:12:33 -04:00
|
|
|
{
|
2016-08-23 17:50:41 -04:00
|
|
|
"type": "field_dropdown",
|
|
|
|
"name": "BROADCAST_OPTION",
|
|
|
|
"options": [
|
|
|
|
['message1', 'MESSAGE1'],
|
|
|
|
['message2', 'MESSAGE2'],
|
|
|
|
['new message', 'NEW_MESSAGE']
|
|
|
|
]
|
2016-06-13 12:12:33 -04:00
|
|
|
}
|
2016-05-05 16:13:43 -04:00
|
|
|
],
|
|
|
|
"inputsInline": true,
|
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-08 09:48:01 -03:00
|
|
|
Blockly.Blocks['event_whenbackdropswitchesto'] = {
|
|
|
|
/**
|
|
|
|
* Block for when the current backdrop switched to a selected backdrop.
|
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
|
|
|
"message0": "when backdrop switches to %1",
|
|
|
|
"args0": [
|
|
|
|
{
|
|
|
|
"type": "field_dropdown",
|
|
|
|
"name": "BACKDROP",
|
|
|
|
"options": [
|
|
|
|
['backdrop1', 'BACKDROP1']
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"inputsInline": true,
|
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-23 17:50:41 -04:00
|
|
|
Blockly.Blocks['event_whengreaterthan'] = {
|
2016-07-08 09:48:01 -03:00
|
|
|
/**
|
2016-08-23 17:50:41 -04:00
|
|
|
* Block for when loudness/timer/video motion is greater than the value.
|
2016-07-08 09:48:01 -03:00
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
2016-08-23 17:50:41 -04:00
|
|
|
"message0": "when %1 > %2",
|
2016-07-08 09:48:01 -03:00
|
|
|
"args0": [
|
|
|
|
{
|
|
|
|
"type": "field_dropdown",
|
|
|
|
"name": "WHENGREATERTHANMENU",
|
|
|
|
"options": [
|
|
|
|
['loudness', 'LOUDNESS'],
|
|
|
|
['timer', 'TIMER'],
|
2016-07-11 11:00:33 -04:00
|
|
|
['video motion', 'VIDEOMOTION']
|
2016-07-08 09:48:01 -03:00
|
|
|
]
|
2016-08-23 17:50:41 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "input_value",
|
|
|
|
"name": "VALUE"
|
2016-07-08 09:48:01 -03:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"inputsInline": true,
|
2016-08-23 17:50:41 -04:00
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
2016-07-08 09:48:01 -03:00
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
2016-08-23 17:50:41 -04:00
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
2016-07-08 09:48:01 -03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-05 16:13:43 -04:00
|
|
|
Blockly.Blocks['event_broadcast'] = {
|
|
|
|
/**
|
|
|
|
* Block to send a broadcast.
|
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
|
|
|
"id": "event_broadcast",
|
2016-06-13 12:12:33 -04:00
|
|
|
"message0": "broadcast %1",
|
2016-05-05 16:13:43 -04:00
|
|
|
"args0": [
|
2016-06-13 12:12:33 -04:00
|
|
|
{
|
2016-08-23 17:50:41 -04:00
|
|
|
"type": "field_dropdown",
|
|
|
|
"name": "BROADCAST_OPTION",
|
|
|
|
"options": [
|
|
|
|
['message1', 'MESSAGE1'],
|
|
|
|
['message2', 'MESSAGE2'],
|
|
|
|
['new message', 'NEW_MESSAGE']
|
|
|
|
]
|
2016-06-13 12:12:33 -04:00
|
|
|
}
|
2016-05-05 16:13:43 -04:00
|
|
|
],
|
|
|
|
"inputsInline": true,
|
|
|
|
"previousStatement": null,
|
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-13 12:12:33 -04:00
|
|
|
Blockly.Blocks['event_broadcastandwait'] = {
|
2016-05-05 16:13:43 -04:00
|
|
|
/**
|
2016-06-13 12:12:33 -04:00
|
|
|
* Block to send a broadcast.
|
2016-05-05 16:13:43 -04:00
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
2016-06-13 12:12:33 -04:00
|
|
|
"message0": "broadcast %1 and wait",
|
2016-05-05 16:13:43 -04:00
|
|
|
"args0": [
|
|
|
|
{
|
2016-08-23 17:50:41 -04:00
|
|
|
"type": "field_dropdown",
|
|
|
|
"name": "BROADCAST_OPTION",
|
|
|
|
"options": [
|
|
|
|
['message1', 'MESSAGE1'],
|
|
|
|
['message2', 'MESSAGE2'],
|
|
|
|
['new message', 'NEW_MESSAGE']
|
|
|
|
]
|
2016-05-05 16:13:43 -04:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"inputsInline": true,
|
|
|
|
"previousStatement": null,
|
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2016-07-05 10:20:43 -03:00
|
|
|
|
2016-08-23 17:50:41 -04:00
|
|
|
Blockly.Blocks['event_whenkeypressed'] = {
|
2016-07-05 10:20:43 -03:00
|
|
|
/**
|
2016-08-23 17:50:41 -04:00
|
|
|
* Block to send a broadcast.
|
2016-07-05 10:20:43 -03:00
|
|
|
* @this Blockly.Block
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this.jsonInit({
|
2016-08-23 17:50:41 -04:00
|
|
|
"id": "event_whenkeypressed",
|
|
|
|
"message0": "when %1 key pressed",
|
2016-07-05 10:20:43 -03:00
|
|
|
"args0": [
|
2016-07-05 09:58:16 -04:00
|
|
|
{
|
|
|
|
"type": "field_dropdown",
|
|
|
|
"name": "KEY_OPTION",
|
|
|
|
"options": [
|
|
|
|
['space', 'SPACE'],
|
2016-07-05 10:20:43 -03:00
|
|
|
['left arrow', 'LEFTARROW'],
|
|
|
|
['right arrow', 'RIGHTARROW'],
|
|
|
|
['down arrow', 'DOWNARROW'],
|
|
|
|
['up arrow', 'UPARROW'],
|
2016-07-05 09:58:16 -04:00
|
|
|
['any', 'ANY'],
|
2016-07-05 10:20:43 -03:00
|
|
|
['a', 'A'],
|
|
|
|
['b', 'B'],
|
|
|
|
['c', 'C'],
|
|
|
|
['d', 'D'],
|
|
|
|
['e', 'E'],
|
2016-07-05 09:58:16 -04:00
|
|
|
['f', 'F'],
|
|
|
|
['g', 'G'],
|
2016-07-05 10:20:43 -03:00
|
|
|
['h', 'H'],
|
|
|
|
['i', 'I'],
|
|
|
|
['j', 'J'],
|
|
|
|
['k', 'K'],
|
|
|
|
['m', 'M'],
|
|
|
|
['n', 'N'],
|
|
|
|
['o', 'O'],
|
|
|
|
['p', 'P'],
|
|
|
|
['q', 'Q'],
|
|
|
|
['r', 'R'],
|
|
|
|
['s', 'S'],
|
|
|
|
['t', 'T'],
|
|
|
|
['u', 'U'],
|
|
|
|
['v', 'V'],
|
|
|
|
['w', 'W'],
|
|
|
|
['x', 'X'],
|
|
|
|
['y', 'Y'],
|
|
|
|
['0', 'ZERO'],
|
|
|
|
['1', 'ONE'],
|
|
|
|
['2', 'TWO'],
|
|
|
|
['3', 'THREE'],
|
|
|
|
['4', 'FOUR'],
|
|
|
|
['5', 'FIVE'],
|
|
|
|
['6', 'SIX'],
|
|
|
|
['7', 'SEVEN'],
|
|
|
|
['8', 'EIGHT'],
|
2016-07-05 09:58:16 -04:00
|
|
|
['9', 'NINE']
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2016-07-05 10:20:43 -03:00
|
|
|
"inputsInline": true,
|
|
|
|
"nextStatement": null,
|
|
|
|
"colour": Blockly.Colours.event.primary,
|
|
|
|
"colourSecondary": Blockly.Colours.event.secondary,
|
|
|
|
"colourTertiary": Blockly.Colours.event.tertiary
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|