Initial commit of 001code-html Scratch frontend project.

Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-16 15:37:45 +08:00
commit 6e0a1fbcbb
11350 changed files with 965674 additions and 0 deletions

View File

@@ -0,0 +1,532 @@
/**
* @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.control');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['control_forever'] = {
/**
* Block for repeat n times (external number).
* https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#5eke39
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_forever",
"message0": Blockly.Msg.CONTROL_FOREVER,
"message1": "%1", // Statement
"message2": "%1", // Icon
"lastDummyAlign2": "RIGHT",
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"args2": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
"flip_rtl": true
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_end"]
});
}
};
Blockly.Blocks['control_repeat'] = {
/**
* Block for repeat n times (external number).
* https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#so57n9
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_repeat",
"message0": Blockly.Msg.CONTROL_REPEAT,
"message1": "%1", // Statement
"message2": "%1", // Icon
"lastDummyAlign2": "RIGHT",
"args0": [
{
"type": "input_value",
"name": "TIMES"
}
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"args2": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
"flip_rtl": true
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_if'] = {
/**
* Block for if-then.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"type": "control_if",
"message0": Blockly.Msg.CONTROL_IF,
"message1": "%1", // Statement
"args0": [
{
"type": "input_value",
"name": "CONDITION",
"check": "Boolean"
}
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_if_else'] = {
/**
* Block for if-else.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"type": "control_if_else",
"message0": Blockly.Msg.CONTROL_IF,
"message1": "%1",
"message2": Blockly.Msg.CONTROL_ELSE,
"message3": "%1",
"args0": [
{
"type": "input_value",
"name": "CONDITION",
"check": "Boolean"
}
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"args3": [
{
"type": "input_statement",
"name": "SUBSTACK2"
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_stop'] = {
/**
* Block for stop all scripts.
* @this Blockly.Block
*/
init: function() {
var ALL_SCRIPTS = 'all';
var THIS_SCRIPT = 'this script';
var OTHER_SCRIPTS = 'other scripts in sprite';
var stopDropdown = new Blockly.FieldDropdown(function() {
if (this.sourceBlock_ &&
this.sourceBlock_.nextConnection &&
this.sourceBlock_.nextConnection.isConnected()) {
return [
[Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS]
];
}
return [[Blockly.Msg.CONTROL_STOP_ALL, ALL_SCRIPTS],
[Blockly.Msg.CONTROL_STOP_THIS, THIS_SCRIPT],
[Blockly.Msg.CONTROL_STOP_OTHER, OTHER_SCRIPTS]
];
}, function(option) {
// Create an event group to keep field value and mutator in sync
// Return null at the end because setValue is called here already.
Blockly.Events.setGroup(true);
var oldMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom());
this.sourceBlock_.setNextStatement(option == OTHER_SCRIPTS);
var newMutation = Blockly.Xml.domToText(this.sourceBlock_.mutationToDom());
Blockly.Events.fire(new Blockly.Events.BlockChange(this.sourceBlock_,
'mutation', null, oldMutation, newMutation));
this.setValue(option);
Blockly.Events.setGroup(false);
return null;
});
this.appendDummyInput()
.appendField(Blockly.Msg.CONTROL_STOP)
.appendField(stopDropdown, 'STOP_OPTION');
this.setCategory(Blockly.Categories.control);
this.setColour(Blockly.Colours.control.primary,
Blockly.Colours.control.secondary,
Blockly.Colours.control.tertiary,
Blockly.Colours.control.quaternary
);
this.setPreviousStatement(true);
},
mutationToDom: function() {
var container = document.createElement('mutation');
container.setAttribute('hasnext', this.nextConnection != null);
return container;
},
domToMutation: function(xmlElement) {
var hasNext = (xmlElement.getAttribute('hasnext') == 'true');
this.setNextStatement(hasNext);
}
};
Blockly.Blocks['control_wait'] = {
/**
* Block to wait (pause) stack.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_wait",
"message0": Blockly.Msg.CONTROL_WAIT,
"args0": [
{
"type": "input_value",
"name": "DURATION"
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_wait_until'] = {
/**
* Block to wait until a condition becomes true.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_WAITUNTIL,
"args0": [
{
"type": "input_value",
"name": "CONDITION",
"check": "Boolean"
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_repeat_until'] = {
/**
* Block to repeat until a condition becomes true.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_REPEATUNTIL,
"message1": "%1",
"message2": "%1",
"lastDummyAlign2": "RIGHT",
"args0": [
{
"type": "input_value",
"name": "CONDITION",
"check": "Boolean"
}
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"args2": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
"flip_rtl": true
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_while'] = {
/**
* Block to repeat until a condition becomes false.
* (This is an obsolete "hacked" block, for compatibility with 2.0.)
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_WHILE,
"message1": "%1",
"message2": "%1",
"lastDummyAlign2": "RIGHT",
"args0": [
{
"type": "input_value",
"name": "CONDITION",
"check": "Boolean"
}
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"args2": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "repeat.svg",
"width": 24,
"height": 24,
"alt": "*",
"flip_rtl": true
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_for_each'] = {
/**
* Block for for-each. This is an obsolete block that is implemented for
* compatibility with Scratch 2.0 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"type": "control_for_each",
"message0": Blockly.Msg.CONTROL_FOREACH,
"message1": "%1",
"args0": [
{
"type": "field_variable",
"name": "VARIABLE"
},
{
"type": "input_value",
"name": "VALUE"
}
],
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_start_as_clone'] = {
/**
* Block for "when I start as a clone" hat.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_start_as_clone",
"message0": Blockly.Msg.CONTROL_STARTASCLONE,
"args0": [
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_hat"]
});
}
};
Blockly.Blocks['control_create_clone_of_menu'] = {
/**
* Create-clone drop-down menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "CLONE_OPTION",
"options": [
[Blockly.Msg.CONTROL_CREATECLONEOF_MYSELF, '_myself_']
]
}
],
"extensions": ["colours_control", "output_string"]
});
}
};
Blockly.Blocks['control_create_clone_of'] = {
/**
* Block for "create clone of..."
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "control_start_as_clone",
"message0": Blockly.Msg.CONTROL_CREATECLONEOF,
"args0": [
{
"type": "input_value",
"name": "CLONE_OPTION"
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_delete_this_clone'] = {
/**
* Block for "delete this clone."
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_DELETETHISCLONE,
"args0": [
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_end"]
});
}
};
Blockly.Blocks['control_get_counter'] = {
/**
* Block to get the counter value. This is an obsolete block that is
* implemented for compatibility with Scratch 2.0 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_COUNTER,
"category": Blockly.Categories.control,
"extensions": ["colours_control", "output_number"]
});
}
};
Blockly.Blocks['control_incr_counter'] = {
/**
* Block to add one to the counter value. This is an obsolete block that is
* implemented for compatibility with Scratch 2.0 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_INCRCOUNTER,
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_clear_counter'] = {
/**
* Block to clear the counter value. This is an obsolete block that is
* implemented for compatibility with Scratch 2.0 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_CLEARCOUNTER,
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};
Blockly.Blocks['control_all_at_once'] = {
/**
* Block to run the contained script. This is an obsolete block that is
* implemented for compatibility with Scratch 2.0 projects. Note that
* this was originally designed to run all of the contained blocks
* (sequentially, like normal) within a single frame, but this feature
* was removed in place of custom blocks marked "run without screen
* refresh". The "all at once" block was changed to run the contained
* blocks ordinarily, functioning the same way as an "if" block with a
* reporter that is always true (e.g. "if 1 = 1"). Also note that the
* Scratch 2.0 spec for this block is "warpSpeed", but the label shows
* "all at once".
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.CONTROL_ALLATONCE,
"message1": "%1", // Statement
"args1": [
{
"type": "input_statement",
"name": "SUBSTACK"
}
],
"category": Blockly.Categories.control,
"extensions": ["colours_control", "shape_statement"]
});
}
};

View File

@@ -0,0 +1,666 @@
/**
* @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.data');
goog.provide('Blockly.Constants.Data');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['data_variable'] = {
/**
* Block of Variables
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"lastDummyAlign0": "CENTRE",
"args0": [
{
"type": "field_variable_getter",
"text": "",
"name": "VARIABLE",
"variableType": ""
}
],
"category": Blockly.Categories.data,
"checkboxInFlyout": true,
"extensions": ["contextMenu_getVariableBlock", "colours_data", "output_string"]
});
}
};
Blockly.Blocks['data_setvariableto'] = {
/**
* Block to set variable to a certain value
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_SETVARIABLETO,
"args0": [
{
"type": "field_variable",
"name": "VARIABLE"
},
{
"type": "input_value",
"name": "VALUE"
}
],
"category": Blockly.Categories.data,
"extensions": ["colours_data", "shape_statement"]
});
}
};
Blockly.Blocks['data_changevariableby'] = {
/**
* Block to change variable by a certain value
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_CHANGEVARIABLEBY,
"args0": [
{
"type": "field_variable",
"name": "VARIABLE"
},
{
"type": "input_value",
"name": "VALUE"
}
],
"category": Blockly.Categories.data,
"extensions": ["colours_data", "shape_statement"]
});
}
};
Blockly.Blocks['data_showvariable'] = {
/**
* Block to show a variable
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_SHOWVARIABLE,
"args0": [
{
"type": "field_variable",
"name": "VARIABLE"
}
],
"previousStatement": null,
"nextStatement": null,
"category": Blockly.Categories.data,
"extensions": ["colours_data"]
});
}
};
Blockly.Blocks['data_hidevariable'] = {
/**
* Block to hide a variable
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_HIDEVARIABLE,
"args0": [
{
"type": "field_variable",
"name": "VARIABLE"
}
],
"previousStatement": null,
"nextStatement": null,
"category": Blockly.Categories.data,
"extensions": ["colours_data"]
});
}
};
Blockly.Blocks['data_listcontents'] = {
/**
* List reporter.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_variable_getter",
"text": "",
"name": "LIST",
"variableType": Blockly.LIST_VARIABLE_TYPE
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["contextMenu_getListBlock", "colours_data_lists", "output_string"],
"checkboxInFlyout": true
});
}
};
Blockly.Blocks['data_listindexall'] = {
/**
* List index menu, with all option.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_numberdropdown",
"name": "INDEX",
"value": "1",
"min": 1,
"precision": 1,
"options": [
["1", "1"],
[Blockly.Msg.DATA_INDEX_LAST, "last"],
[Blockly.Msg.DATA_INDEX_ALL, "all"]
]
}
],
"category": Blockly.Categories.data,
"extensions": ["colours_textfield", "output_string"]
});
}
};
Blockly.Blocks['data_listindexrandom'] = {
/**
* List index menu, with random option.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_numberdropdown",
"name": "INDEX",
"value": "1",
"min": 1,
"precision": 1,
"options": [
["1", "1"],
[Blockly.Msg.DATA_INDEX_LAST, "last"],
[Blockly.Msg.DATA_INDEX_RANDOM, "random"]
]
}
],
"category": Blockly.Categories.data,
"extensions": ["colours_textfield", "output_string"]
});
}
};
Blockly.Blocks['data_addtolist'] = {
/**
* Block to add item to list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_ADDTOLIST,
"args0": [
{
"type": "input_value",
"name": "ITEM"
},
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};
Blockly.Blocks['data_deleteoflist'] = {
/**
* Block to delete item from list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_DELETEOFLIST,
"args0": [
{
"type": "input_value",
"name": "INDEX"
},
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};
Blockly.Blocks['data_deletealloflist'] = {
/**
* Block to delete all items from list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_DELETEALLOFLIST,
"args0": [
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};
Blockly.Blocks['data_insertatlist'] = {
/**
* Block to insert item to list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_INSERTATLIST,
"args0": [
{
"type": "input_value",
"name": "ITEM"
},
{
"type": "input_value",
"name": "INDEX"
},
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};
Blockly.Blocks['data_replaceitemoflist'] = {
/**
* Block to insert item to list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_REPLACEITEMOFLIST,
"args0": [
{
"type": "input_value",
"name": "INDEX"
},
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
},
{
"type": "input_value",
"name": "ITEM"
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};
Blockly.Blocks['data_itemoflist'] = {
/**
* Block for reporting item of list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_ITEMOFLIST,
"args0": [
{
"type": "input_value",
"name": "INDEX"
},
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"output": null,
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists"],
"outputShape": Blockly.OUTPUT_SHAPE_ROUND
});
}
};
Blockly.Blocks['data_itemnumoflist'] = {
/**
* Block for reporting the item # of a string in a list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_ITEMNUMOFLIST,
"args0": [
{
"type": "input_value",
"name": "ITEM"
},
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"output": null,
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists"],
"outputShape": Blockly.OUTPUT_SHAPE_ROUND
});
}
};
Blockly.Blocks['data_lengthoflist'] = {
/**
* Block for reporting length of list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_LENGTHOFLIST,
"args0": [
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "output_number"]
});
}
};
Blockly.Blocks['data_listcontainsitem'] = {
/**
* Block to report whether list contains item.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_LISTCONTAINSITEM,
"args0": [
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
},
{
"type": "input_value",
"name": "ITEM"
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "output_boolean"]
});
}
};
Blockly.Blocks['data_showlist'] = {
/**
* Block to show a list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_SHOWLIST,
"args0": [
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};
Blockly.Blocks['data_hidelist'] = {
/**
* Block to hide a list.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.DATA_HIDELIST,
"args0": [
{
"type": "field_variable",
"name": "LIST",
"variableTypes": [Blockly.LIST_VARIABLE_TYPE]
}
],
"category": Blockly.Categories.dataLists,
"extensions": ["colours_data_lists", "shape_statement"]
});
}
};
/**
* Mixin to add a context menu for a data_variable block. It adds one item for
* each variable defined on the workspace.
* @mixin
* @augments Blockly.Block
* @package
* @readonly
*/
Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_VARIABLE_MIXIN = {
/**
* Add context menu option to change the selected variable.
* @param {!Array} options List of menu options to add to.
* @this Blockly.Block
*/
customContextMenu: function(options) {
var fieldName = 'VARIABLE';
if (this.isCollapsed()) {
return;
}
var currentVarName = this.getField(fieldName).text_;
if (!this.isInFlyout) {
var variablesList = this.workspace.getVariablesOfType('');
variablesList.sort(function(a, b) {
return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
});
for (var i = 0; i < variablesList.length; i++) {
var varName = variablesList[i].name;
if (varName == currentVarName) continue;
var option = {enabled: true};
option.text = varName;
option.callback =
Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
variablesList[i].getId(), fieldName);
options.push(option);
}
} else {
var renameOption = {
text: Blockly.Msg.RENAME_VARIABLE,
enabled: true,
callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
fieldName)
};
var deleteOption = {
text: Blockly.Msg.DELETE_VARIABLE.replace('%1', currentVarName),
enabled: true,
callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
fieldName)
};
options.push(renameOption);
options.push(deleteOption);
}
}
};
Blockly.Extensions.registerMixin('contextMenu_getVariableBlock',
Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_VARIABLE_MIXIN);
/**
* Mixin to add a context menu for a data_listcontents block. It adds one item for
* each list defined on the workspace.
* @mixin
* @augments Blockly.Block
* @package
* @readonly
*/
Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_LIST_MIXIN = {
/**
* Add context menu option to change the selected list.
* @param {!Array} options List of menu options to add to.
* @this Blockly.Block
*/
customContextMenu: function(options) {
var fieldName = 'LIST';
if (this.isCollapsed()) {
return;
}
var currentVarName = this.getField(fieldName).text_;
if (!this.isInFlyout) {
var variablesList = this.workspace.getVariablesOfType('list');
variablesList.sort(function(a, b) {
return Blockly.scratchBlocksUtils.compareStrings(a.name, b.name);
});
for (var i = 0; i < variablesList.length; i++) {
var varName = variablesList[i].name;
if (varName == currentVarName) continue;
var option = {enabled: true};
option.text = varName;
option.callback =
Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY(this,
variablesList[i].getId(), fieldName);
options.push(option);
}
} else {
var renameOption = {
text: Blockly.Msg.RENAME_LIST,
enabled: true,
callback: Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY(this,
fieldName)
};
var deleteOption = {
text: Blockly.Msg.DELETE_LIST.replace('%1', currentVarName),
enabled: true,
callback: Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY(this,
fieldName)
};
options.push(renameOption);
options.push(deleteOption);
}
}
};
Blockly.Extensions.registerMixin('contextMenu_getListBlock',
Blockly.Constants.Data.CUSTOM_CONTEXT_MENU_GET_LIST_MIXIN);
/**
* Callback factory for dropdown menu options associated with a variable getter
* block. Each variable on the workspace gets its own item in the dropdown
* menu, and clicking on that item changes the text of the field on the source
* block.
* @param {!Blockly.Block} block The block to update.
* @param {string} id The id of the variable to set on this block.
* @param {string} fieldName The name of the field to update on the block.
* @return {!function()} A function that updates the block with the new name.
*/
Blockly.Constants.Data.VARIABLE_OPTION_CALLBACK_FACTORY = function(block,
id, fieldName) {
return function() {
var variableField = block.getField(fieldName);
if (!variableField) {
console.log("Tried to get a variable field on the wrong type of block.");
}
variableField.setValue(id);
};
};
/**
* Callback for rename variable dropdown menu option associated with a
* variable getter block.
* @param {!Blockly.Block} block The block with the variable to rename.
* @param {string} fieldName The name of the field to inspect on the block.
* @return {!function()} A function that renames the variable.
*/
Blockly.Constants.Data.RENAME_OPTION_CALLBACK_FACTORY = function(block,
fieldName) {
return function() {
var workspace = block.workspace;
var variable = block.getField(fieldName).getVariable();
Blockly.Variables.renameVariable(workspace, variable);
};
};
/**
* Callback for delete variable dropdown menu option associated with a
* variable getter block.
* @param {!Blockly.Block} block The block with the variable to delete.
* @param {string} fieldName The name of the field to inspect on the block.
* @return {!function()} A function that deletes the variable.
*/
Blockly.Constants.Data.DELETE_OPTION_CALLBACK_FACTORY = function(block,
fieldName) {
return function() {
var workspace = block.workspace;
var variable = block.getField(fieldName).getVariable();
workspace.deleteVariableById(variable.getId());
};
};

View File

@@ -0,0 +1,569 @@
/**
* @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.defaultToolbox');
goog.require('Blockly.Blocks');
/**
* @fileoverview Provide a default toolbox XML.
*/
/**
* NOTE: This is only used in the scratch-blocks development playground!
* The XML here is overridden by scratch-gui.
*/
Blockly.Blocks.defaultToolbox = '<xml id="toolbox-categories" style="display: none">' +
'<category name="%{BKY_CATEGORY_MOTION}" id="motion" colour="#4C97FF" secondaryColour="#3373CC">' +
'<block type="motion_movesteps" id="motion_movesteps">' +
'<value name="STEPS">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_turnright" id="motion_turnright">' +
'<value name="DEGREES">' +
'<shadow type="math_number">' +
'<field name="NUM">15</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_turnleft" id="motion_turnleft">' +
'<value name="DEGREES">' +
'<shadow type="math_number">' +
'<field name="NUM">15</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_pointindirection" id="motion_pointindirection">' +
'<value name="DIRECTION">' +
'<shadow type="math_angle">' +
'<field name="NUM">90</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_pointtowards" id="motion_pointtowards">' +
'<value name="TOWARDS">' +
'<shadow type="motion_pointtowards_menu">' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_gotoxy" id="motion_gotoxy">' +
'<value name="X">' +
'<shadow id="movex" type="math_number">' +
'<field name="NUM">0</field>' +
'</shadow>' +
'</value>' +
'<value name="Y">' +
'<shadow id="movey" type="math_number">' +
'<field name="NUM">0</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_goto" id="motion_goto">' +
'<value name="TO">' +
'<shadow type="motion_goto_menu">' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_glidesecstoxy" id="motion_glidesecstoxy">' +
'<value name="SECS">' +
'<shadow type="math_number">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'<value name="X">' +
'<shadow id="glidex" type="math_number">' +
'<field name="NUM">0</field>' +
'</shadow>' +
'</value>' +
'<value name="Y">' +
'<shadow id="glidey" type="math_number">' +
'<field name="NUM">0</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_glideto" id="motion_glideto">' +
'<value name="SECS">' +
'<shadow type="math_number">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'<value name="TO">' +
'<shadow type="motion_glideto_menu">' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_changexby" id="motion_changexby">' +
'<value name="DX">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_setx" id="motion_setx">' +
'<value name="X">' +
'<shadow id="setx" type="math_number">' +
'<field name="NUM">0</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_changeyby" id="motion_changeyby">' +
'<value name="DY">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_sety" id="motion_sety">' +
'<value name="Y">' +
'<shadow id="sety" type="math_number">' +
'<field name="NUM">0</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="motion_ifonedgebounce" id="motion_ifonedgebounce"></block>' +
'<block type="motion_setrotationstyle" id="motion_setrotationstyle"></block>' +
'<block type="motion_xposition" id="motion_xposition"></block>' +
'<block type="motion_yposition" id="motion_yposition"></block>' +
'<block type="motion_direction" id="motion_direction"></block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_LOOKS}" id="looks" colour="#9966FF" secondaryColour="#774DCB">' +
'<block type="looks_show" id="looks_show"></block>' +
'<block type="looks_hide" id="looks_hide"></block>' +
'<block type="looks_switchcostumeto" id="looks_switchcostumeto">' +
'<value name="COSTUME">' +
'<shadow type="looks_costume"></shadow>' +
'</value>' +
'</block>' +
'<block type="looks_nextcostume" id="looks_nextcostume"></block>' +
'<block type="looks_nextbackdrop" id="looks_nextbackdrop"></block>' +
'<block type="looks_switchbackdropto" id="looks_switchbackdropto">' +
'<value name="BACKDROP">' +
'<shadow type="looks_backdrops"></shadow>' +
'</value>' +
'</block>' +
'<block type="looks_switchbackdroptoandwait" id="looks_switchbackdroptoandwait">' +
'<value name="BACKDROP">' +
'<shadow type="looks_backdrops"></shadow>' +
'</value>' +
'</block>' +
'<block type="looks_changeeffectby" id="looks_changeeffectby">' +
'<value name="CHANGE">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="looks_seteffectto" id="looks_seteffectto">' +
'<value name="VALUE">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="looks_cleargraphiceffects" id="looks_cleargraphiceffects"></block>' +
'<block type="looks_changesizeby" id="looks_changesizeby">' +
'<value name="CHANGE">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="looks_setsizeto" id="looks_setsizeto">' +
'<value name="SIZE">' +
'<shadow type="math_number">' +
'<field name="NUM">100</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="looks_gotofrontback" id="looks_gotofrontback"></block>' +
'<block type="looks_goforwardbackwardlayers" id="looks_goforwardbackwardlayers">' +
'<value name="NUM">' +
'<shadow type="math_integer">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="looks_costumenumbername" id="looks_costumenumbername"></block>' +
'<block type="looks_backdropnumbername" id="looks_backdropnumbername"></block>' +
'<block type="looks_size" id="looks_size"></block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_SOUND}" id="sound" colour="#D65CD6" secondaryColour="#BD42BD">' +
'<block type="sound_play" id="sound_play">' +
'<value name="SOUND_MENU">' +
'<shadow type="sound_sounds_menu"></shadow>' +
'</value>' +
'</block>' +
'<block type="sound_playuntildone" id="sound_playuntildone">' +
'<value name="SOUND_MENU">' +
'<shadow type="sound_sounds_menu"></shadow>' +
'</value>' +
'</block>' +
'<block type="sound_stopallsounds" id="sound_stopallsounds"></block>' +
'<block type="sound_changeeffectby" id="sound_changeeffectby">' +
'<value name="VALUE">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="sound_seteffectto" id="sound_seteffectto">' +
'<value name="VALUE">' +
'<shadow type="math_number">' +
'<field name="NUM">100</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="sound_cleareffects" id="sound_cleareffects"></block>' +
'<block type="sound_changevolumeby" id="sound_changevolumeby">' +
'<value name="VOLUME">' +
'<shadow type="math_number">' +
'<field name="NUM">-10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="sound_setvolumeto" id="sound_setvolumeto">' +
'<value name="VOLUME">' +
'<shadow type="math_number">' +
'<field name="NUM">100</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="sound_volume" id="sound_volume"></block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_EVENTS}" id="events" colour="#FFD500" secondaryColour="#CC9900">' +
'<block type="event_whenflagclicked" id="event_whenflagclicked"></block>' +
'<block type="event_whenkeypressed" id="event_whenkeypressed">' +
'</block>' +
'<block type="event_whenthisspriteclicked" id="event_whenthisspriteclicked"></block>' +
'<block type="event_whenbackdropswitchesto" id="event_whenbackdropswitchesto">' +
'</block>' +
'<block type="event_whengreaterthan" id="event_whengreaterthan">' +
'<value name="VALUE">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="event_whenbroadcastreceived" id="event_whenbroadcastreceived">' +
'</block>' +
'<block type="event_broadcast" id="event_broadcast">' +
'<value name="BROADCAST_INPUT">' +
'<shadow type="event_broadcast_menu"></shadow>' +
'</value>' +
'</block>' +
'<block type="event_broadcastandwait" id="event_broadcastandwait">' +
'<value name="BROADCAST_INPUT">' +
'<shadow type="event_broadcast_menu"></shadow>' +
'</value>' +
'</block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_CONTROL}" id="control" colour="#FFAB19" secondaryColour="#CF8B17">' +
'<block type="control_wait" id="control_wait">' +
'<value name="DURATION">' +
'<shadow type="math_positive_number">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="control_repeat" id="control_repeat">' +
'<value name="TIMES">' +
'<shadow type="math_whole_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="control_forever" id="control_forever"></block>' +
'<block type="control_if" id="control_if"></block>' +
'<block type="control_if_else" id="control_if_else"></block>' +
'<block type="control_wait_until" id="control_wait_until"></block>' +
'<block type="control_repeat_until" id="control_repeat_until"></block>' +
'<block type="control_stop" id="control_stop"></block>' +
'<block type="control_start_as_clone" id="control_start_as_clone"></block>' +
'<block type="control_create_clone_of" id="control_create_clone_of">' +
'<value name="CLONE_OPTION">' +
'<shadow type="control_create_clone_of_menu"></shadow>' +
'</value>' +
'</block>' +
'<block type="control_delete_this_clone" id="control_delete_this_clone"></block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_SENSING}" id="sensing" colour="#4CBFE6" secondaryColour="#2E8EB8">' +
'<block type="sensing_touchingobject" id="sensing_touchingobject">' +
'<value name="TOUCHINGOBJECTMENU">' +
'<shadow type="sensing_touchingobjectmenu"></shadow>' +
'</value>' +
'</block>' +
'<block type="sensing_touchingcolor" id="sensing_touchingcolor">' +
'<value name="COLOR">' +
'<shadow type="colour_picker"></shadow>' +
'</value>' +
'</block>' +
'<block type="sensing_coloristouchingcolor" id="sensing_coloristouchingcolor">' +
'<value name="COLOR">' +
'<shadow type="colour_picker"></shadow>' +
'</value>' +
'<value name="COLOR2">' +
'<shadow type="colour_picker"></shadow>' +
'</value>' +
'</block>' +
'<block type="sensing_distanceto" id="sensing_distanceto">' +
'<value name="DISTANCETOMENU">' +
'<shadow type="sensing_distancetomenu"></shadow>' +
'</value>' +
'</block>' +
'<block type="sensing_keypressed" id="sensing_keypressed">' +
'<value name="KEY_OPTION">' +
'<shadow type="sensing_keyoptions"></shadow>' +
'</value>' +
'</block>' +
'<block type="sensing_mousedown" id="sensing_mousedown"></block>' +
'<block type="sensing_mousex" id="sensing_mousex"></block>' +
'<block type="sensing_mousey" id="sensing_mousey"></block>' +
'<block type="sensing_setdragmode" id="sensing_setdragmode"></block>' +
'<block type="sensing_loudness" id="sensing_loudness"></block>' +
'<block type="sensing_timer" id="sensing_timer"></block>' +
'<block type="sensing_resettimer" id="sensing_resettimer"></block>' +
'<block type="sensing_of" id="sensing_of">' +
'<value name="OBJECT">' +
'<shadow type="sensing_of_object_menu"></shadow>' +
'</value>' +
'</block>' +
'<block type="sensing_current" id="sensing_current"></block>' +
'<block type="sensing_dayssince2000" id="sensing_dayssince2000"></block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_OPERATORS}" id="operators" colour="#40BF4A" secondaryColour="#389438">' +
'<block type="operator_add" id="operator_add">' +
'<value name="NUM1">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'<value name="NUM2">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_subtract" id="operator_subtract">' +
'<value name="NUM1">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'<value name="NUM2">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_multiply" id="operator_multiply">' +
'<value name="NUM1">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'<value name="NUM2">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_divide" id="operator_divide">' +
'<value name="NUM1">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'<value name="NUM2">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_random" id="operator_random">' +
'<value name="FROM">' +
'<shadow type="math_number">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'<value name="TO">' +
'<shadow type="math_number">' +
'<field name="NUM">10</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_lt" id="operator_lt">' +
'<value name="OPERAND1">' +
'<shadow type="text">' +
'<field name="TEXT"></field>' +
'</shadow>' +
'</value>' +
'<value name="OPERAND2">' +
'<shadow type="text">' +
'<field name="TEXT"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_equals" id="operator_equals">' +
'<value name="OPERAND1">' +
'<shadow type="text">' +
'<field name="TEXT"></field>' +
'</shadow>' +
'</value>' +
'<value name="OPERAND2">' +
'<shadow type="text">' +
'<field name="TEXT"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_gt" id="operator_gt">' +
'<value name="OPERAND1">' +
'<shadow type="text">' +
'<field name="TEXT"></field>' +
'</shadow>' +
'</value>' +
'<value name="OPERAND2">' +
'<shadow type="text">' +
'<field name="TEXT"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_and" id="operator_and"></block>' +
'<block type="operator_or" id="operator_or"></block>' +
'<block type="operator_not" id="operator_not"></block>' +
'<block type="operator_join" id="operator_join">' +
'<value name="STRING1">' +
'<shadow type="text">' +
'<field name="TEXT">hello</field>' +
'</shadow>' +
'</value>' +
'<value name="STRING2">' +
'<shadow type="text">' +
'<field name="TEXT">world</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_letter_of" id="operator_letter_of">' +
'<value name="LETTER">' +
'<shadow type="math_whole_number">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'<value name="STRING">' +
'<shadow type="text">' +
'<field name="TEXT">world</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_length" id="operator_length">' +
'<value name="STRING">' +
'<shadow type="text">' +
'<field name="TEXT">world</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_contains" id="operator_contains">' +
'<value name="STRING1">' +
'<shadow type="text">' +
'<field name="TEXT">hello</field>' +
'</shadow>' +
'</value>' +
'<value name="STRING2">' +
'<shadow type="text">' +
'<field name="TEXT">world</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_mod" id="operator_mod">' +
'<value name="NUM1">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'<value name="NUM2">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_round" id="operator_round">' +
'<value name="NUM">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="operator_mathop" id="operator_mathop">' +
'<value name="NUM">' +
'<shadow type="math_number">' +
'<field name="NUM"></field>' +
'</shadow>' +
'</value>' +
'</block>' +
'</category>' +
'<category name="%{BKY_CATEGORY_VARIABLES}" id="data" colour="#FF8C1A" secondaryColour="#DB6E00" custom="VARIABLE">' +
'</category>' +
'<category name="%{BKY_CATEGORY_MYBLOCKS}" id="more" colour="#FF6680" secondaryColour="#FF4D6A" custom="PROCEDURE">' +
'</category>' +
'<category name="Extensions" id="extensions" colour="#FF6680" secondaryColour="#FF4D6A" ' +
'iconURI="../media/extensions/wedo2-block-icon.svg" showStatusButton="true">' +
'<block type="extension_pen_down" id="extension_pen_down"></block>' +
'<block type="extension_music_drum" id="extension_music_drum">' +
'<value name="NUMBER">' +
'<shadow type="math_number">' +
'<field name="NUM">1</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="extension_wedo_motor" id="extension_wedo_motor"></block>' +
'<block type="extension_wedo_hat" id="extension_wedo_hat"></block>' +
'<block type="extension_wedo_boolean" id="extension_wedo_boolean"></block>' +
'<block type="extension_wedo_tilt_reporter" id="extension_wedo_reporter">' +
'<value name="TILT">' +
'<shadow type="extension_wedo_tilt_menu"></shadow>' +
'</value>' +
'</block>' +
'<block type="extension_music_reporter" id="extension_music_reporter"></block>' +
'<block type="extension_microbit_display" id="extension_microbit_display">' +
'<value name="MATRIX">' +
'<shadow type="matrix">' +
'<field name="MATRIX">0101010101100010101000100</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'<block type="extension_music_play_note" id="extension_music_play_note">' +
'<value name="NOTE">' +
'<shadow type="note">' +
'<field name="NOTE">60</field>' +
'</shadow>' +
'</value>' +
'<value name="BEATS">' +
'<shadow type="math_number">' +
'<field name="NUM">0.25</field>' +
'</shadow>' +
'</value>' +
'</block>' +
'</category>' +
'</xml>';

View File

@@ -0,0 +1,329 @@
/**
* @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');
Blockly.Blocks['event_whentouchingobject'] = {
/**
* Block for when a sprite is touching an object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.EVENT_WHENTOUCHINGOBJECT,
"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",
// "width": 24,
// "height": 24,
// "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": [
['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() {
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,
"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'],
[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"]
});
}
};

View File

@@ -0,0 +1,294 @@
/**
* @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.extensions');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['extension_pen_down'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 pen down",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/pen-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "shape_statement", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_music_drum'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 play drum %3",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/music-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
},
{
"type": "input_value",
"name": "NUMBER"
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "shape_statement", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_wedo_motor'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 turn a motor %3",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
},
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg",
"width": 24,
"height": 24
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "shape_statement", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_wedo_hat'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 when I am wearing a hat",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "shape_hat", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_wedo_boolean'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 O RLY?",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "output_boolean", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_wedo_tilt_reporter'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 tilt angle %3",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/wedo2-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
},
{
"type": "input_value",
"name": "TILT"
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "output_number", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_wedo_tilt_menu'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "TILT",
"options": [
['Any', 'Any'],
['Whirl', 'Whirl'],
['South', 'South'],
['Back in time', 'Back in time']
]
}
],
"extensions": ["colours_more", "output_string"]
});
}
};
Blockly.Blocks['extension_music_reporter'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 hey now, you're an all-star",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/music-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
}
],
"category": Blockly.Categories.more,
"extensions": ["colours_more", "output_number", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_microbit_display'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 display %3",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/microbit-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
},
{
"type": "input_value",
"name": "MATRIX"
},
],
"category": Blockly.Categories.pen,
"extensions": ["colours_pen", "shape_statement", "scratch_extension"]
});
}
};
Blockly.Blocks['extension_music_play_note'] = {
/**
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1 %2 play note %3 for %4 beats",
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "extensions/music-block-icon.svg",
"width": 40,
"height": 40
},
{
"type": "field_vertical_separator"
},
{
"type": "input_value",
"name": "NOTE"
},
{
"type": "input_value",
"name": "BEATS"
}
],
"category": Blockly.Categories.pen,
"extensions": ["colours_pen", "shape_statement", "scratch_extension"]
});
}
};

View File

@@ -0,0 +1,663 @@
/**
* @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.looks');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['looks_sayforsecs'] = {
/**
* Block to say for some time.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SAYFORSECS,
"args0": [
{
"type": "input_value",
"name": "MESSAGE"
},
{
"type": "input_value",
"name": "SECS"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_say'] = {
/**
* Block to say.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SAY,
"args0": [
{
"type": "input_value",
"name": "MESSAGE"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['vehicle_move'] = {
/**
* Block to say.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.Vehicle_Move,
"args0": [
{
"type": "input_value",
"name": "STEPS"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['vehicle_turnright'] = {
/**
* Block to turn right.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.Vehicle_TURNRIGHT,
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg",
"width": 24,
"height": 24
},
{
"type": "input_value",
"name": "DEGREES"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['vehicle_turnleft'] = {
/**
* Block to turn left.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.Vehicle_TURNLEFT,
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "rotate-left.svg",
"width": 24,
"height": 24
},
{
"type": "input_value",
"name": "DEGREES"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_thinkforsecs'] = {
/**
* Block to think for some time.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_THINKFORSECS,
"args0": [
{
"type": "input_value",
"name": "MESSAGE"
},
{
"type": "input_value",
"name": "SECS"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_think'] = {
/**
* Block to think.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_THINK,
"args0": [
{
"type": "input_value",
"name": "MESSAGE"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_show'] = {
/**
* Show block.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SHOW,
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_hide'] = {
/**
* Hide block.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_HIDE,
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_hideallsprites'] = {
/**
* Hide-all-sprites block. Does not actually do anything. This is an
* obsolete block that is implemented for compatibility with Scratch 2.0
* projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_HIDEALLSPRITES,
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_changeeffectby'] = {
/**
* Block to change graphic effect.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_CHANGEEFFECTBY,
"args0": [
{
"type": "field_dropdown",
"name": "EFFECT",
"options": [
[Blockly.Msg.LOOKS_EFFECT_COLOR, 'COLOR'],
[Blockly.Msg.LOOKS_EFFECT_FISHEYE, 'FISHEYE'],
[Blockly.Msg.LOOKS_EFFECT_WHIRL, 'WHIRL'],
[Blockly.Msg.LOOKS_EFFECT_PIXELATE, 'PIXELATE'],
[Blockly.Msg.LOOKS_EFFECT_MOSAIC, 'MOSAIC'],
[Blockly.Msg.LOOKS_EFFECT_BRIGHTNESS, 'BRIGHTNESS'],
[Blockly.Msg.LOOKS_EFFECT_GHOST, 'GHOST']
]
},
{
"type": "input_value",
"name": "CHANGE"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_seteffectto'] = {
/**
* Block to set graphic effect.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SETEFFECTTO,
"args0": [
{
"type": "field_dropdown",
"name": "EFFECT",
"options": [
[Blockly.Msg.LOOKS_EFFECT_COLOR, 'COLOR'],
[Blockly.Msg.LOOKS_EFFECT_FISHEYE, 'FISHEYE'],
[Blockly.Msg.LOOKS_EFFECT_WHIRL, 'WHIRL'],
[Blockly.Msg.LOOKS_EFFECT_PIXELATE, 'PIXELATE'],
[Blockly.Msg.LOOKS_EFFECT_MOSAIC, 'MOSAIC'],
[Blockly.Msg.LOOKS_EFFECT_BRIGHTNESS, 'BRIGHTNESS'],
[Blockly.Msg.LOOKS_EFFECT_GHOST, 'GHOST']
]
},
{
"type": "input_value",
"name": "VALUE"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_cleargraphiceffects'] = {
/**
* Block to clear graphic effects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_CLEARGRAPHICEFFECTS,
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_changesizeby'] = {
/**
* Block to change size
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_CHANGESIZEBY,
"args0": [
{
"type": "input_value",
"name": "CHANGE"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_setsizeto'] = {
/**
* Block to set size
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SETSIZETO,
"args0": [
{
"type": "input_value",
"name": "SIZE"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_size'] = {
/**
* Block to report size
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SIZE,
"category": Blockly.Categories.looks,
"checkboxInFlyout": true,
"extensions": ["colours_looks", "output_number"]
});
}
};
Blockly.Blocks['looks_changestretchby'] = {
/**
* Block to change stretch. Does not actually do anything. This is an
* obsolete block that is implemented for compatibility with Scratch 1.4
* projects as well as 2.0 projects that still have the block.
* The "stretch" blocks were introduced in very early versions of Scratch,
* but their functionality was removed shortly later. They still appeared
* correctly up until (and including) Scratch 1.4 - as "change stretch by"
* and "set stretch to" - but were removed altogether in Scratch 2.0, and
* displayed as red "undefined" blocks. Some Scratch projects still contain
* these blocks, however, and they don't open in 3.0 unless the blocks
* actually exist (though they still don't funcitonally do anything).
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_CHANGESTRETCHBY,
"args0": [
{
"type": "input_value",
"name": "CHANGE"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_setstretchto'] = {
/**
* Block to set stretch. Does not actually do anything. This is an obsolete
* block that is implemented for compatibility with Scratch 1.4 projects
* (see looks_changestretchby).
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SETSTRETCHTO,
"args0": [
{
"type": "input_value",
"name": "STRETCH"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_costume'] = {
/**
* Costumes drop-down menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "COSTUME",
"options": [
['costume1', 'COSTUME1'],
['costume2', 'COSTUME2']
]
}
],
"colour": Blockly.Colours.looks.secondary,
"colourSecondary": Blockly.Colours.looks.secondary,
"colourTertiary": Blockly.Colours.looks.tertiary,
"colourQuaternary": Blockly.Colours.looks.quaternary,
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['looks_switchcostumeto'] = {
/**
* Block to switch the sprite's costume to the selected one.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SWITCHCOSTUMETO,
"args0": [
{
"type": "input_value",
"name": "COSTUME"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_nextcostume'] = {
/**
* Block to switch the sprite's costume to the next one.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_NEXTCOSTUME,
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_switchbackdropto'] = {
/**
* Block to switch the backdrop to the selected one.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SWITCHBACKDROPTO,
"args0": [
{
"type": "input_value",
"name": "BACKDROP"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_backdrops'] = {
/**
* Backdrop list
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"id": "looks_backdrops",
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "BACKDROP",
"options": [
['backdrop1', 'BACKDROP1']
]
}
],
"colour": Blockly.Colours.looks.secondary,
"colourSecondary": Blockly.Colours.looks.secondary,
"colourTertiary": Blockly.Colours.looks.tertiary,
"colourQuaternary": Blockly.Colours.looks.quaternary,
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['looks_gotofrontback'] = {
/**
* "Go to front/back" Block.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_GOTOFRONTBACK,
"args0": [
{
"type": "field_dropdown",
"name": "FRONT_BACK",
"options": [
[Blockly.Msg.LOOKS_GOTOFRONTBACK_FRONT, 'front'],
[Blockly.Msg.LOOKS_GOTOFRONTBACK_BACK, 'back']
]
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_goforwardbackwardlayers'] = {
/**
* "Go forward/backward [Number] Layers" Block.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_GOFORWARDBACKWARDLAYERS,
"args0": [
{
"type": "field_dropdown",
"name": "FORWARD_BACKWARD",
"options": [
[Blockly.Msg.LOOKS_GOFORWARDBACKWARDLAYERS_FORWARD, 'forward'],
[Blockly.Msg.LOOKS_GOFORWARDBACKWARDLAYERS_BACKWARD, 'backward']
]
},
{
"type": "input_value",
"name": "NUM"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_backdropnumbername'] = {
/**
* Block to report backdrop's number or name
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_BACKDROPNUMBERNAME,
"args0": [
{
"type": "field_dropdown",
"name": "NUMBER_NAME",
"options": [
[Blockly.Msg.LOOKS_NUMBERNAME_NUMBER, 'number'],
[Blockly.Msg.LOOKS_NUMBERNAME_NAME, 'name']
]
}
],
"category": Blockly.Categories.looks,
"checkboxInFlyout": true,
"extensions": ["colours_looks", "output_number"]
});
}
};
Blockly.Blocks['looks_costumenumbername'] = {
/**
* Block to report costume's number or name
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_COSTUMENUMBERNAME,
"args0": [
{
"type": "field_dropdown",
"name": "NUMBER_NAME",
"options": [
[Blockly.Msg.LOOKS_NUMBERNAME_NUMBER, 'number'],
[Blockly.Msg.LOOKS_NUMBERNAME_NAME, 'name']
]
}
],
"category": Blockly.Categories.looks,
"checkboxInFlyout": true,
"extensions": ["colours_looks", "output_number"]
});
}
};
Blockly.Blocks['looks_switchbackdroptoandwait'] = {
/**
* Block to switch the backdrop to the selected one and wait.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_SWITCHBACKDROPTOANDWAIT,
"args0": [
{
"type": "input_value",
"name": "BACKDROP"
}
],
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};
Blockly.Blocks['looks_nextbackdrop'] = {
/**
* Block to switch the backdrop to the next one.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.LOOKS_NEXTBACKDROP_BLOCK,
"category": Blockly.Categories.looks,
"extensions": ["colours_looks", "shape_statement"]
});
}
};

View File

@@ -0,0 +1,683 @@
/**
* @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.motion');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['motion_movesteps'] = {
/**
* Block to move steps.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_MOVESTEPS,
"args0": [
{
"type": "input_value",
"name": "STEPS"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_testblock'] = {
/**
* Block to move steps.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_MOVESTEPS,
"args0": [
{
"type": "input_value",
"name": "STEPS"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_move_f'] = {
/**
* Block to move steps.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_MOVEFOWRD,
"args0": [
{
"type": "input_value",
"name": "STEPS"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_move_b'] = {
/**
* Block to move steps.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_MOVEBACK,
"args0": [
{
"type": "input_value",
"name": "STEPS"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_turnright'] = {
/**
* Block to turn right.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_TURNRIGHT,
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "rotate-right.svg",
"width": 24,
"height": 24
},
{
"type": "input_value",
"name": "DEGREES"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_turnleft'] = {
/**
* Block to turn left.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_TURNLEFT,
"args0": [
{
"type": "field_image",
"src": Blockly.mainWorkspace.options.pathToMedia + "rotate-left.svg",
"width": 24,
"height": 24
},
{
"type": "input_value",
"name": "DEGREES"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_jump_move'] = {
/**
* Block to move steps.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_JUMP_MOVE,
"args0": [
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_pointindirection'] = {
/**
* Block to point in direction.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_POINTINDIRECTION,
"args0": [
{
"type": "input_value",
"name": "DIRECTION"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_cmd_print'] = {
/**
* Block to move steps.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_PRINT,
"args0": [
{
"type": "input_value",
"name": "TEXT"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_pointtowards_menu'] = {
/**
* Point towards drop-down menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "TOWARDS",
"options": [
[Blockly.Msg.MOTION_POINTTOWARDS_POINTER, '_mouse_'],
[Blockly.Msg.MOTION_POINTTOWARDS_RANDOM, '_random_']
]
}
],
"colour": Blockly.Colours.motion.secondary,
"colourSecondary": Blockly.Colours.motion.secondary,
"colourTertiary": Blockly.Colours.motion.tertiary,
"colourQuaternary": Blockly.Colours.motion.quaternary,
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['motion_pointtowards'] = {
/**
* Block to point in direction.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_POINTTOWARDS,
"args0": [
{
"type": "input_value",
"name": "TOWARDS"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_goto_menu'] = {
/**
* Go to drop-down menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "TO",
"options": [
[Blockly.Msg.MOTION_GOTO_POINTER, '_mouse_'],
[Blockly.Msg.MOTION_GOTO_RANDOM, '_random_']
]
}
],
"colour": Blockly.Colours.motion.secondary,
"colourSecondary": Blockly.Colours.motion.secondary,
"colourTertiary": Blockly.Colours.motion.tertiary,
"colourQuaternary": Blockly.Colours.motion.quaternary,
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['motion_gotoxy'] = {
/**
* Block to go to X, Y.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_GOTOXY,
"args0": [
{
"type": "input_value",
"name": "X"
},
{
"type": "input_value",
"name": "Y"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_goto'] = {
/**
* Block to go to a menu item.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_GOTO,
"args0": [
{
"type": "input_value",
"name": "TO"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_glidesecstoxy'] = {
/**
* Block to glide for a specified time.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_GLIDESECSTOXY,
"args0": [
{
"type": "input_value",
"name": "SECS"
},
{
"type": "input_value",
"name": "X"
},
{
"type": "input_value",
"name": "Y"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_glideto_menu'] = {
/**
* Glide to drop-down menu
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "TO",
"options": [
[Blockly.Msg.MOTION_GLIDETO_POINTER, '_mouse_'],
[Blockly.Msg.MOTION_GLIDETO_RANDOM, '_random_']
]
}
],
"colour": Blockly.Colours.motion.secondary,
"colourSecondary": Blockly.Colours.motion.secondary,
"colourTertiary": Blockly.Colours.motion.tertiary,
"colourQuaternary": Blockly.Colours.motion.quaternary,
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['motion_glideto'] = {
/**
* Block to glide to a menu item
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_GLIDETO,
"args0": [
{
"type": "input_value",
"name": "SECS"
},
{
"type": "input_value",
"name": "TO"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_changexby'] = {
/**
* Block to change X.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_CHANGEXBY,
"args0": [
{
"type": "input_value",
"name": "DX"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_setx'] = {
/**
* Block to set X.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_SETX,
"args0": [
{
"type": "input_value",
"name": "X"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_changeyby'] = {
/**
* Block to change Y.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_CHANGEYBY,
"args0": [
{
"type": "input_value",
"name": "DY"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_sety'] = {
/**
* Block to set Y.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_SETY,
"args0": [
{
"type": "input_value",
"name": "Y"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_ifonedgebounce'] = {
/**
* Block to bounce on edge.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_IFONEDGEBOUNCE,
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_setrotationstyle'] = {
/**
* Block to set rotation style.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_SETROTATIONSTYLE,
"args0": [
{
"type": "field_dropdown",
"name": "STYLE",
"options": [
[Blockly.Msg.MOTION_SETROTATIONSTYLE_LEFTRIGHT, 'left-right'],
[Blockly.Msg.MOTION_SETROTATIONSTYLE_DONTROTATE, 'don\'t rotate'],
[Blockly.Msg.MOTION_SETROTATIONSTYLE_ALLAROUND, 'all around']
]
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_xposition'] = {
/**
* Block to report X.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_XPOSITION,
"category": Blockly.Categories.motion,
// "checkboxInFlyout": true,
"extensions": ["colours_motion", "output_number"]
});
}
};
Blockly.Blocks['motion_yposition'] = {
/**
* Block to report Y.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_YPOSITION,
"category": Blockly.Categories.motion,
// "checkboxInFlyout": true,
"extensions": ["colours_motion", "output_number"]
});
}
};
Blockly.Blocks['motion_direction'] = {
/**
* Block to report direction.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_DIRECTION,
"category": Blockly.Categories.motion,
// "checkboxInFlyout": true,
"extensions": ["colours_motion", "output_number"]
});
}
};
Blockly.Blocks['motion_scroll_right'] = {
/**
* Block to scroll the stage right. Does not actually do anything. This is
* an obsolete block that is implemented for compatibility with Scratch 2.0
* projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_SCROLLRIGHT,
"args0": [
{
"type": "input_value",
"name": "DISTANCE"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_scroll_up'] = {
/**
* Block to scroll the stage up. Does not actually do anything. This is an
* obsolete block that is implemented for compatibility with Scratch 2.0
* projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_SCROLLUP,
"args0": [
{
"type": "input_value",
"name": "DISTANCE"
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_align_scene'] = {
/**
* Block to change the stage's scrolling alignment. Does not actually do
* anything. This is an obsolete block that is implemented for compatibility
* with Scratch 2.0 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_ALIGNSCENE,
"args0": [
{
"type": "field_dropdown",
"name": "ALIGNMENT",
"options": [
[Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMLEFT, 'bottom-left'],
[Blockly.Msg.MOTION_ALIGNSCENE_BOTTOMRIGHT, 'bottom-right'],
[Blockly.Msg.MOTION_ALIGNSCENE_MIDDLE, 'middle'],
[Blockly.Msg.MOTION_ALIGNSCENE_TOPLEFT, 'top-left'],
[Blockly.Msg.MOTION_ALIGNSCENE_TOPRIGHT, 'top-right']
]
}
],
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "shape_statement"]
});
}
};
Blockly.Blocks['motion_xscroll'] = {
/**
* Block to report the stage's scroll position's X value. Does not actually
* do anything. This is an obsolete block that is implemented for
* compatibility with Scratch 2.0 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_XSCROLL,
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "output_number"]
});
}
};
Blockly.Blocks['motion_yscroll'] = {
/**
* Block to report the stage's scroll position's Y value. Does not actually
* do anything. This is an obsolete block that is implemented for
* compatibility with Scratch 2.0 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.MOTION_YSCROLL,
"category": Blockly.Categories.motion,
"extensions": ["colours_motion", "output_number"]
});
}
};

View File

@@ -0,0 +1,470 @@
/**
* @license
* Visual Blocks Editor
*
* Copyright 2012 Google Inc.
* https://developers.google.com/blockly/
*
* 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.operators');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['operator_add'] = {
/**
* Block for adding two numbers.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_ADD,
"args0": [
{
"type": "input_value",
"name": "NUM1"
},
{
"type": "input_value",
"name": "NUM2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};
Blockly.Blocks['operator_subtract'] = {
/**
* Block for subtracting two numbers.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_SUBTRACT,
"args0": [
{
"type": "input_value",
"name": "NUM1"
},
{
"type": "input_value",
"name": "NUM2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};
Blockly.Blocks['operator_multiply'] = {
/**
* Block for multiplying two numbers.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_MULTIPLY,
"args0": [
{
"type": "input_value",
"name": "NUM1"
},
{
"type": "input_value",
"name": "NUM2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};
Blockly.Blocks['operator_divide'] = {
/**
* Block for dividing two numbers.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_DIVIDE,
"args0": [
{
"type": "input_value",
"name": "NUM1"
},
{
"type": "input_value",
"name": "NUM2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};
Blockly.Blocks['operator_random'] = {
/**
* Block for picking a random number.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_RANDOM,
"args0": [
{
"type": "input_value",
"name": "FROM"
},
{
"type": "input_value",
"name": "TO"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};
Blockly.Blocks['operator_lt'] = {
/**
* Block for less than comparator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_LT,
"args0": [
{
"type": "input_value",
"name": "OPERAND1"
},
{
"type": "input_value",
"name": "OPERAND2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_boolean"]
});
}
};
Blockly.Blocks['operator_equals'] = {
/**
* Block for equals comparator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_EQUALS,
"args0": [
{
"type": "input_value",
"name": "OPERAND1"
},
{
"type": "input_value",
"name": "OPERAND2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_boolean"]
});
}
};
Blockly.Blocks['operator_gt'] = {
/**
* Block for greater than comparator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_GT,
"args0": [
{
"type": "input_value",
"name": "OPERAND1"
},
{
"type": "input_value",
"name": "OPERAND2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_boolean"]
});
}
};
Blockly.Blocks['operator_and'] = {
/**
* Block for "and" boolean comparator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_AND,
"args0": [
{
"type": "input_value",
"name": "OPERAND1",
"check": "Boolean"
},
{
"type": "input_value",
"name": "OPERAND2",
"check": "Boolean"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_boolean"]
});
}
};
Blockly.Blocks['operator_or'] = {
/**
* Block for "or" boolean comparator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_OR,
"args0": [
{
"type": "input_value",
"name": "OPERAND1",
"check": "Boolean"
},
{
"type": "input_value",
"name": "OPERAND2",
"check": "Boolean"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_boolean"]
});
}
};
Blockly.Blocks['operator_not'] = {
/**
* Block for "not" unary boolean operator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_NOT,
"args0": [
{
"type": "input_value",
"name": "OPERAND",
"check": "Boolean"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_boolean"]
});
}
};
Blockly.Blocks['operator_join'] = {
/**
* Block for string join operator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_JOIN,
"args0": [
{
"type": "input_value",
"name": "STRING1"
},
{
"type": "input_value",
"name": "STRING2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_string"]
});
}
};
Blockly.Blocks['operator_letter_of'] = {
/**
* Block for "letter _ of _" operator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_LETTEROF,
"args0": [
{
"type": "input_value",
"name": "LETTER"
},
{
"type": "input_value",
"name": "STRING"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_string"]
});
}
};
Blockly.Blocks['operator_length'] = {
/**
* Block for string length operator.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_LENGTH,
"args0": [
{
"type": "input_value",
"name": "STRING"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_string"]
});
}
};
Blockly.Blocks['operator_contains'] = {
/**
* Block for _ contains _ operator
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_CONTAINS,
"args0": [
{
"type": "input_value",
"name": "STRING1"
},
{
"type": "input_value",
"name": "STRING2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_boolean"]
});
}
};
Blockly.Blocks['operator_mod'] = {
/**
* Block for mod two numbers.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_MOD,
"args0": [
{
"type": "input_value",
"name": "NUM1"
},
{
"type": "input_value",
"name": "NUM2"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};
Blockly.Blocks['operator_round'] = {
/**
* Block for rounding a numbers.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_ROUND,
"args0": [
{
"type": "input_value",
"name": "NUM"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};
Blockly.Blocks['operator_mathop'] = {
/**
* Block for "advanced" math ops on a number.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.OPERATORS_MATHOP,
"args0": [
{
"type": "field_dropdown",
"name": "OPERATOR",
"options": [
[Blockly.Msg.OPERATORS_MATHOP_ABS, 'abs'],
[Blockly.Msg.OPERATORS_MATHOP_FLOOR, 'floor'],
[Blockly.Msg.OPERATORS_MATHOP_CEILING, 'ceiling'],
[Blockly.Msg.OPERATORS_MATHOP_SQRT, 'sqrt'],
[Blockly.Msg.OPERATORS_MATHOP_SIN, 'sin'],
[Blockly.Msg.OPERATORS_MATHOP_COS, 'cos'],
[Blockly.Msg.OPERATORS_MATHOP_TAN, 'tan'],
[Blockly.Msg.OPERATORS_MATHOP_ASIN, 'asin'],
[Blockly.Msg.OPERATORS_MATHOP_ACOS, 'acos'],
[Blockly.Msg.OPERATORS_MATHOP_ATAN, 'atan'],
[Blockly.Msg.OPERATORS_MATHOP_LN, 'ln'],
[Blockly.Msg.OPERATORS_MATHOP_LOG, 'log'],
[Blockly.Msg.OPERATORS_MATHOP_EEXP, 'e ^'],
[Blockly.Msg.OPERATORS_MATHOP_10EXP, '10 ^']
]
},
{
"type": "input_value",
"name": "NUM"
}
],
"category": Blockly.Categories.operators,
"extensions": ["colours_operators", "output_number"]
});
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,821 @@
/**
* @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.sensing');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['sensing_touchingobject'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_TOUCHINGOBJECT,
"args0": [
{
"type": "input_value",
"name": "TOUCHINGOBJECTMENU"
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
// 角色方向转
Blockly.Blocks['sensing_001_base_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_001_BASE_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock'],
[Blockly.Msg.SENSING_ISMapEdge, 'MapEdge']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_001_forward_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_001_FORWARD_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_001_back_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_001_BACK_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock'],
[Blockly.Msg.SENSING_ISMapEdge, 'MapEdge']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_001_left_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_001_LEFT_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock'],
[Blockly.Msg.SENSING_ISMapEdge, 'MapEdge']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_001_right_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_001_RIGHT_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock'],
[Blockly.Msg.SENSING_ISMapEdge, 'MapEdge']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
//世界方向砖
Blockly.Blocks['sensing_base_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_BASE_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_north_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_NORTH_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_south_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_SOUTH_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_east_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_EAST_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_west_block'] = {
/**
* Block to Report if its touching a Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_WEST_BLOCK,
"args0": [
{
"type": "field_dropdown",
"name": "BLOCKS",
"options": [
[Blockly.Msg.SENSING_ISWallBlock, 'WallBlock'],
[Blockly.Msg.SENSING_ISBaseblock, 'Baseblock'],
[Blockly.Msg.SENSING_ISJumpBlock, 'JumpBlock'],
[Blockly.Msg.SENSING_ISRideBlock, 'RideBlock'],
[Blockly.Msg.SENSING_ISNoneBlock, 'NoneBlock']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_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_sensing", "output_string"]
});
}
};
Blockly.Blocks['sensing_touchingcolor'] = {
/**
* Block to Report if its touching a certain Color.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_TOUCHINGCOLOR,
"args0": [
{
"type": "input_value",
"name": "COLOR"
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_coloristouchingcolor'] = {
/**
* Block to Report if a color is touching a certain Color.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_COLORISTOUCHINGCOLOR,
"args0": [
{
"type": "input_value",
"name": "COLOR"
},
{
"type": "input_value",
"name": "COLOR2"
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_distanceto'] = {
/**
* Block to Report distance to another Object.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_DISTANCETO,
"args0": [
{
"type": "input_value",
"name": "DISTANCETOMENU"
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_distancetomenu'] = {
/**
* "Distance to [Object]" Block Menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "DISTANCETOMENU",
"options": [
[Blockly.Msg.SENSING_DISTANCETO_POINTER, '_mouse_']
]
}
],
"extensions": ["colours_sensing", "output_string"]
});
}
};
Blockly.Blocks['sensing_askandwait'] = {
/**
* Block to ask a question and wait
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_ASKANDWAIT,
"args0": [
{
"type": "input_value",
"name": "QUESTION"
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "shape_statement"]
});
}
};
Blockly.Blocks['sensing_answer'] = {
/**
* Block to report answer
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_ANSWER,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": true,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_keypressed'] = {
/**
* Block to Report if a key is pressed.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_KEYPRESSED,
"args0": [
{
"type": "input_value",
"name": "KEY_OPTION"
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_keyoptions'] = {
/**
* Options for Keys
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "KEY_OPTION",
"options": [
[Blockly.Msg.EVENT_WHENKEYPRESSED_SPACE, 'space'],
[Blockly.Msg.EVENT_WHENKEYPRESSED_UP, 'up arrow'],
[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']
]
}
],
"extensions": ["colours_sensing", "output_string"]
});
}
};
Blockly.Blocks['sensing_mousedown'] = {
/**
* Block to Report if the mouse is down.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_MOUSEDOWN,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": true,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_mousex'] = {
/**
* Block to report mouse's x position
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_MOUSEX,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": true,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_mousey'] = {
/**
* Block to report mouse's y position
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_MOUSEY,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": true,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_setdragmode'] = {
/**
* Block to set drag mode.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_SETDRAGMODE,
"args0": [
{
"type": "field_dropdown",
"name": "DRAG_MODE",
"options": [
[Blockly.Msg.SENSING_SETDRAGMODE_DRAGGABLE, 'draggable'],
[Blockly.Msg.SENSING_SETDRAGMODE_NOTDRAGGABLE, 'not draggable']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "shape_statement"]
});
}
};
Blockly.Blocks['sensing_loudness'] = {
/**
* Block to report loudness
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_LOUDNESS,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": true,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_loud'] = {
/**
* Block to report if the loudness is "loud" (greater than 10). This is an
* obsolete block that is implemented for compatibility with Scratch 2.0 and
* 1.4 projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_LOUD,
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_boolean"]
});
}
};
Blockly.Blocks['sensing_timer'] = {
/**
* Block to report timer
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_TIMER,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": false,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_resettimer'] = {
/**
* Block to reset timer
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_RESETTIMER,
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "shape_statement"]
});
}
};
Blockly.Blocks['sensing_of_object_menu'] = {
/**
* "* of _" object menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "OBJECT",
"options": [
['Sprite1', 'Sprite1'],
['Stage', '_stage_']
]
}
],
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_string"]
});
}
};
Blockly.Blocks['sensing_of'] = {
/**
* Block to report properties of sprites.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_OF,
"args0": [
{
"type": "field_dropdown",
"name": "PROPERTY",
"options": [
[Blockly.Msg.SENSING_OF_XPOSITION, 'x position'],
[Blockly.Msg.SENSING_OF_YPOSITION, 'y position'],
[Blockly.Msg.SENSING_OF_DIRECTION, 'direction'],
[Blockly.Msg.SENSING_OF_COSTUMENUMBER, 'costume #'],
[Blockly.Msg.SENSING_OF_COSTUMENAME, 'costume name'],
[Blockly.Msg.SENSING_OF_SIZE, 'size'],
[Blockly.Msg.SENSING_OF_VOLUME, 'volume'],
[Blockly.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'],
[Blockly.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name']
]
},
{
"type": "input_value",
"name": "OBJECT"
}
],
"output": true,
"category": Blockly.Categories.sensing,
"outputShape": Blockly.OUTPUT_SHAPE_ROUND,
"extensions": ["colours_sensing"]
});
}
};
Blockly.Blocks['sensing_current'] = {
/**
* Block to Report the current option.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_CURRENT,
"args0": [
{
"type": "field_dropdown",
"name": "CURRENTMENU",
"options": [
[Blockly.Msg.SENSING_CURRENT_YEAR, 'YEAR'],
[Blockly.Msg.SENSING_CURRENT_MONTH, 'MONTH'],
[Blockly.Msg.SENSING_CURRENT_DATE, 'DATE'],
[Blockly.Msg.SENSING_CURRENT_DAYOFWEEK, 'DAYOFWEEK'],
[Blockly.Msg.SENSING_CURRENT_HOUR, 'HOUR'],
[Blockly.Msg.SENSING_CURRENT_MINUTE, 'MINUTE'],
[Blockly.Msg.SENSING_CURRENT_SECOND, 'SECOND']
]
}
],
"category": Blockly.Categories.sensing,
"checkboxInFlyout": false,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_dayssince2000'] = {
/**
* Block to report days since 2000
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_DAYSSINCE2000,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": false,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_username'] = {
/**
* Block to report user's username
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_USERNAME,
"category": Blockly.Categories.sensing,
"checkboxInFlyout": true,
"extensions": ["colours_sensing", "output_number"]
});
}
};
Blockly.Blocks['sensing_userid'] = {
/**
* Block to report user's ID. Does not actually do anything. This is an
* obsolete block that is implemented for compatibility with Scratch 2.0
* projects.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SENSING_USERID,
"category": Blockly.Categories.sensing,
"extensions": ["colours_sensing", "output_number"]
});
}
};

View File

@@ -0,0 +1,246 @@
/**
* @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.sound');
goog.require('Blockly.Blocks');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
goog.require('Blockly.ScratchBlocks.VerticalExtensions');
Blockly.Blocks['sound_sounds_menu'] = {
/**
* Sound effects drop-down menu.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "SOUND_MENU",
"options": [
['1', '0'],
['2', '1'],
['3', '2'],
['4', '3'],
['5', '4'],
['6', '5'],
['7', '6'],
['8', '7'],
['9', '8'],
['10', '9'],
['call a function', function() {
window.alert('function called!');}
]
]
}
],
"colour": Blockly.Colours.sounds.secondary,
"colourSecondary": Blockly.Colours.sounds.secondary,
"colourTertiary": Blockly.Colours.sounds.tertiary,
"colourQuaternary": Blockly.Colours.sounds.quaternary,
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['sound_play'] = {
/**
* Block to play sound.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_PLAY,
"args0": [
{
"type": "input_value",
"name": "SOUND_MENU"
}
],
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_playuntildone'] = {
/**
* Block to play sound until done.
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_PLAYUNTILDONE,
"args0": [
{
"type": "input_value",
"name": "SOUND_MENU"
}
],
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_stopallsounds'] = {
/**
* Block to stop all sounds
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_STOPALLSOUNDS,
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_seteffectto'] = {
/**
* Block to set the audio effect
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_SETEFFECTO,
"args0": [
{
"type": "field_dropdown",
"name": "EFFECT",
"options": [
[Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'],
[Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN']
]
},
{
"type": "input_value",
"name": "VALUE"
}
],
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_changeeffectby'] = {
/**
* Block to change the audio effect
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_CHANGEEFFECTBY,
"args0": [
{
"type": "field_dropdown",
"name": "EFFECT",
"options": [
[Blockly.Msg.SOUND_EFFECTS_PITCH, 'PITCH'],
[Blockly.Msg.SOUND_EFFECTS_PAN, 'PAN']
]
},
{
"type": "input_value",
"name": "VALUE"
}
],
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_cleareffects'] = {
/**
* Block to clear audio effects
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_CLEAREFFECTS,
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_changevolumeby'] = {
/**
* Block to change the sprite's volume by a certain value
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_CHANGEVOLUMEBY,
"args0": [
{
"type": "input_value",
"name": "VOLUME"
}
],
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_setvolumeto'] = {
/**
* Block to set the sprite's volume to a certain percent
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_SETVOLUMETO,
"args0": [
{
"type": "input_value",
"name": "VOLUME"
}
],
"category": Blockly.Categories.sound,
"extensions": ["colours_sounds", "shape_statement"]
});
}
};
Blockly.Blocks['sound_volume'] = {
/**
* Block to report volume
* @this Blockly.Block
*/
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_VOLUME,
"category": Blockly.Categories.sound,
"checkboxInFlyout": true,
"extensions": ["colours_sounds", "output_number"]
});
}
};

View File

@@ -0,0 +1,289 @@
/**
* @license
* Visual Blocks Editor
*
* Copyright 2017 Google Inc.
* https://developers.google.com/blockly/
*
* 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.
*/
/**
* @fileoverview Extensions for vertical blocks in scratch-blocks.
* The following extensions can be used to describe a block in Scratch terms.
* For instance, a block in the operators colour scheme with a number output
* would have the "colours_operators" and "output_number" extensions.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.ScratchBlocks.VerticalExtensions');
goog.require('Blockly.Colours');
goog.require('Blockly.constants');
/**
* Helper function that generates an extension based on a category name.
* The generated function will set primary, secondary, tertiary, and quaternary
* colours based on the category name.
* @param {String} category The name of the category to set colours for.
* @return {function} An extension function that sets colours based on the given
* category.
*/
Blockly.ScratchBlocks.VerticalExtensions.colourHelper = function(category) {
var colours = Blockly.Colours[category];
if (!(colours && colours.primary && colours.secondary && colours.tertiary &&
colours.quaternary)) {
throw new Error('Could not find colours for category "' + category + '"');
}
/**
* Set the primary, secondary, tertiary, and quaternary colours on this block for
* the given category.
* @this {Blockly.Block}
*/
return function() {
this.setColourFromRawValues_(colours.primary, colours.secondary,
colours.tertiary, colours.quaternary);
};
};
/**
* Extension to set the colours of a text field, which are all the same.
*/
Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD = function() {
this.setColourFromRawValues_(Blockly.Colours.textField,
Blockly.Colours.textField, Blockly.Colours.textField,
Blockly.Colours.textField);
};
/**
* Extension to make a block fit into a stack of statements, regardless of its
* inputs. That means the block should have a previous connection and a next
* connection and have inline inputs.
* @this {Blockly.Block}
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT = function() {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
};
/**
* Extension to make a block be shaped as a hat block, regardless of its
* inputs. That means the block should have a next connection and have inline
* inputs, but have no previous connection.
* @this {Blockly.Block}
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT = function() {
this.setInputsInline(true);
this.setNextStatement(true, null);
};
/**
* Extension to make a block be shaped as an end block, regardless of its
* inputs. That means the block should have a previous connection and have
* inline inputs, but have no next connection.
* @this {Blockly.Block}
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END = function() {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
};
/**
* Extension to make represent a number reporter in Scratch-Blocks.
* That means the block has inline inputs, a round output shape, and a 'Number'
* output type.
* @this {Blockly.Block}
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER = function() {
this.setInputsInline(true);
this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
this.setOutput(true, 'Number');
};
/**
* Extension to make represent a string reporter in Scratch-Blocks.
* That means the block has inline inputs, a round output shape, and a 'String'
* output type.
* @this {Blockly.Block}
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING = function() {
this.setInputsInline(true);
this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
this.setOutput(true, 'String');
};
/**
* Extension to make represent a boolean reporter in Scratch-Blocks.
* That means the block has inline inputs, a round output shape, and a 'Boolean'
* output type.
* @this {Blockly.Block}
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN = function() {
this.setInputsInline(true);
this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
this.setOutput(true, 'Boolean');
};
/**
* Mixin to add a context menu for a procedure definition block.
* It adds the "edit" option and removes the "duplicate" option.
* @mixin
* @augments Blockly.Block
* @package
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU = {
/**
* Add the "edit" option and removes the "duplicate" option from the context
* menu.
* @param {!Array.<!Object>} menuOptions List of menu options to edit.
* @this Blockly.Block
*/
customContextMenu: function(menuOptions) {
// Add the edit option at the end.
menuOptions.push(Blockly.Procedures.makeEditOption(this));
// Find the delete option and update its callback to be specific to
// functions.
for (var i = 0, option; option = menuOptions[i]; i++) {
if (option.text == Blockly.Msg.DELETE_BLOCK) {
var input = this.getInput('custom_block');
// this is the root block, not the shadow block.
if (input && input.connection && input.connection.targetBlock()) {
var procCode = input.connection.targetBlock().getProcCode();
} else {
return;
}
var rootBlock = this;
option.callback = function() {
var didDelete = Blockly.Procedures.deleteProcedureDefCallback(
procCode, rootBlock);
if (!didDelete) {
alert(Blockly.Msg.PROCEDURE_USED);
}
};
}
}
// Find and remove the duplicate option
for (var i = 0, option; option = menuOptions[i]; i++) {
if (option.text == Blockly.Msg.DUPLICATE) {
menuOptions.splice(i, 1);
break;
}
}
}
};
/**
* Mixin to add a context menu for a procedure call block.
* It adds the "edit" option and the "define" option.
* @mixin
* @augments Blockly.Block
* @package
* @readonly
*/
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU = {
/**
* Add the "edit" option to the context menu.
* @todo Add "go to definition" option once implemented.
* @param {!Array.<!Object>} menuOptions List of menu options to edit.
* @this Blockly.Block
*/
customContextMenu: function(menuOptions) {
menuOptions.push(Blockly.Procedures.makeEditOption(this));
if (
!this.isInFlyout &&
Blockly.Procedures.USER_CAN_CHANGE_CALL_TYPE &&
this.workspace.procedureReturnsEnabled
) {
menuOptions.push(Blockly.Procedures.makeChangeTypeOption(this));
}
}
};
Blockly.ScratchBlocks.VerticalExtensions.FROM_EXTENSION = function() {
this.isFromExtension = true;
};
Blockly.ScratchBlocks.VerticalExtensions.DEFAULT_EXTENSION_COLORS = function() {
this.usesDefaultExtensionColors = true;
};
Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION = function() {
this.isScratchExtension = true;
};
/**
* Register all extensions for scratch-blocks.
* @package
*/
Blockly.ScratchBlocks.VerticalExtensions.registerAll = function() {
var categoryNames =
['control', 'data', 'data_lists', 'sounds', 'motion', 'looks', 'event',
'sensing', 'pen', 'operators', 'more'];
// Register functions for all category colours.
for (var i = 0; i < categoryNames.length; i++) {
var name = categoryNames[i];
Blockly.Extensions.register('colours_' + name,
Blockly.ScratchBlocks.VerticalExtensions.colourHelper(name));
}
// Text fields transcend categories.
Blockly.Extensions.register('colours_textfield',
Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD);
// Register extensions for common block shapes.
Blockly.Extensions.register('shape_statement',
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT);
Blockly.Extensions.register('shape_hat',
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT);
Blockly.Extensions.register('shape_end',
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END);
// Output shapes and types are related.
Blockly.Extensions.register('output_number',
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER);
Blockly.Extensions.register('output_string',
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING);
Blockly.Extensions.register('output_boolean',
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN);
// Custom procedures have interesting context menus.
Blockly.Extensions.registerMixin('procedure_def_contextmenu',
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU);
Blockly.Extensions.registerMixin('procedure_call_contextmenu',
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU);
// Given to all blocks from an extension.
Blockly.Extensions.register('from_extension',
Blockly.ScratchBlocks.VerticalExtensions.FROM_EXTENSION);
// Given to blocks that use the default extension colors ("pen")
Blockly.Extensions.register('default_extension_colors',
Blockly.ScratchBlocks.VerticalExtensions.DEFAULT_EXTENSION_COLORS);
// Misleading name. Given to blocks that have an extension icon.
Blockly.Extensions.register('scratch_extension',
Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION);
};
Blockly.ScratchBlocks.VerticalExtensions.registerAll();