初始化提交
This commit is contained in:
1127
boards/default_src/python_skulpt/blocks/data.js
Normal file
1127
boards/default_src/python_skulpt/blocks/data.js
Normal file
File diff suppressed because it is too large
Load Diff
202
boards/default_src/python_skulpt/blocks/inout.js
Normal file
202
boards/default_src/python_skulpt/blocks/inout.js
Normal file
@@ -0,0 +1,202 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const INOUT_HUE = 20;
|
||||
|
||||
export const inout_input = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.blockpy_inout_raw_input)
|
||||
.setCheck(String);
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.INOUT_input_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const inout_print = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.BLOCKPY_PRINT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_inline = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_end = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
|
||||
this.appendValueInput("END")
|
||||
.appendField(Blockly.Msg.MIXLY_ENDSWITH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_PYTHON_INOUT_PRINT_END_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_type_input = {
|
||||
init: function () {
|
||||
|
||||
var input_type =
|
||||
[[Blockly.Msg.LANG_MATH_STRING, 'str'], [Blockly.Msg.LANG_MATH_INT, 'int']
|
||||
, [Blockly.Msg.LANG_MATH_FLOAT, 'float']];
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
|
||||
.appendField(new Blockly.FieldDropdown(input_type), 'DIR')
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE)
|
||||
.setCheck(String);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'str': Blockly.Msg.MIXLY_MIXPY_INOUT_STR_INPUT_TOOLTIP,
|
||||
'int': Blockly.Msg.MIXLY_MIXPY_INOUT_INT_INPUT_TOOLTIP,
|
||||
'float': Blockly.Msg.MIXLY_MIXPY_INOUT_FLOAT_INPUT_TOOLTIP
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_many = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
|
||||
this.itemCount_ = 2;
|
||||
this.updateShape_();
|
||||
this.setPreviousStatement(false);
|
||||
this.setNextStatement(false);
|
||||
this.setInputsInline(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['inout_print_item'], this));
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_TOOLTIP);
|
||||
},
|
||||
|
||||
mutationToDom: function () {
|
||||
var container = document.createElement('mutation');
|
||||
container.setAttribute('items', this.itemCount_);
|
||||
return container;
|
||||
},
|
||||
|
||||
domToMutation: function (xmlElement) {
|
||||
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
|
||||
this.updateShape_();
|
||||
},
|
||||
|
||||
decompose: function (workspace) {
|
||||
var containerBlock =
|
||||
workspace.newBlock('inout_print_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = workspace.newBlock('inout_print_item');
|
||||
itemBlock.initSvg();
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
}
|
||||
return containerBlock;
|
||||
},
|
||||
|
||||
compose: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
// Count number of inputs.
|
||||
var connections = [];
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
connections[i] = itemBlock.valueConnection_;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
i++;
|
||||
}
|
||||
this.itemCount_ = i;
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
if (connections[i]) {
|
||||
this.getInput('ADD' + i)
|
||||
.connection.connect(connections[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
saveConnections: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
var input = this.getInput('ADD' + i);
|
||||
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
||||
i++;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
}
|
||||
},
|
||||
|
||||
updateShape_: function () {
|
||||
// Delete everything.
|
||||
if (this.getInput('EMPTY')) {
|
||||
this.removeInput('EMPTY');
|
||||
} else {
|
||||
var i = 0;
|
||||
while (this.getInput('ADD' + i)) {
|
||||
this.removeInput('ADD' + i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Rebuild block.
|
||||
if (this.itemCount_ == 0) {
|
||||
this.appendDummyInput('EMPTY')
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_EMPTY);
|
||||
} else {
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var input = this.appendValueInput('ADD' + i);
|
||||
if (i == 0) {
|
||||
input.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
export const inout_print_container = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
this.appendStatementInput('STACK');
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_CONTAINER_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_item = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_ITEM_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
270
boards/default_src/python_skulpt/blocks/iot.js
Normal file
270
boards/default_src/python_skulpt/blocks/iot.js
Normal file
@@ -0,0 +1,270 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import * as Mixly from 'mixly';
|
||||
|
||||
const IOT_HUE = '#526FC3';
|
||||
//'#2FAD7A';
|
||||
|
||||
export const iot_mixio_connect = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('USERNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_WIFI_USERNAME)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('PASSWORD')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_IOT_PASSWORD)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('PROJECT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PROJECT)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_PUBLISH = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_NEW)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.appendValueInput('MSG')
|
||||
.appendField(Blockly.Msg.HTML_BODY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_PUBLISH_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_SUBSCRIBE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SUBSCRIBE + Blockly.Msg.MIXLY_MICROBIT_MSG)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.appendValueInput('METHOD')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SET_METHOD);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_SUBSCRIBE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_UNSUBSCRIBE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MSG.stop + Blockly.Msg.MIXLY_EMQX_SUBSCRIBE)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_SUBSCRIBE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_disconnect = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_DISCONNECT_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_connect_only = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_CONNECT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_check = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_CHECK_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_CHECK_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_format_topic = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT)
|
||||
.appendField(Blockly.MQTT_Topic);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_format_msg = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_MSG);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_FORMATTING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_IOT_MAP_FORMATING);
|
||||
this.setOutput(true);
|
||||
// this.setTooltip();
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_FORMAT_STRING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT + '(Json)');
|
||||
this.setOutput(true);
|
||||
// this.setTooltip();
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_EMQX_PING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PING);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_PING_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_NTP = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
.appendField(Blockly.Msg.MIXLY_GET_NTP)
|
||||
this.appendValueInput('addr')
|
||||
.appendField(Blockly.blynk_SERVER_ADD);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_SHARE_CODE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('KEY')
|
||||
.appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH + Blockly.Msg.MIXLY_MIXIO_SHARE_KEY)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_MIXLY_CODE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('KEY')
|
||||
.appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH + "Mixly Key")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const iot_mixly_key = {
|
||||
init: function () {
|
||||
this.VISITOR_ID = Mixly.Config.BOARD.visitorId.str32.substring(0, 8).toUpperCase();
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput(this.visitorId), 'VISITOR_ID');
|
||||
this.setOutput(true, null);
|
||||
},
|
||||
onchange: function () {
|
||||
const nowVisitorId = this.getFieldValue('VISITOR_ID');
|
||||
if (this.VISITOR_ID !== nowVisitorId)
|
||||
this.setFieldValue(this.VISITOR_ID, 'VISITOR_ID');
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixly_key_py = {
|
||||
init: function () {
|
||||
this.VISITOR_ID = Mixly.Config.BOARD.visitorId.str32.substring(0, 8).toUpperCase();
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(this.newQuote_(true))
|
||||
.appendField(new Blockly.FieldTextInput(this.visitorId), 'VISITOR_ID')
|
||||
.appendField(this.newQuote_(false));
|
||||
this.setOutput(true, null);
|
||||
},
|
||||
onchange: function () {
|
||||
const nowVisitorId = this.getFieldValue('VISITOR_ID');
|
||||
if (this.VISITOR_ID !== nowVisitorId)
|
||||
this.setFieldValue(this.VISITOR_ID, 'VISITOR_ID');
|
||||
},
|
||||
newQuote_: function (open) {
|
||||
if (open == this.RTL) {
|
||||
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
|
||||
} else {
|
||||
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
|
||||
}
|
||||
return new Blockly.FieldImage(file, 12, 12, '"');
|
||||
}
|
||||
};
|
||||
126
boards/default_src/python_skulpt/blocks/system.js
Normal file
126
boards/default_src/python_skulpt/blocks/system.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const SYSTEM_HUE = 120;
|
||||
|
||||
export const base_delay = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("DELAY_TIME", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DELAY + '(' + Blockly.Msg.MIXLY_MILLIS + ')')
|
||||
.setCheck(Number);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_millis = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_time_time);
|
||||
this.setOutput(true, Number);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_MILLIS);
|
||||
}
|
||||
};
|
||||
|
||||
export const time_localtime = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME)
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_ALL, "all"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_YEAR, "0"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_MONTH, "1"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_DATE, "2"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_HOUR, "3"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_MINUTE, "4"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_SECOND, "5"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_INWEEK, "6"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_INYEAR, "7"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_DST, "8"]
|
||||
]), "op");
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const Panic_with_status_code = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("STATUS_CODE", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_Panic_with_status_code)
|
||||
.setCheck(Number);
|
||||
this.setPreviousStatement(true, null);
|
||||
// this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
export const reset = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_Reset_micro);
|
||||
this.setPreviousStatement(true);
|
||||
// this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2 = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput('TIME')
|
||||
.setCheck(Number)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_EVERY);
|
||||
this.appendDummyInput()
|
||||
.appendField('ms');
|
||||
this.appendStatementInput('DO')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_DO);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2_start = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_START);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2_stop = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_STOP);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const time_sleep = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("DELAY_TIME", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DELAY)
|
||||
.setCheck(Number);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_SECOND)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
877
boards/default_src/python_skulpt/blocks/turtle.js
Normal file
877
boards/default_src/python_skulpt/blocks/turtle.js
Normal file
@@ -0,0 +1,877 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const TURTLE_HUE = 180;
|
||||
|
||||
export const turtle_create = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
|
||||
.appendField(Blockly.Msg.blockpy_turtle_create)
|
||||
.appendField(new Blockly.FieldTextInput('tina'), 'VAR')
|
||||
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.blockpy_turtle_create_TOOLTIP);
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const turtle_done = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_TURTLE_DONE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_exitonclick = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_TURTLE_EXITONCLICK);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_move = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var front_back =
|
||||
[[Blockly.Msg.blockpy_forward, 'forward'], [Blockly.Msg.blockpy_backward, 'backward']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MOVE_BY)
|
||||
.appendField(new Blockly.FieldDropdown(front_back), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MOVE_BY_num);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'forward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_FORWARD,
|
||||
'backward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_BACKWARD
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_rotate = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var front_back =
|
||||
[[Blockly.Msg.blockpy_left, 'left'], [Blockly.Msg.blockpy_right, 'right']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_rotate)
|
||||
.appendField(new Blockly.FieldDropdown(front_back), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_BY_ANGLE);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'left': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_LEFT,
|
||||
'right': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_RIGHT
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_setheading = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_setheading);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_setheading_degree);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_screen_delay = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_SCREEN_DELAY);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MILLIS);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SCREEN_DELAY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_goto = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto);
|
||||
this.appendValueInput('val')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto_y);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto_position);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_setxy = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var set_xy =
|
||||
[[Blockly.Msg.PYLAB_LABEL_X, 'x'], [Blockly.Msg.PYLAB_LABEL_Y, 'y']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(new Blockly.FieldDropdown(set_xy), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_SETXY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_TURTLE_SETXY_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pos_shape = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
var pos_shape =
|
||||
[[Blockly.Msg.TURTLE_POS, 'pos'], [Blockly.Msg.TURTLE_SHAPE, 'shape'], [Blockly.Msg.TURTLE_HEADING, 'heading'], [Blockly.Msg.MIXLY_MIXPY_TURTLE_WIDTH, 'width'], [Blockly.Msg.MIXLY_TURTEL_GET_SHAPESIZE, 'shapesize'], [Blockly.Msg.MIXLY_SPEED, 'speed']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.TURTLE_POS_SHAPE)
|
||||
.appendField(new Blockly.FieldDropdown(pos_shape), 'DIR')
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'pos': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_POS,
|
||||
'shape': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SHAPE,
|
||||
'heading': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HEADING,
|
||||
'width': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_WIDTH,
|
||||
'speed': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_GET_SPEED,
|
||||
'shapesize': Blockly.Msg.MIXLY_TURTEL_GET_SHAPESIZE_TOOLTIP
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_clear = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var clear_reset =
|
||||
[[Blockly.Msg.MIXLY_LCD_STAT_CLEAR, 'clear'], [Blockly.Msg.blockpy_turtle_reset, 'reset']
|
||||
, [Blockly.Msg.blockpy_turtle_home, 'home']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(clear_reset), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'clear': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CLEAR,
|
||||
'reset': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_RESET,
|
||||
'home': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HOME
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_penup = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var penup_down =
|
||||
[[Blockly.Msg.blockpy_turtle_penup, 'penup'], [Blockly.Msg.blockpy_turtle_pendown, 'pendown']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(penup_down), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'penup': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_PENUP,
|
||||
'pendown': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_PENDOWN
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fill = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var fill =
|
||||
[[Blockly.Msg.blockpy_turtle_beginfill, 'begin'], [Blockly.Msg.blockpy_turtle_endfill, 'end']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(fill), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'begin': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_BEGINFILL,
|
||||
'end': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_ENDFILL
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_size_speed = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('tina'), 'TUR')
|
||||
var size_speed =
|
||||
[[Blockly.Msg.blockpy_turtle_size, 'pensize'], [Blockly.Msg.MIXLY_SPEED, 'speed']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set)
|
||||
.appendField(new Blockly.FieldDropdown(size_speed), 'DIR')
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_num);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'pensize': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SIZE,
|
||||
'speed': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SPEED
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_size = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_size);
|
||||
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SIZE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_speed = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_speed);
|
||||
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SPEED);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_circle = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var circle_dot =
|
||||
[[Blockly.Msg.blockpy_turtle_circle, 'circle'], [Blockly.Msg.blockpy_turtle_dot, 'dot']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_draw)
|
||||
.appendField(new Blockly.FieldDropdown(circle_dot), 'DIR')
|
||||
.appendField(Blockly.Msg.blockpy_turtle_radius);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'circle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CIRCLE,
|
||||
'dot': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_DOT
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_circle_advanced = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_DRAW_CIRCLE)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_radius);
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_angle);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CIRCLE);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_visible = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var visible =
|
||||
[[Blockly.Msg.blockpy_turtle_hide, 'hideturtle'], [Blockly.Msg.blockpy_turtle_show, 'showturtle']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(visible), 'DIR')
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'hideturtle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HIDE,
|
||||
'showturtle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SHOW
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_bgcolor = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_clone = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.TURTLE_CLONE);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_CLONE_TOOLTIP);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_bgcolor_hex_new = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor_hex_new = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor_hex_new = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_color = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME2');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_color_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR1')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor);
|
||||
this.appendValueInput('VAR2')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_bgcolor_hex = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_shape = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var shape = [
|
||||
[Blockly.Msg.blockpy_turtle_shape_arrow, 'arrow'], [Blockly.Msg.blockpy_turtle_shape_turtle, 'turtle'],
|
||||
[Blockly.Msg.blockpy_turtle_shape_circle, 'circle'], [Blockly.Msg.blockpy_turtle_shape_square, 'square'],
|
||||
[Blockly.Msg.blockpy_turtle_shape_triangle, 'triangle'], [Blockly.Msg.blockpy_turtle_shape_classic, 'classic']
|
||||
];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_turtle_shape)
|
||||
.appendField(new Blockly.FieldDropdown(shape), 'DIR');
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_SHAPE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_shapesize = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE);
|
||||
this.appendValueInput('WID')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_WID);
|
||||
this.appendValueInput('LEN')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_LEN);
|
||||
this.appendValueInput('OUTLINE')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_OUTLINE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SHAPESIZE);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_numinput = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_NUMINPUT)
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TITLE')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_TITLE);
|
||||
this.appendValueInput('PROMPT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_PROMPT);
|
||||
this.appendValueInput('DEFAULT')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.DICTS_DEFAULT_VALUE);
|
||||
this.appendValueInput('MIN')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MATH_ONLIST_OPERATOR_MIN);
|
||||
this.appendValueInput('MAX')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MATH_ONLIST_OPERATOR_MAX);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, Number);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_NUMINPUT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_textinput = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT)
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TITLE')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_TITLE);
|
||||
this.appendValueInput('PROMPT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_PROMPT);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_TEXTINPUT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write_format = {
|
||||
init: function () {
|
||||
var move =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, 'False'], [Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, 'True']];
|
||||
var align =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_LEFT, 'left'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_CENTER, 'center'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_RIGHT, 'right']];
|
||||
var fonttype =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_NORMAL, 'normal'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD, 'bold'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_ITALIC, 'italic'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD_ITALIC, 'bold","italic']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE)
|
||||
.appendField(new Blockly.FieldDropdown(move), 'MOVE');
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN)
|
||||
.appendField(new Blockly.FieldDropdown(align), 'ALIGN');
|
||||
this.appendValueInput('FONTNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME);
|
||||
this.appendValueInput('FONTNUM')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE)
|
||||
.appendField(new Blockly.FieldDropdown(fonttype), 'FONTTYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write_format_skulpt = {
|
||||
init: function () {
|
||||
var move =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, 'False'], [Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, 'True']];
|
||||
var align =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_LEFT, 'left'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_CENTER, 'center'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_RIGHT, 'right']];
|
||||
var fonttype =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_NORMAL, 'normal'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD, 'bold'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_ITALIC, 'italic']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE)
|
||||
.appendField(new Blockly.FieldDropdown(move), 'MOVE');
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN)
|
||||
.appendField(new Blockly.FieldDropdown(align), 'ALIGN');
|
||||
this.appendValueInput('FONTNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME);
|
||||
this.appendValueInput('FONTNUM')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE)
|
||||
.appendField(new Blockly.FieldDropdown(fonttype), 'FONTTYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_color_seclet = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldColour("ff0000"), "COLOR");
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_getscreen = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_GETSCREEN)
|
||||
.appendField(new Blockly.FieldTextInput('screen'), 'VAR')
|
||||
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_GETSCREEN_TOOLTIP);
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const turtle_onkey = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONKEY);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONKEY_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_onclick = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONCLICK);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONCLICK_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_ontimer = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONTIMER);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_mSecond);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONTIMER_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_listen = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SCREEN_LISTEN);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_screen_savefig = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput("FILE")
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.mixpy_PL_SAVEFIG);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setOutput(false);
|
||||
this.setTooltip(Blockly.Msg.mixpy_TURTLE_SAVEFIG_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user