初始化提交
This commit is contained in:
3
boards/default_src/python_skulpt_car/.npmignore
Normal file
3
boards/default_src/python_skulpt_car/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
build
|
||||
origin
|
||||
551
boards/default_src/python_skulpt_car/blocks/game.js
Normal file
551
boards/default_src/python_skulpt_car/blocks/game.js
Normal file
@@ -0,0 +1,551 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
//初始化地图为第1关
|
||||
export const initSettedMap_1 = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("初始化地图为第一关")
|
||||
this.setInputsInline(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
//初始化地图为第2关
|
||||
export const initSettedMap_2 = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("初始化地图为第二关")
|
||||
this.setInputsInline(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
//初始化地图为第3关
|
||||
export const initSettedMap_3 = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("初始化地图为第三关")
|
||||
this.setInputsInline(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
//初始化地图为第4关
|
||||
export const initSettedMap_4 = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("初始化地图为第四关")
|
||||
this.setInputsInline(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
//初始化地图为第5关
|
||||
export const initSettedMap_5 = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("初始化地图为第五关")
|
||||
this.setInputsInline(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
//初始化地图为第6关
|
||||
export const initSettedMap_6 = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("初始化地图为第六关")
|
||||
this.setInputsInline(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
//初始化地图为第7关
|
||||
export const initSettedMap_7 = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("初始化地图为第七关")
|
||||
this.setInputsInline(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
export const game_init = {
|
||||
init: function () {
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.appendStatementInput('DO0')
|
||||
.appendField(Blockly.Msg.MIXLY_GAME_INIT);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const move_direction_steps = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("向")
|
||||
.appendField(new Blockly.FieldDropdown([["东", '1'], ["南", '2'], ["西", '3'], ["北", '0']]), "direction");
|
||||
this.appendDummyInput()
|
||||
.appendField("移动");
|
||||
this.appendValueInput("times")
|
||||
.setCheck(Number)
|
||||
this.appendDummyInput()
|
||||
.appendField("步");
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
export const Turn = {
|
||||
init: function () {
|
||||
var Directions = [
|
||||
[Blockly.Msg.MIXLY_GAME_Turn_LEFT, 'left'],
|
||||
[Blockly.Msg.MIXLY_GAME_Turn_RIGHT, 'right']
|
||||
];
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_GAME_TURN1)
|
||||
.appendField(new Blockly.FieldDropdown(Directions), 'Direction')
|
||||
.appendField(Blockly.Msg.MIXLY_GAME_TURN2);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const isDone = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_GAME_ISDONE);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const isPath = {
|
||||
init: function () {
|
||||
var Directions = [
|
||||
[Blockly.Msg.MIXLY_GAME_ISPATH_LEFT, 'left'],
|
||||
[Blockly.Msg.MIXLY_GAME_ISPATH_RIGHT, 'right']
|
||||
];
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_GAME_ISPATH1)
|
||||
.appendField(new Blockly.FieldDropdown(Directions), 'Direction')
|
||||
.appendField(Blockly.Msg.MIXLY_GAME_ISPATH2);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
//最新块
|
||||
export const set_map = {
|
||||
init: function () {
|
||||
// this.appendDummyInput()
|
||||
// .appendField("设置地图:长");
|
||||
this.appendValueInput("x")
|
||||
.setCheck(Number)
|
||||
.appendField("设置地图,长为:");
|
||||
this.appendValueInput("y")
|
||||
.setCheck(Number)
|
||||
.appendField("宽为:");
|
||||
this.appendValueInput("startPos")
|
||||
.setCheck(null)
|
||||
.appendField(",起点坐标");
|
||||
this.appendValueInput("endPos")
|
||||
.setCheck(null)
|
||||
.appendField("终点坐标");
|
||||
this.appendValueInput("background")
|
||||
.setCheck(null)
|
||||
.appendField("背景");
|
||||
// this.appendDummyInput()
|
||||
// .appendField(",背景")
|
||||
// .appendField(new Blockly.FieldDropdown([["背景1","3"],["背景2","4"]]), "bg");
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const game_get_local_img = {
|
||||
init: function () {
|
||||
this.imgArr = this.getLocalImg();
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldDropdown(this.getLocalImg()), "type");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
},
|
||||
onchange: function () {
|
||||
let typeValue = this.getFieldValue("type");
|
||||
//let newImgArr = this.getLocalImg();
|
||||
let newImgArr = this.imgArr;
|
||||
if (this.haveNewSrc(this.imgArr, newImgArr)) {
|
||||
this.imgArr = newImgArr;
|
||||
var typeField = this.getField("type");
|
||||
typeField.menuGenerator_ = this.imgArr;
|
||||
if (this.checkSrc(typeValue, this.imgArr)) {
|
||||
this.setFieldValue(typeValue, "type");
|
||||
} else {
|
||||
this.setFieldValue(this.imgArr[0][1], "type");
|
||||
}
|
||||
}
|
||||
},
|
||||
haveNewSrc: function (oldArr, newArr) {
|
||||
if (oldArr.length !== newArr.length) return true;
|
||||
for (var i = 0; i < oldArr.length; i++) {
|
||||
if (oldArr[i][0].src !== newArr[i][0].src) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
checkSrc: function (newSrc, srcArr) {
|
||||
for (var i = 0; i < srcArr.length; i++) {
|
||||
if (srcArr[i][0].src == newSrc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getLocalImg: function () {
|
||||
let imgArr = [];
|
||||
try {
|
||||
var imgDirArr = ["bg_default.png", "bg_astro.png", "bg_panda.jpg"]
|
||||
for (var i = 0; i < imgDirArr.length; i++) {
|
||||
var dropdownItem = {};
|
||||
dropdownItem.src = "./media/mixpyBuild/maps/" + imgDirArr[i];
|
||||
dropdownItem.width = 40;
|
||||
dropdownItem.height = 45;
|
||||
if (imgDirArr[i] == "") {
|
||||
dropdownItem.alt = "无";
|
||||
} else {
|
||||
dropdownItem.alt = "*";
|
||||
}
|
||||
var dropdownArr = [];
|
||||
dropdownArr.push(dropdownItem);
|
||||
var dropdownData = imgDirArr[i].substring(0, imgDirArr[i].lastIndexOf("."));
|
||||
dropdownData = '\'' + dropdownData + '\'';
|
||||
dropdownArr.push(dropdownData);
|
||||
imgArr.push(dropdownArr);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
imgArr = [["'无可用地图'", "'无可用地图'"]];
|
||||
}
|
||||
if (imgArr.length > 0) {
|
||||
return imgArr;
|
||||
}
|
||||
return [["'无可用地图'", "'无可用地图'"]];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const set_pathtype = {
|
||||
init: function () {
|
||||
this.appendValueInput("pathtype")
|
||||
.setCheck(null)
|
||||
.appendField("设置路径样式为");
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const game_get_path_img = {
|
||||
init: function () {
|
||||
this.imgArr = this.getLocalImg();
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldDropdown(this.getLocalImg()), "type");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
},
|
||||
onchange: function () {
|
||||
let typeValue = this.getFieldValue("type");
|
||||
//let newImgArr = this.getLocalImg();
|
||||
let newImgArr = this.imgArr;
|
||||
if (this.haveNewSrc(this.imgArr, newImgArr)) {
|
||||
this.imgArr = newImgArr;
|
||||
var typeField = this.getField("type");
|
||||
typeField.menuGenerator_ = this.imgArr;
|
||||
if (this.checkSrc(typeValue, this.imgArr)) {
|
||||
this.setFieldValue(typeValue, "type");
|
||||
} else {
|
||||
this.setFieldValue(this.imgArr[0][1], "type");
|
||||
}
|
||||
}
|
||||
},
|
||||
haveNewSrc: function (oldArr, newArr) {
|
||||
if (oldArr.length !== newArr.length) return true;
|
||||
for (var i = 0; i < oldArr.length; i++) {
|
||||
if (oldArr[i][0].src !== newArr[i][0].src) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
checkSrc: function (newSrc, srcArr) {
|
||||
for (var i = 0; i < srcArr.length; i++) {
|
||||
if (srcArr[i][0].src == newSrc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getLocalImg: function () {
|
||||
let imgArr = [];
|
||||
try {
|
||||
var imgDirArr = ["default.png", "bamboo.png", "pipeline.png"]
|
||||
for (var i = 0; i < imgDirArr.length; i++) {
|
||||
var dropdownItem = {};
|
||||
dropdownItem.src = "./media/mixpyBuild/path/" + imgDirArr[i];
|
||||
dropdownItem.width = 40;
|
||||
dropdownItem.height = 45;
|
||||
dropdownItem.alt = "*";
|
||||
var dropdownArr = [];
|
||||
dropdownArr.push(dropdownItem);
|
||||
var dropdownData = imgDirArr[i].substring(0, imgDirArr[i].lastIndexOf("."));
|
||||
dropdownData = '\'' + dropdownData + '\'';
|
||||
dropdownArr.push(dropdownData);
|
||||
imgArr.push(dropdownArr);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
imgArr = [["'无可用路径'", "'无可用路径'"]];
|
||||
}
|
||||
if (imgArr.length > 0) {
|
||||
return imgArr;
|
||||
}
|
||||
return [["'无可用路径'", "'无可用路径'"]];
|
||||
}
|
||||
};
|
||||
|
||||
export const place_item = {
|
||||
init: function () {
|
||||
this.setColour(290);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.appendValueInput("posx")
|
||||
.setCheck(null)
|
||||
.appendField("在(");
|
||||
this.appendDummyInput()
|
||||
.appendField(',');
|
||||
this.appendValueInput("posy")
|
||||
.setCheck(null)
|
||||
.appendField("");
|
||||
this.appendDummyInput()
|
||||
.appendField(')放置')
|
||||
.appendField(new Blockly.FieldDropdown([["障碍", "'wall'"], ["金币", "'coin'"]]), "item");
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
export const game_get_character_img = {
|
||||
init: function () {
|
||||
this.imgArr = this.getLocalImg();
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldDropdown(this.getLocalImg()), "type");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
},
|
||||
onchange: function () {
|
||||
let typeValue = this.getFieldValue("type");
|
||||
//let newImgArr = this.getLocalImg();
|
||||
let newImgArr = this.imgArr;
|
||||
if (this.haveNewSrc(this.imgArr, newImgArr)) {
|
||||
this.imgArr = newImgArr;
|
||||
var typeField = this.getField("type");
|
||||
typeField.menuGenerator_ = this.imgArr;
|
||||
if (this.checkSrc(typeValue, this.imgArr)) {
|
||||
this.setFieldValue(typeValue, "type");
|
||||
} else {
|
||||
this.setFieldValue(this.imgArr[0][1], "type");
|
||||
}
|
||||
}
|
||||
},
|
||||
haveNewSrc: function (oldArr, newArr) {
|
||||
if (oldArr.length !== newArr.length) return true;
|
||||
for (var i = 0; i < oldArr.length; i++) {
|
||||
if (oldArr[i][0].src !== newArr[i][0].src) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
checkSrc: function (newSrc, srcArr) {
|
||||
for (var i = 0; i < srcArr.length; i++) {
|
||||
if (srcArr[i][0].src == newSrc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getLocalImg: function () {
|
||||
let imgArr = [];
|
||||
try {
|
||||
var imgDirArr = ["pegman.png", "astro.png", "panda.png", "robot.png"]
|
||||
for (var i = 0; i < imgDirArr.length; i++) {
|
||||
var dropdownItem = {};
|
||||
dropdownItem.src = "./media/mixpyBuild/characters/" + imgDirArr[i];
|
||||
dropdownItem.width = 40;
|
||||
dropdownItem.height = 45;
|
||||
dropdownItem.alt = "*";
|
||||
var dropdownArr = [];
|
||||
dropdownArr.push(dropdownItem);
|
||||
var dropdownData = imgDirArr[i].substring(0, imgDirArr[i].lastIndexOf("."));
|
||||
dropdownData = '\'' + dropdownData + '\'';
|
||||
dropdownArr.push(dropdownData);
|
||||
imgArr.push(dropdownArr);
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
imgArr = [["'无可用角色'", "'无可用角色'"]];
|
||||
}
|
||||
if (imgArr.length > 0) {
|
||||
return imgArr;
|
||||
}
|
||||
return [["'无可用角色'", "'无可用角色'"]];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const initialize = {
|
||||
init: function () {
|
||||
this.setColour(290);
|
||||
this.appendValueInput("character")
|
||||
.setCheck(null)
|
||||
.appendField("初始化角色为");
|
||||
this.appendDummyInput()
|
||||
// .appendField('初始化角色为')
|
||||
// .appendField(new Blockly.FieldDropdown([["默认⼩⼈","0"],["熊猫","1"],["宇航员","2"],["机器⼈","3"]]), "character")
|
||||
.appendField('面朝')
|
||||
.appendField(new Blockly.FieldDropdown([["北", "0"], ["南", "2"], ["西", "3"], ["东", "1"]]), "direction");
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
export const get_actor_point = {
|
||||
init: function () {
|
||||
this.setColour(290);
|
||||
this.appendDummyInput()
|
||||
.appendField('获取⻆⾊所获分数');
|
||||
this.setOutput(true, Number);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
export const isBarrier = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldDropdown([["北", "0"], ["南", "2"], ["西", "3"], ["东", "1"]]), "direction");
|
||||
this.appendDummyInput()
|
||||
.appendField('侧有障碍');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const randomOil = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("随机生成小车油量");
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
export const isOilFull = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField('需要加油');
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const isLightGreen = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField('信号灯为绿灯');
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const isLightRed = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField('信号灯为红灯');
|
||||
this.setOutput(true, null);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const addOil = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("进加油站加油");
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
|
||||
export const isCirculationRight = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("检查程序循环数目是否正确");
|
||||
this.setPreviousStatement(true);
|
||||
this.setColour(290);
|
||||
this.setTooltip('');
|
||||
}
|
||||
};
|
||||
1512
boards/default_src/python_skulpt_car/converters/data.js
Normal file
1512
boards/default_src/python_skulpt_car/converters/data.js
Normal file
File diff suppressed because it is too large
Load Diff
74
boards/default_src/python_skulpt_car/converters/inout.js
Normal file
74
boards/default_src/python_skulpt_car/converters/inout.js
Normal file
@@ -0,0 +1,74 @@
|
||||
'use strict';
|
||||
|
||||
pbc.globalFunctionD['input'] = function(py2block, func, args, keywords, starargs, kwargs, node){
|
||||
if (args.length !== 1 && args.length !== 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
if (args.length == 1){
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return block("inout_type_input", func.lineno, {
|
||||
"DIR":"str"
|
||||
}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
});}
|
||||
if (args.length == 0){
|
||||
|
||||
return block("inout_type_input", func.lineno, {
|
||||
"DIR":"str"
|
||||
}, {
|
||||
//'VAR':argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
});}
|
||||
}
|
||||
|
||||
|
||||
//int(input('prompt'))在math.js中实现
|
||||
//float(input('prompt'))在lists.js中实现
|
||||
|
||||
pbc.globalFunctionD['print'] = function(py2block, func, args, keywords, starargs, kwargs, node){
|
||||
if (args.length === 1 && keywords.length === 1
|
||||
&& py2block.identifier(keywords[0].arg) === "end"
|
||||
&& keywords[0].value._astname === "Str"
|
||||
//&& py2block.Str_value(keywords[0].value) === ""
|
||||
) { if(py2block.Str_value(keywords[0].value) === ""){//print('Hello',end ="")
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print_inline", func.lineno, {}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "false"
|
||||
})];
|
||||
}
|
||||
else{
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print_end", func.lineno, {
|
||||
}, {
|
||||
'VAR':argblock,
|
||||
'END':py2block.convert(keywords[0].value)
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
}else if (args.length === 1 && keywords.length === 0) { //print('Hello')
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print", func.lineno, {}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "false"
|
||||
})];
|
||||
}else if (args.length != 1 && keywords.length === 0) { //print()
|
||||
var d = py2block.convertElements("ADD", args);
|
||||
|
||||
return [block("inout_print_many", node.lineno, {
|
||||
}, d, {
|
||||
"inline": "true",
|
||||
}, {
|
||||
"@items":args.length
|
||||
})];
|
||||
|
||||
}else{
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
function defDict(type) {
|
||||
var dict = {};
|
||||
return {
|
||||
get: function (key) {
|
||||
if (!dict[key]) {
|
||||
dict[key] = type.constructor();
|
||||
}
|
||||
return dict[key];
|
||||
},
|
||||
dict: dict
|
||||
};
|
||||
}
|
||||
|
||||
function Py2blockConfig (){
|
||||
this.initIgnoreS();
|
||||
this.initModuleAttrD();
|
||||
this.initKnownModuleS();
|
||||
this.initObjectTypeD();
|
||||
}
|
||||
|
||||
var pbc = Py2blockConfig.prototype;
|
||||
pbc.MIXPY = "MIXPY";
|
||||
pbc.board = pbc.MIXPY;
|
||||
pbc.objectFunctionD = defDict({});
|
||||
pbc.moduleFunctionD = defDict({});
|
||||
pbc.moduleAttrD = defDict({});
|
||||
pbc.objectAttrD = defDict({});
|
||||
pbc.globalFunctionD = {};
|
||||
pbc.assignD = defDict({});
|
||||
pbc.ifStatementD= defDict({});
|
||||
pbc.whileStatementD= defDict({});
|
||||
pbc.forStatementD= defDict({});
|
||||
pbc.reservedNameD= {};
|
||||
pbc.knownModuleS = new Set();
|
||||
pbc.objectTypeD = {}; //key:变量名,value:变量类型,如{'a':'List'}
|
||||
pbc.ignoreS = new Set();
|
||||
pbc.pinType = null;
|
||||
pbc.inScope = null;
|
||||
pbc.formatModuleKeyL = [];
|
||||
pbc.formatModuleL = [];
|
||||
|
||||
//忽略某些方法、类、赋值
|
||||
pbc.initIgnoreS = function(){
|
||||
var pythonIgnoreL = [
|
||||
];
|
||||
var boardIgnoreL = [];
|
||||
|
||||
var ignoreL = pythonIgnoreL.concat(boardIgnoreL);
|
||||
for (var i = 0; i < ignoreL.length; i++) {
|
||||
this.ignoreS.add(ignoreL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pbc.initModuleAttrD = function(){
|
||||
}
|
||||
|
||||
pbc.initKnownModuleS = function(){
|
||||
var pythonModuleL = [
|
||||
'math', 'random'
|
||||
];
|
||||
var boardModuleL = [];
|
||||
|
||||
var moduleL = pythonModuleL.concat(boardModuleL);
|
||||
for (var i = 0; i < moduleL.length; i++) {
|
||||
this.knownModuleS.add(moduleL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pbc.initObjectTypeD = function () {
|
||||
this.objectTypeD = {
|
||||
'tina': 'turtle.Turtle',
|
||||
'f': 'open'
|
||||
}
|
||||
}
|
||||
|
||||
pbc.reset = function(){
|
||||
this.initObjectTypeD();
|
||||
}
|
||||
|
||||
var py2block_config = new Py2blockConfig();
|
||||
|
||||
45
boards/default_src/python_skulpt_car/converters/system.js
Normal file
45
boards/default_src/python_skulpt_car/converters/system.js
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
pbc.globalFunctionD['exit'] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return [block("controls_end_program", func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
|
||||
|
||||
pbc.moduleFunctionD.get('time')['time'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return block("controls_millis", func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('time')['localtime'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return block("time_localtime", func.lineno, {
|
||||
"op":'all'
|
||||
}, {}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('time')['sleep'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 1) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("time_sleep", func.lineno, {}, {
|
||||
|
||||
"DELAY_TIME":argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
1127
boards/default_src/python_skulpt_car/converters/turtle.js
Normal file
1127
boards/default_src/python_skulpt_car/converters/turtle.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,120 @@
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(1) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/inout.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(1) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/inout2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(2) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/ctrl.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(2) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/ctrl2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(3) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/math.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(3) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/math2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(4) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/logic.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(4) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/logic2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(5) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/text.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(5) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/text2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(6) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/list3.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(6) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/list4.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(7) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/tuple.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(7) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/tuple2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(8) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/dict.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(8) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/dict2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(9) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/set.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(9) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/set2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(10) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/var.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(10) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/var2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(11) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/func.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(11) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/func2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(12) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/game5.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(12) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/game6.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(13) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/data.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(13) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/data2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(14) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/machine_learning.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(14) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/machine_learning2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
9
boards/default_src/python_skulpt_car/export.js
Normal file
9
boards/default_src/python_skulpt_car/export.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as MicropythonESP32Pins from './blocks/esp32_profile';
|
||||
import * as MicropythonESP32PinsBlocks from './blocks/pins';
|
||||
import * as MicropythonESP32PinsGenerators from './generators/pins';
|
||||
|
||||
export {
|
||||
MicropythonESP32Pins,
|
||||
MicropythonESP32PinsBlocks,
|
||||
MicropythonESP32PinsGenerators
|
||||
};
|
||||
202
boards/default_src/python_skulpt_car/generators/game.js
Normal file
202
boards/default_src/python_skulpt_car/generators/game.js
Normal file
@@ -0,0 +1,202 @@
|
||||
export const game_init = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = generator.statementToCode(block, "DO0") + 'blocklygame.initMap(\'block_id=' + block.id + '\');\n'
|
||||
|
||||
var code_piece = [];
|
||||
code_piece = code.split("\n");
|
||||
for (var i = 0; i < code_piece.length; i++) {
|
||||
if ((code_piece[i].indexOf(" ") >= 0)) {
|
||||
code_piece[i] = code_piece[i].replace(" ", "");
|
||||
}
|
||||
}
|
||||
code = ""
|
||||
for (var i = 0; i < code_piece.length; i++) {
|
||||
code += code_piece[i] + '\n'
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
// export const move_direction = function(block) {
|
||||
// generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
// var Direction = this.getFieldValue('direction');
|
||||
// return 'actor.moveDirection('+Direction+',\'block_id=' + block.id + '\');\n';
|
||||
// }
|
||||
|
||||
export const move_direction_steps = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var times = generator.valueToCode(this, 'times', generator.ORDER_ATOMIC);
|
||||
var Direction = this.getFieldValue('direction');
|
||||
var d = 'actor.moveDirection(' + Direction + ',\'block_id=' + block.id + '\');\n',
|
||||
d = generator.addLoopTrap(d, block.id) || generator.PASS;
|
||||
return 'for _my_variable in range(' + times + '):\n\t' + d;
|
||||
}
|
||||
|
||||
export const initSettedMap_1 = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'blocklygame.settedMap(0,\'block_id=' + block.id + '\');\n' + 'actor=blocklygame.Actor(\'car\',2);\n';
|
||||
}
|
||||
|
||||
export const initSettedMap_2 = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'blocklygame.settedMap(1,\'block_id=' + block.id + '\');\n' + 'actor=blocklygame.Actor(\'car\',2);\n';
|
||||
}
|
||||
|
||||
export const initSettedMap_3 = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'blocklygame.settedMap(2,\'block_id=' + block.id + '\');\n' + 'actor=blocklygame.Actor(\'car\',2);\n';
|
||||
}
|
||||
|
||||
export const initSettedMap_4 = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'blocklygame.settedMap(3,\'block_id=' + block.id + '\');\n' + 'actor=blocklygame.Actor(\'car\',2);\n' + 'actor.randomOil(\'block_id=' + block.id + '\');\n';
|
||||
}
|
||||
|
||||
export const initSettedMap_5 = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'blocklygame.settedMap(4,\'block_id=' + block.id + '\');\n' + 'actor=blocklygame.Actor(\'car\',2);\n';
|
||||
}
|
||||
|
||||
export const initSettedMap_6 = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'blocklygame.settedMap(5,\'block_id=' + block.id + '\');\n' + 'actor=blocklygame.Actor(\'car\',2);\n';
|
||||
}
|
||||
|
||||
export const initSettedMap_7 = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'blocklygame.settedMap(6,\'block_id=' + block.id + '\');\n' + 'actor=blocklygame.Actor(\'car\',2);\n';
|
||||
}
|
||||
|
||||
// export const move_forward = function(block) {
|
||||
// generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
// return 'actor.moveForward(\'block_id=' + block.id + '\');\n';
|
||||
// }
|
||||
|
||||
// export const move_backward = function(block) {
|
||||
// generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
// var code = 'actor.moveBackward(\'block_id=' + block.id + '\');\n';
|
||||
// return code;
|
||||
// }
|
||||
|
||||
export const Turn = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var dropdown_Direction = this.getFieldValue('Direction');
|
||||
var code = 'actor.turn(\'' + dropdown_Direction + "','block_id=" + block.id + '\');\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const isDone = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = 'actor.isDone(\'block_id=' + block.id + '\')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const isPath = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var dropdown_Direction = this.getFieldValue('Direction');
|
||||
var code = 'actor.isPath(\'' + dropdown_Direction + "','block_id=" + block.id + '\')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
// 从这里开始是新的块
|
||||
export const get_actor_point = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = 'actor.getPoint(\'block_id=' + block.id + '\')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const game_get_local_img = function (_, generator) {
|
||||
var dropdown_type = this.getFieldValue('type');
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = dropdown_type;
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const set_map = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var value_x = generator.valueToCode(this, 'x', generator.ORDER_ATOMIC);
|
||||
var value_y = generator.valueToCode(this, 'y', generator.ORDER_ATOMIC);
|
||||
var startPos = generator.valueToCode(this, 'startPos', generator.ORDER_ATOMIC);
|
||||
var endPos = generator.valueToCode(this, 'endPos', generator.ORDER_ATOMIC);
|
||||
var bg_pic = generator.valueToCode(this, 'background', generator.ORDER_ATOMIC);
|
||||
|
||||
return 'blocklygame.setMap(' + value_x + ',' + value_y + ',' + startPos + ',' + endPos + ',' + bg_pic + ",'block_id=" + block.id + '\');\n';
|
||||
}
|
||||
|
||||
export const game_get_character_img = function (_, generator) {
|
||||
var dropdown_type = this.getFieldValue('type');
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = dropdown_type;
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const initialize = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
// var value_character = this.getFieldValue('character');
|
||||
var value_direction = this.getFieldValue('direction');
|
||||
var value_character = generator.valueToCode(this, 'character', generator.ORDER_ATOMIC);
|
||||
return 'actor=blocklygame.Actor(' + value_character + ',' + value_direction + ",'block_id=" + block.id + '\');\n';
|
||||
}
|
||||
|
||||
export const place_item = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var value_posx = generator.valueToCode(this, 'posx', generator.ORDER_ATOMIC);
|
||||
var value_posy = generator.valueToCode(this, 'posy', generator.ORDER_ATOMIC);
|
||||
var value_item = this.getFieldValue('item');
|
||||
return 'blocklygame.placeItem(' + value_posx + ',' + value_posy + ',' + value_item + ",'block_id=" + block.id + '\');\n';
|
||||
}
|
||||
|
||||
export const game_get_path_img = function (_, generator) {
|
||||
var dropdown_type = this.getFieldValue('type');
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = dropdown_type;
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const set_pathtype = function (block, generator) {
|
||||
generator.definitions_['import_blocklygame'] = 'import blocklygame';
|
||||
var path_type = generator.valueToCode(this, 'pathtype', generator.ORDER_ATOMIC);
|
||||
return 'blocklygame.setPathType(' + path_type + ",'block_id=" + block.id + '\');\n';
|
||||
// return 'actor.getPoint();\n';
|
||||
}
|
||||
|
||||
export const isBarrier = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var dropdown_Direction = this.getFieldValue('direction');
|
||||
var code = 'actor.isBarrier(' + dropdown_Direction + ",'block_id=" + block.id + '\')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const randomOil = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
return 'actor.randomOil(\'block_id=' + block.id + '\');\n';
|
||||
}
|
||||
|
||||
export const isOilFull = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = 'actor.isOilFull(\'block_id=' + block.id + '\')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const isLightGreen = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = 'actor.isLightGreen(\'block_id=' + block.id + '\')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const isLightRed = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = 'not actor.isLightGreen(\'block_id=' + block.id + '\')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const addOil = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = 'actor.addOil(\'block_id=' + block.id + '\');\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const isCirculationRight = function (block, generator) {
|
||||
generator.definitions_.import_blocklygame = "import blocklygame";
|
||||
var code = 'actor.isCirculationRight(\'block_id=' + block.id + '\');\n';
|
||||
return code;
|
||||
}
|
||||
101
boards/default_src/python_skulpt_car/index.js
Normal file
101
boards/default_src/python_skulpt_car/index.js
Normal file
@@ -0,0 +1,101 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import { Profile } from 'mixly';
|
||||
|
||||
import Variables from '@mixly/python/others/variables';
|
||||
import Procedures from '@mixly/python/others/procedures';
|
||||
import { Python } from '@mixly/python/python_generator';
|
||||
|
||||
import * as PythonVariablesBlocks from '@mixly/python/blocks/variables';
|
||||
import * as PythonControlBlocks from '@mixly/python/blocks/control';
|
||||
import * as PythonMathBlocks from '@mixly/python/blocks/math';
|
||||
import * as PythonTextBlocks from '@mixly/python/blocks/text';
|
||||
import * as PythonListsBlocks from '@mixly/python/blocks/lists';
|
||||
import * as PythonDictsBlocks from '@mixly/python/blocks/dicts';
|
||||
import * as PythonLogicBlocks from '@mixly/python/blocks/logic';
|
||||
import * as PythonStorageBlocks from '@mixly/python/blocks/storage';
|
||||
import * as PythonProceduresBlocks from '@mixly/python/blocks/procedures';
|
||||
import * as PythonTupleBlocks from '@mixly/python/blocks/tuple';
|
||||
import * as PythonSetBlocks from '@mixly/python/blocks/set';
|
||||
import * as PythonHtmlBlocks from '@mixly/python/blocks/html';
|
||||
import * as PythonUtilityBlocks from '@mixly/python/blocks/utility';
|
||||
|
||||
import * as SkulptPyDataBlocks from '@mixly/python-skulpt/blocks/data';
|
||||
import * as SkulptPyInoutBlocks from '@mixly/python-skulpt/blocks/inout';
|
||||
import * as SkulptPySystemBlocks from '@mixly/python-skulpt/blocks/system';
|
||||
import * as SkulptPyTurtleBlocks from '@mixly/python-skulpt/blocks/turtle';
|
||||
|
||||
import * as GameBlocks from './blocks/game';
|
||||
|
||||
import * as PythonVariablesGenerators from '@mixly/python/generators/variables';
|
||||
import * as PythonControlGenerators from '@mixly/python/generators/control';
|
||||
import * as PythonMathGenerators from '@mixly/python/generators/math';
|
||||
import * as PythonTextGenerators from '@mixly/python/generators/text';
|
||||
import * as PythonListsGenerators from '@mixly/python/generators/lists';
|
||||
import * as PythonDictsGenerators from '@mixly/python/generators/dicts';
|
||||
import * as PythonLogicGenerators from '@mixly/python/generators/logic';
|
||||
import * as PythonStorageGenerators from '@mixly/python/generators/storage';
|
||||
import * as PythonProceduresGenerators from '@mixly/python/generators/procedures';
|
||||
import * as PythonTupleGenerators from '@mixly/python/generators/tuple';
|
||||
import * as PythonSetGenerators from '@mixly/python/generators/set';
|
||||
import * as PythonHtmlGenerators from '@mixly/python/generators/html';
|
||||
import * as PythonUtilityGenerators from '@mixly/python/generators/utility';
|
||||
|
||||
import * as SkulptPyDataGenerators from '@mixly/python-skulpt/generators/data';
|
||||
import * as SkulptPyInoutGenerators from '@mixly/python-skulpt/generators/inout';
|
||||
import * as SkulptPySystemGenerators from '@mixly/python-skulpt/generators/system';
|
||||
import * as SkulptPyTurtleGenerators from '@mixly/python-skulpt/generators/turtle';
|
||||
|
||||
import * as GameGenerators from './generators/game';
|
||||
|
||||
import './css/color_mixpy_python_skulpt.css';
|
||||
|
||||
Object.assign(Blockly.Variables, Variables);
|
||||
Object.assign(Blockly.Procedures, Procedures);
|
||||
Blockly.Python = Python;
|
||||
Blockly.generator = Python;
|
||||
|
||||
Profile.default = {};
|
||||
|
||||
Object.assign(
|
||||
Blockly.Blocks,
|
||||
PythonVariablesBlocks,
|
||||
PythonControlBlocks,
|
||||
PythonMathBlocks,
|
||||
PythonTextBlocks,
|
||||
PythonListsBlocks,
|
||||
PythonDictsBlocks,
|
||||
PythonLogicBlocks,
|
||||
PythonStorageBlocks,
|
||||
PythonProceduresBlocks,
|
||||
PythonTupleBlocks,
|
||||
PythonSetBlocks,
|
||||
PythonHtmlBlocks,
|
||||
PythonUtilityBlocks,
|
||||
SkulptPyDataBlocks,
|
||||
SkulptPyInoutBlocks,
|
||||
SkulptPySystemBlocks,
|
||||
SkulptPyTurtleBlocks,
|
||||
GameBlocks,
|
||||
);
|
||||
|
||||
Object.assign(
|
||||
Blockly.Python.forBlock,
|
||||
PythonVariablesGenerators,
|
||||
PythonControlGenerators,
|
||||
PythonMathGenerators,
|
||||
PythonTextGenerators,
|
||||
PythonListsGenerators,
|
||||
PythonDictsGenerators,
|
||||
PythonLogicGenerators,
|
||||
PythonStorageGenerators,
|
||||
PythonProceduresGenerators,
|
||||
PythonTupleGenerators,
|
||||
PythonSetGenerators,
|
||||
PythonHtmlGenerators,
|
||||
PythonUtilityGenerators,
|
||||
SkulptPyDataGenerators,
|
||||
SkulptPyInoutGenerators,
|
||||
SkulptPySystemGenerators,
|
||||
SkulptPyTurtleGenerators,
|
||||
GameGenerators
|
||||
);
|
||||
13
boards/default_src/python_skulpt_car/origin/config.json
Normal file
13
boards/default_src/python_skulpt_car/origin/config.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"language": "Python",
|
||||
"nav": {
|
||||
"webrun": true,
|
||||
"websteprun": true,
|
||||
"webcancel": true,
|
||||
"save": {
|
||||
"py": true
|
||||
},
|
||||
"levelSelector": true
|
||||
},
|
||||
"saveMixWithCode": false
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
BIN
boards/default_src/python_skulpt_car/origin/media/webpy.png
Normal file
BIN
boards/default_src/python_skulpt_car/origin/media/webpy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
BIN
boards/default_src/python_skulpt_car/origin/media/webpy0.png
Normal file
BIN
boards/default_src/python_skulpt_car/origin/media/webpy0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -0,0 +1,3 @@
|
||||
var mixpyProject = new MixpyProject();
|
||||
var pyengine = new PyEngine({}, mixpyProject);
|
||||
Sk.__future__ = Sk.python3;
|
||||
32
boards/default_src/python_skulpt_car/package.json
Normal file
32
boards/default_src/python_skulpt_car/package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@mixly/python-skulpt-car",
|
||||
"version": "1.0.0",
|
||||
"description": "适用于mixly的python skulpt car模块",
|
||||
"scripts": {
|
||||
"build:dev": "webpack --config=webpack.dev.js",
|
||||
"build:prod": "webpack --config=webpack.prod.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mixly/python": "1.0.0"
|
||||
},
|
||||
"main": "./export.js",
|
||||
"author": "Mixly Team",
|
||||
"keywords": [
|
||||
"mixly",
|
||||
"mixly-plugin",
|
||||
"python-skulpt-car"
|
||||
],
|
||||
"homepage": "https://gitee.com/mixly2/mixly2.0_src/tree/develop/boards/default_src/python_skulpt_car",
|
||||
"bugs": {
|
||||
"url": "https://gitee.com/mixly2/mixly2.0_src/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitee.com/mixly2/mixly2.0_src.git",
|
||||
"directory": "default_src/python_skulpt_car"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"license": "Apache 2.0"
|
||||
}
|
||||
1230
boards/default_src/python_skulpt_car/template.xml
Normal file
1230
boards/default_src/python_skulpt_car/template.xml
Normal file
File diff suppressed because it is too large
Load Diff
12
boards/default_src/python_skulpt_car/webpack.common.js
Normal file
12
boards/default_src/python_skulpt_car/webpack.common.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const path = require("path");
|
||||
const common = require("../../../webpack.common");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
module.exports = merge(common, {
|
||||
resolve: {
|
||||
alias: {
|
||||
'@mixly/python': path.resolve(__dirname, '../python'),
|
||||
'@mixly/python-skulpt': path.resolve(__dirname, '../python_skulpt')
|
||||
}
|
||||
}
|
||||
});
|
||||
21
boards/default_src/python_skulpt_car/webpack.dev.js
Normal file
21
boards/default_src/python_skulpt_car/webpack.dev.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const path = require("path");
|
||||
const common = require("./webpack.common");
|
||||
const { merge } = require("webpack-merge");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const ESLintPlugin = require('eslint-webpack-plugin');
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "development",
|
||||
devtool: 'source-map',
|
||||
plugins: [
|
||||
new ESLintPlugin({
|
||||
context: process.cwd(),
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: false,
|
||||
template: path.resolve(process.cwd(), 'template.xml'),
|
||||
filename: 'index.xml',
|
||||
minify: false
|
||||
}),
|
||||
]
|
||||
});
|
||||
27
boards/default_src/python_skulpt_car/webpack.prod.js
Normal file
27
boards/default_src/python_skulpt_car/webpack.prod.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const path = require("path");
|
||||
const common = require("./webpack.common");
|
||||
const { merge } = require("webpack-merge");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
var HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "production",
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
extractComments: false,
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: false,
|
||||
template: path.resolve(process.cwd(), 'template.xml'),
|
||||
filename: 'index.xml',
|
||||
minify: {
|
||||
removeAttributeQuotes: true,
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user