scratch-blocks/blocks_vertical/event.js

286 lines
7.4 KiB
JavaScript
Raw Normal View History

/**
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.
*/
'use strict';
goog.provide('Blockly.Blocks.event');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
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",
Vertical shapes pass (#362) * Add if, if-else, equals; remove old if-elses * Naming fixes and removal of a dummy input for if-else * Fix spacing constants; add correct notches. * Fixing inner notches and connections on vertical statements * Fix size of extra row after last statement input * Add minimum block width * Vertical hat shape to spec * Larger vertical minimum block width * Remove INLINE_PADDING_Y and increase MIN_BLOCK_X INLINE_PADDING_Y, a fixed padding for the internal inputs, shouldn't be necessary in Scratch Blocks. Instead, we'll attempt to center the inputs vertically, and give a padding eventually not for inline inputs but rather for non-shadow blocks in inputs... * Remove code for horizontal puzzle tabs * Remove code for "external naked fields" * Start hats are always on in Scratch Blocks * Update vertical playground to start at 75% * Vertical field alignment in vertical rendering * Increase size of vertical green flag icon * Minimum width for blocks with C- or E-. * Remove unused field alignment code * Fix up inner spacing on statement input * Fix overhang to avoid clobbering height calculation * Subtract correct height in getHeightWidth * Subtract notch height in drawing statement bay * Add MIN_STATEMENT_INPUT_HEIGHT * Update size of extra row after statement input * Don't add extra pixel on statement input connection * Fix psuedo-height for blocks with no next connection * Rows after a statement input take the same size as EXTRA_STATEMENT_ROW_Y * Simplify height management to never include notches * Consolidate inputRows.rightEdge calculation * Clean up tab removal * Fix domToWorkspace in vertical_playground.html * Render constant newlines * Updating NOTCH_LEFT_PADDING to NOTCH_START_PADDING * Update comments about vertical field centering; spacing * Remove old comment about baseline * Simplify logic for positioning inline inputs * Ensure inputs in the first row don't overlap with notch
2016-05-27 13:21:40 -04:00
"width": 24,
"height": 24,
"alt": "flag",
"flip_rtl": true
}
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
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
});
}
};
Blockly.Blocks['event_whenbroadcastreceived'] = {
/**
* Block for when broadcast received.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_whenbroadcastreceived",
"message0": "when I receive %1",
"args0": [
{
"type": "field_dropdown",
"name": "BROADCAST_OPTION",
"options": [
['message1', 'MESSAGE1'],
['message2', 'MESSAGE2'],
['new message', 'NEW_MESSAGE']
]
}
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
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
});
}
};
Blockly.Blocks['event_whengreaterthan'] = {
/**
* Block for when loudness/timer/video motion is greater than the value.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "when %1 > %2",
"args0": [
{
"type": "field_dropdown",
"name": "WHENGREATERTHANMENU",
"options": [
['loudness', 'LOUDNESS'],
['timer', 'TIMER'],
2016-07-11 11:00:33 -04:00
['video motion', 'VIDEOMOTION']
]
},
{
"type": "input_value",
"name": "VALUE"
}
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
Blockly.Blocks['event_broadcast'] = {
/**
* Block to send a broadcast.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_broadcast",
"message0": "broadcast %1",
"args0": [
{
"type": "field_dropdown",
"name": "BROADCAST_OPTION",
"options": [
['message1', 'MESSAGE1'],
['message2', 'MESSAGE2'],
['new message', 'NEW_MESSAGE']
]
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
Blockly.Blocks['event_broadcastandwait'] = {
/**
* Block to send a broadcast.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "broadcast %1 and wait",
"args0": [
{
"type": "field_dropdown",
"name": "BROADCAST_OPTION",
"options": [
['message1', 'MESSAGE1'],
['message2', 'MESSAGE2'],
['new message', 'NEW_MESSAGE']
]
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};
Blockly.Blocks['event_whenkeypressed'] = {
/**
* Block to send a broadcast.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_whenkeypressed",
"message0": "when %1 key pressed",
"args0": [
{
"type": "field_dropdown",
"name": "KEY_OPTION",
"options": [
['space', 'SPACE'],
['left arrow', 'LEFTARROW'],
['right arrow', 'RIGHTARROW'],
['down arrow', 'DOWNARROW'],
['up arrow', 'UPARROW'],
['any', 'ANY'],
['a', 'A'],
['b', 'B'],
['c', 'C'],
['d', 'D'],
['e', 'E'],
['f', 'F'],
['g', 'G'],
['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'],
['9', 'NINE']
]
}
],
"inputsInline": true,
"nextStatement": null,
"colour": Blockly.Colours.event.primary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary
});
}
};