Skip to content

Commit e5b71da

Browse files
committed
wip #44
1 parent 4ad953a commit e5b71da

File tree

5 files changed

+228
-73
lines changed

5 files changed

+228
-73
lines changed

src/assets/js/blockly/blocks.js

Lines changed: 157 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,158 @@ const sbsPrefix = '';
2626

2727
Blockly.Blocks.CoderBotSettings = {};
2828

29+
Blockly.Blocks.coderbot_basic_repeat = {
30+
/**
31+
* Block for repeat n times (internal number).
32+
* @this Blockly.Block
33+
*/
34+
init(self) {
35+
this.setHelpUrl(Blockly.Msg.CONTROLS_REPEAT_HELPURL);
36+
this.setColour(120);
37+
const di = this.appendDummyInput();
38+
di.appendField(new Blockly.FieldImage('/static/images/blocks/loop_repeat.png', 32, 32, '*'));
39+
di.appendField(new Blockly.FieldTextInput('10',
40+
Blockly.FieldTextInput.nonnegativeIntegerValidator), 'TIMES');
41+
const si = this.appendStatementInput('DO');
42+
this.setPreviousStatement(true);
43+
this.setNextStatement(true);
44+
this.setTooltip(Blockly.Msg.CONTROLS_REPEAT_TOOLTIP);
45+
},
46+
};
47+
48+
Blockly.Python.coderbot_basic_repeat = function (block) {
49+
// Repeat n times (internal number).
50+
const repeats = parseInt(block.getFieldValue('TIMES'), 10);
51+
let branch = Blockly.Python.statementToCode(block, 'DO');
52+
branch = Blockly.Python.addLoopTrap(branch, block.id) ||
53+
Blockly.Python.LOOP_PASS;
54+
const loopVar = Blockly.Python.variableDB_.getDistinctName(
55+
'count', Blockly.Variables.NAME_TYPE,
56+
);
57+
const code = `for ${loopVar} in range(${repeats}):\n${branch}`;
58+
return code;
59+
};
60+
61+
Blockly.Blocks.coderbot_basic_moveForward = {
62+
// Block for moving forward.
63+
init() {
64+
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Move');
65+
this.setColour(40);
66+
const di = this.appendDummyInput();
67+
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_forward.png', 32, 32, '*'));
68+
this.setPreviousStatement(true);
69+
this.setNextStatement(true);
70+
this.setTooltip('CoderBot_moveForwardTooltip');
71+
},
72+
};
73+
74+
Blockly.Python.coderbot_basic_moveForward = function (block) {
75+
// Generate Python for moving forward.
76+
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_MOVE_MOTION) {
77+
return `${sbsPrefix}get_motion().move(dist=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_FW_DEF_ELAPSE})\n`;
78+
}
79+
return `${sbsPrefix}get_bot().forward(speed=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_FW_DEF_SPEED}, elapse=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_FW_DEF_ELAPSE})\n`;
80+
};
81+
82+
Blockly.Blocks.coderbot_basic_moveBackward = {
83+
// Block for moving forward.
84+
init() {
85+
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Move');
86+
this.setColour(40);
87+
const di = this.appendDummyInput();
88+
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_backward.png', 32, 32, '*'));
89+
this.setPreviousStatement(true);
90+
this.setNextStatement(true);
91+
this.setTooltip('CoderBot_moveBackwardTooltip');
92+
},
93+
};
94+
95+
Blockly.Python.coderbot_basic_moveBackward = function (block) {
96+
// Generate Python for moving forward.
97+
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_MOVE_MOTION) {
98+
return `${sbsPrefix}get_motion().move(dist=${-Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_FW_DEF_ELAPSE})\n`;
99+
}
100+
return `${sbsPrefix}get_bot().backward(speed=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_FW_DEF_SPEED}, elapse=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_FW_DEF_ELAPSE})\n`;
101+
};
102+
103+
Blockly.Blocks.coderbot_basic_turnLeft = {
104+
// Block for turning left.
105+
init() {
106+
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Turn');
107+
this.setColour(40);
108+
const di = this.appendDummyInput();
109+
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_left.png', 32, 32, '*'));
110+
this.setPreviousStatement(true);
111+
this.setNextStatement(true);
112+
this.setTooltip(('CoderBot_turnTooltip'));
113+
},
114+
};
115+
116+
Blockly.Python.coderbot_basic_turnLeft = function (block) {
117+
// Generate Python for turning left.
118+
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_MOVE_MOTION) {
119+
return `${sbsPrefix}get_motion().turn(angle=${-Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_ELAPSE})\n`;
120+
}
121+
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_MOVE_MPU) {
122+
return `${sbsPrefix}get_bot().turn_angle(speed=${-Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_SPEED}, angle=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_ELAPSE})\n`;
123+
}
124+
return `${sbsPrefix}get_bot().left(speed=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_SPEED}, elapse=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_ELAPSE})\n`;
125+
};
126+
127+
Blockly.Blocks.coderbot_basic_turnRight = {
128+
// Block for turning right.
129+
init() {
130+
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Turn');
131+
this.setColour(40);
132+
const di = this.appendDummyInput();
133+
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_right.png', 32, 32, '*'));
134+
this.setPreviousStatement(true);
135+
this.setNextStatement(true);
136+
this.setTooltip(('CoderBot_turnTooltip'));
137+
},
138+
};
139+
140+
Blockly.Python.coderbot_basic_turnRight = function (block) {
141+
// Generate Python for turning left or right.
142+
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_MOVE_MOTION) {
143+
return `${sbsPrefix}get_motion().turn(angle=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_ELAPSE})\n`;
144+
}
145+
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_MOVE_MPU) {
146+
return `${sbsPrefix}get_bot().turn_angle(speed=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_SPEED}, angle=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_ELAPSE})\n`;
147+
}
148+
return `${sbsPrefix}get_bot().right(speed=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_SPEED}, elapse=${Blockly.Blocks.CoderBotSettings.CODERBOT_MOV_TR_DEF_ELAPSE})\n`;
149+
};
150+
151+
Blockly.Blocks.coderbot_basic_audio_say = {
152+
// Block for text to speech.
153+
init() {
154+
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Say');
155+
this.setColour(220);
156+
const vi = this.appendValueInput('TEXT');
157+
vi.setCheck(['String', 'Number', 'Date']);
158+
vi.appendField(new Blockly.FieldImage('/static/images/blocks/say.png', 32, 32, '*'));
159+
vi.appendField(new Blockly.FieldDropdown([
160+
[Blockly.Msg.CODERBOT_LOCALE_EN, 'en'],
161+
[Blockly.Msg.CODERBOT_LOCALE_IT, 'it'],
162+
[Blockly.Msg.CODERBOT_LOCALE_FR, 'fr'],
163+
[Blockly.Msg.CODERBOT_LOCALE_ES, 'es'],
164+
]), 'LOCALE');
165+
166+
this.setPreviousStatement(true);
167+
this.setNextStatement(true);
168+
this.setTooltip(('CoderBot_sayTooltip'));
169+
},
170+
};
171+
172+
Blockly.Python.coderbot_basic_audio_say = function (block) {
173+
// Generate Python for turning left or right.
174+
const text = Blockly.Python.valueToCode(block, 'TEXT',
175+
Blockly.Python.ORDER_NONE) || '\'\'';
176+
const locale = block.getFieldValue('LOCALE');
177+
return `${sbsPrefix}get_audio().say(${text}, locale="${locale}")\n`;
178+
};
179+
180+
29181
Blockly.Blocks.coderbot_repeat = {
30182
/**
31183
* Block for repeat n times (internal number).
@@ -81,11 +233,7 @@ Blockly.Blocks.coderbot_moveForward = {
81233
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Move');
82234
this.setColour(40);
83235
const di = this.appendDummyInput();
84-
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_LEVEL.indexOf('basic') >= 0) {
85-
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_forward.png', 32, 32, '*'));
86-
} else {
87-
di.appendField(Blockly.Msg.CODERBOT_MOVE_FORWARD);
88-
}
236+
di.appendField(Blockly.Msg.CODERBOT_MOVE_FORWARD);
89237
this.setPreviousStatement(true);
90238
this.setNextStatement(true);
91239
this.setTooltip('CoderBot_moveForwardTooltip');
@@ -106,11 +254,7 @@ Blockly.Blocks.coderbot_moveBackward = {
106254
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Move');
107255
this.setColour(40);
108256
const di = this.appendDummyInput();
109-
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_LEVEL.indexOf('basic') >= 0) {
110-
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_backward.png', 32, 32, '*'));
111-
} else {
112-
di.appendField(Blockly.Msg.CODERBOT_MOVE_BACKWARD);
113-
}
257+
di.appendField(Blockly.Msg.CODERBOT_MOVE_BACKWARD);
114258
this.setPreviousStatement(true);
115259
this.setNextStatement(true);
116260
this.setTooltip('CoderBot_moveBackwardTooltip');
@@ -131,11 +275,7 @@ Blockly.Blocks.coderbot_turnLeft = {
131275
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Turn');
132276
this.setColour(40);
133277
const di = this.appendDummyInput();
134-
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_LEVEL.indexOf('basic') >= 0) {
135-
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_left.png', 32, 32, '*'));
136-
} else {
137-
di.appendField(Blockly.Msg.CODERBOT_MOVE_LEFT);
138-
}
278+
di.appendField(Blockly.Msg.CODERBOT_MOVE_LEFT);
139279
this.setPreviousStatement(true);
140280
this.setNextStatement(true);
141281
this.setTooltip(('CoderBot_turnTooltip'));
@@ -159,11 +299,7 @@ Blockly.Blocks.coderbot_turnRight = {
159299
this.setHelpUrl('http://code.google.com/p/blockly/wiki/Turn');
160300
this.setColour(40);
161301
const di = this.appendDummyInput();
162-
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_LEVEL.indexOf('basic') >= 0) {
163-
di.appendField(new Blockly.FieldImage('/static/images/blocks/move_right.png', 32, 32, '*'));
164-
} else {
165-
di.appendField(Blockly.Msg.CODERBOT_MOVE_RIGHT);
166-
}
302+
di.appendField(Blockly.Msg.CODERBOT_MOVE_RIGHT);
167303
this.setPreviousStatement(true);
168304
this.setNextStatement(true);
169305
this.setTooltip(('CoderBot_turnTooltip'));
@@ -188,11 +324,7 @@ Blockly.Blocks.coderbot_audio_say = {
188324
this.setColour(220);
189325
const vi = this.appendValueInput('TEXT');
190326
vi.setCheck(['String', 'Number', 'Date']);
191-
if (Blockly.Blocks.CoderBotSettings.CODERBOT_PROG_LEVEL.indexOf('basic') >= 0) {
192-
vi.appendField(new Blockly.FieldImage('/static/images/blocks/say.png', 32, 32, '*'));
193-
} else {
194-
vi.appendField(Blockly.Msg.CODERBOT_SAY);
195-
}
327+
vi.appendField(Blockly.Msg.CODERBOT_SAY);
196328
vi.appendField(new Blockly.FieldDropdown([
197329
[Blockly.Msg.CODERBOT_LOCALE_EN, 'en'],
198330
[Blockly.Msg.CODERBOT_LOCALE_IT, 'it'],

src/assets/toolbox_adv.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,36 @@
662662
}
663663
]
664664
},
665+
{
666+
"kind": "category",
667+
"name": "CoderBot - Base",
668+
"colour": "40",
669+
"contents": [{
670+
"kind": "block",
671+
"type": "coderbot_basic_moveForward"
672+
},
673+
{
674+
"kind": "block",
675+
"type": "coderbot_basic_moveBackward"
676+
},
677+
{
678+
"kind": "block",
679+
"type": "coderbot_basic_turnLeft"
680+
},
681+
{
682+
"kind": "block",
683+
"type": "coderbot_basic_turnRight"
684+
},
685+
{
686+
"kind": "block",
687+
"type": "coderbot_basic_repeat"
688+
},
689+
{
690+
"kind": "block",
691+
"type": "coderbot_basic_audio_say"
692+
}
693+
]
694+
},
665695
{
666696
"kind": "category",
667697
"name": "Camera",

src/common/coderbot.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,7 @@ class CoderBot {
151151
.then((response) => {
152152
this.$store.commit('setInfo', response.data);
153153
});
154-
const p3 = this.$axios.get(`${this.CB}/logs`)
155-
.then((response) => {
156-
this.$store.commit('setLogs', response.data);
157-
});
158-
return Promise.all([p1, p2, p3]);
154+
return Promise.all([p1, p2]);
159155
}
160156

161157
deleteMusicPackage(pkgNameID) {

src/components/ActivityEditor.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,49 +647,49 @@ export default {
647647
{
648648
action: 'clearProgramDlg',
649649
icon: 'clear',
650-
label: this.$i18n.t('message.activity_program_clear'),
650+
label: 'message.activity_program_clear',
651651
type: 'text',
652652
},
653653
{
654654
action: 'saveProgram',
655655
icon: 'save',
656-
label: this.$i18n.t('message.activity_program_save'),
656+
label: 'message.activity_program_save',
657657
type: 'text',
658658
},
659659
{
660660
action: 'toggleSaveAs',
661661
icon: 'edit',
662-
label: this.$i18n.t('message.activity_program_save_as'),
662+
label: 'message.activity_program_save_as',
663663
type: 'text',
664664
},
665665
{
666666
action: 'loadProgramList',
667667
icon: 'folder_open',
668-
label: this.$i18n.t('message.activity_program_load'),
668+
label: 'message.activity_program_load',
669669
type: 'text',
670670
},
671671
{
672672
action: 'runProgram',
673673
icon: 'play_arrow',
674-
label: this.$i18n.t('message.activity_program_run'),
674+
label: 'message.activity_program_run',
675675
type: 'text',
676676
},
677677
{
678678
action: 'getProgramCode',
679679
icon: 'code',
680-
label: this.$i18n.t('message.activity_program_show_code'),
680+
label: 'message.activity_program_show_code',
681681
type: 'text',
682682
},
683683
{
684684
action: 'exportProgram',
685685
icon: 'fa-file-export',
686-
label: this.$i18n.t('message.activity_program_export'),
686+
label: 'message.activity_program_export',
687687
type: 'text',
688688
},
689689
{
690690
action: 'pickFile',
691691
icon: 'fa-file-import',
692-
label: this.$i18n.t('message.activity_program_import'),
692+
label: 'message.activity_program_import',
693693
type: 'text',
694694
},
695695
/*

0 commit comments

Comments
 (0)