scratch-blocks/blocks_vertical/event.js

330 lines
8.2 KiB
JavaScript
Raw Permalink 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');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
2018-06-05 19:34:03 -04:00
Blockly.Blocks['event_whentouchingobject'] = {
/**
* Block for when a sprite is touching an object.
2018-06-05 19:34:03 -04:00
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENTOUCHINGOBJECT,
2018-06-05 19:34:03 -04:00
"args0": [
{
"type": "input_value",
"name": "TOUCHINGOBJECTMENU"
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};
Blockly.Blocks['event_touchingobjectmenu'] = {
/**
* "Touching [Object]" Block Menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "TOUCHINGOBJECTMENU",
"options": [
[Blockly.Msg.SENSING_TOUCHINGOBJECT_POINTER, '_mouse_'],
[Blockly.Msg.SENSING_TOUCHINGOBJECT_EDGE, '_edge_']
]
}
],
"extensions": ["colours_event", "output_string"]
});
}
};
Blockly.Blocks['event_whenflagclicked'] = {
/**
* Block for when flag clicked.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_whenflagclicked",
"message0": Blockly.Msg.EVENT_WHENFLAGCLICKED,
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "green-flag.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,
2017-08-09 10:13:38 -04:00
"alt": "flag"
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};
Blockly.Blocks['event_whenthisspriteclicked'] = {
/**
* Block for when this sprite clicked.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENTHISSPRITECLICKED,
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};
Blockly.Blocks['event_whenstageclicked'] = {
/**
* Block for when the stage is clicked.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENSTAGECLICKED,
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};
Blockly.Blocks['event_whenbroadcastreceived'] = {
/**
* Block for when broadcast received.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_whenbroadcastreceived",
"message0": Blockly.Msg.EVENT_WHENBROADCASTRECEIVED,
"args0": [
{
"type": "field_variable",
"name": "BROADCAST_OPTION",
"variableTypes": [Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};
Blockly.Blocks['event_whenbackdropswitchesto'] = {
/**
* Block for when the current backdrop switched to a selected backdrop.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENBACKDROPSWITCHESTO,
"args0": [
{
"type": "field_dropdown",
"name": "BACKDROP",
"options": [
2018-05-02 15:58:36 -07:00
['backdrop1', 'BACKDROP1']
]
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};
Blockly.Blocks['event_whengreaterthan'] = {
/**
* Block for when loudness/timer/video motion is greater than the value.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENGREATERTHAN,
"args0": [
{
"type": "field_dropdown",
"name": "WHENGREATERTHANMENU",
"options": [
[Blockly.Msg.EVENT_WHENGREATERTHAN_LOUDNESS, 'LOUDNESS'],
[Blockly.Msg.EVENT_WHENGREATERTHAN_TIMER, 'TIMER']
]
},
{
"type": "input_value",
"name": "VALUE"
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};
Blockly.Blocks['event_broadcast_menu'] = {
/**
* Broadcast drop-down menu.
* @this Blockly.Block
*/
init: function() {
2018-05-02 15:58:36 -07:00
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_variable",
"name": "BROADCAST_OPTION",
"variableTypes":[Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE],
"variable": Blockly.Msg.DEFAULT_BROADCAST_MESSAGE_NAME
}
],
"colour": Blockly.Colours.event.secondary,
"colourSecondary": Blockly.Colours.event.secondary,
"colourTertiary": Blockly.Colours.event.tertiary,
"colourQuaternary": Blockly.Colours.event.quaternary,
2018-05-02 15:58:36 -07:00
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['event_broadcast'] = {
/**
* Block to send a broadcast.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_broadcast",
"message0": Blockly.Msg.EVENT_BROADCAST,
"args0": [
{
"type": "input_value",
"name": "BROADCAST_INPUT"
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_statement"]
});
}
};
Blockly.Blocks['event_broadcastandwait'] = {
/**
* Block to send a broadcast.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_BROADCASTANDWAIT,
"args0": [
{
"type":"input_value",
"name":"BROADCAST_INPUT"
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_statement"]
});
}
};
Blockly.Blocks['event_whenkeypressed'] = {
/**
* Block to send a broadcast.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "event_whenkeypressed",
"message0": Blockly.Msg.EVENT_WHENKEYPRESSED,
"args0": [
{
"type": "field_dropdown",
"name": "KEY_OPTION",
"options": [
[Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'],
[Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'],
2018-12-12 16:20:02 -05:00
[Blockly.Msg.EVENT_WHENKEYPRESSED_DOWN, 'down arrow'],
[Blockly.Msg.EVENT_WHENKEYPRESSED_RIGHT, 'right arrow'],
[Blockly.Msg.EVENT_WHENKEYPRESSED_LEFT, 'left arrow'],
[Blockly.Msg.EVENT_WHENKEYPRESSED_ANY, 'any'],
['a', 'a'],
['b', 'b'],
['c', 'c'],
['d', 'd'],
['e', 'e'],
['f', 'f'],
['g', 'g'],
['h', 'h'],
['i', 'i'],
['j', 'j'],
['k', 'k'],
['l', 'l'],
['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'],
['z', 'z'],
['0', '0'],
['1', '1'],
['2', '2'],
['3', '3'],
['4', '4'],
['5', '5'],
['6', '6'],
['7', '7'],
['8', '8'],
['9', '9']
]
}
],
"category": Blockly.Categories.event,
"extensions": ["colours_event", "shape_hat"]
});
}
};