|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
goog.provide('Blockly.ScratchBlocks.VerticalExtensions');
|
|
|
|
|
|
goog.require('Blockly.Colours');
|
|
|
goog.require('Blockly.constants');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.colourHelper = function(category) {
|
|
|
var colours = Blockly.Colours[category];
|
|
|
if (!(colours && colours.primary && colours.secondary && colours.tertiary)) {
|
|
|
throw new Error('Could not find colours for category "' + category + '"');
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return function() {
|
|
|
this.setColourFromRawValues_(colours.primary, colours.secondary,
|
|
|
colours.tertiary);
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD = function() {
|
|
|
this.setColourFromRawValues_(Blockly.Colours.textField,
|
|
|
Blockly.Colours.textField, Blockly.Colours.textField);
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_PROCEDURE = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setPreviousStatement(true, 'procedure');
|
|
|
this.setNextStatement(true, 'procedure');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_CASE = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setPreviousStatement(true, 'switchCase');
|
|
|
this.setNextStatement(true, 'switchCase');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_STATEMENT = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setPreviousStatement(true, 'normal');
|
|
|
this.setNextStatement(true, 'normal');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_HAT = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setNextStatement(true, 'normal');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_END = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setPreviousStatement(true, 'normal');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_NUMBER = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
|
|
|
this.setOutput(true, 'Number');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_STRING = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
|
|
|
this.setOutput(true, 'String');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.OUTPUT_BOOLEAN = function() {
|
|
|
this.setInputsInline(true);
|
|
|
this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
|
|
|
this.setOutput(true, 'Boolean');
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
customContextMenu: function(menuOptions) {
|
|
|
|
|
|
menuOptions.push(Blockly.Procedures.makeEditOption(this));
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0, option; option = menuOptions[i]; i++) {
|
|
|
if (option.text == Blockly.Msg.DELETE_BLOCK) {
|
|
|
var input = this.getInput('custom_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);
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (var i = 0, option; option = menuOptions[i]; i++) {
|
|
|
if (option.text == Blockly.Msg.DUPLICATE) {
|
|
|
menuOptions.splice(i, 1);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
customContextMenu: function(menuOptions) {
|
|
|
menuOptions.push(Blockly.Procedures.makeEditOption(this));
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION = function() {
|
|
|
this.isScratchExtension = true;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.registerAll = function() {
|
|
|
var categoryNames =
|
|
|
['control', 'data', 'data_lists', 'sounds', 'motion', 'looks', 'event',
|
|
|
'sensing', 'pen', 'operators', 'more'];
|
|
|
|
|
|
for (var i = 0; i < categoryNames.length; i++) {
|
|
|
var name = categoryNames[i];
|
|
|
Blockly.Extensions.register('colours_' + name,
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.colourHelper(name));
|
|
|
}
|
|
|
|
|
|
|
|
|
Blockly.Extensions.register('colours_textfield',
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.COLOUR_TEXTFIELD);
|
|
|
|
|
|
|
|
|
Blockly.Extensions.register('shape_procedure',
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_PROCEDURE);
|
|
|
Blockly.Extensions.register('shape_case',
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SHAPE_CASE);
|
|
|
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);
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
Blockly.Extensions.registerMixin('procedure_def_contextmenu',
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_DEF_CONTEXTMENU);
|
|
|
Blockly.Extensions.registerMixin('procedure_call_contextmenu',
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.PROCEDURE_CALL_CONTEXTMENU);
|
|
|
|
|
|
|
|
|
Blockly.Extensions.register('scratch_extension',
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION);
|
|
|
};
|
|
|
|
|
|
Blockly.ScratchBlocks.VerticalExtensions.registerAll();
|
|
|
|