选择汽车后,我需要在下一条语句中选择汽车
我删除了一些代码,只留下重要部分
Blockly.Blocks.car_selection = {
init() {
const cars = STORE.getCars();
const carsSelection = cars.map(car => [car.name, car._id]);
this.appendStatementInput('CarSelection')
.appendField('Select the Car')
.appendField(new Blockly.FieldDropdown(carsSelection), 'Car');
this.setNextStatement(true, 'Number');
},
};
Blockly.Blocks.car_movement = {
init() {
this.appendValueInput('Movement')
.setCheck('Array')
.appendField('Go X')
.appendField(new Blockly.FieldNumber(0, 0, 20000), 'posX')
.appendField('Y')
.appendField(new Blockly.FieldNumber(0, 0, 20000), 'posY');
this.setPreviousStatement(true, 'Number');
this.setNextStatement(true, null);
},
};
而且代码...
在car_movement
blockly中,我怎样才能选择汽车?
Blockly.JSON.car_selection = function(block) {
const car = block.getFieldValue('Car');
const statements = statementsCode
.split('\n')
.filter(it => it.length > 0)
.map(it => JSON.parse(it));
const command = {
topic: `to/car/${robotIdentifier}`,
packet: statements,
};
return `${JSON.stringify(command, null, 2).trim()}\n`;
};
Blockly.JSON.car_movement = function(block) {
const x = block.getFieldValue('posX');
const y = block.getFieldValue('posY');
// TODO HOW TO GET CAR ID FROM PREVIOUS BLOCKLY ?
// const car = STORE.getCar(carId); <-- I NEED THE CAR ID
const jsonSpec = {
x,
y,
currentX: car.x,
currentY: car.y,
};
return `${JSON.stringify(jsonSpec).trim()}\n`;
};