Refactor VoiceControl to handle server-side movement and state commands directly
This commit is contained in:
@@ -60,52 +60,68 @@ export default function VoiceControl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const turtleId = selectedTurtle.turtleID;
|
const turtleId = selectedTurtle.turtleID;
|
||||||
let action = null;
|
let actionName = null;
|
||||||
let param = null;
|
|
||||||
|
|
||||||
// Parse voice commands
|
// Movement commands (server-side)
|
||||||
if (command.includes('forward') || command.includes('go ahead')) {
|
if (command.includes('forward') || command.includes('go ahead')) {
|
||||||
action = 'forward';
|
moveForward(turtleId);
|
||||||
|
actionName = 'forward';
|
||||||
} else if (command.includes('back') || command.includes('backward')) {
|
} else if (command.includes('back') || command.includes('backward')) {
|
||||||
action = 'back';
|
moveBack(turtleId);
|
||||||
|
actionName = 'back';
|
||||||
} else if (command.includes('turn left') || command.includes('left')) {
|
} else if (command.includes('turn left') || command.includes('left')) {
|
||||||
action = 'turnLeft';
|
turnLeft(turtleId);
|
||||||
|
actionName = 'turn left';
|
||||||
} else if (command.includes('turn right') || command.includes('right')) {
|
} else if (command.includes('turn right') || command.includes('right')) {
|
||||||
action = 'turnRight';
|
turnRight(turtleId);
|
||||||
|
actionName = 'turn right';
|
||||||
} else if (command.includes('go up') || command.includes('move up')) {
|
} else if (command.includes('go up') || command.includes('move up')) {
|
||||||
action = 'up';
|
moveUp(turtleId);
|
||||||
|
actionName = 'up';
|
||||||
} else if (command.includes('go down') || command.includes('move down')) {
|
} else if (command.includes('go down') || command.includes('move down')) {
|
||||||
action = 'down';
|
moveDown(turtleId);
|
||||||
|
actionName = 'down';
|
||||||
} else if (command.includes('dig')) {
|
} else if (command.includes('dig')) {
|
||||||
if (command.includes('up')) {
|
if (command.includes('up')) {
|
||||||
action = 'digUp';
|
digBlockUp(turtleId);
|
||||||
|
actionName = 'dig up';
|
||||||
} else if (command.includes('down')) {
|
} else if (command.includes('down')) {
|
||||||
action = 'digDown';
|
digBlockDown(turtleId);
|
||||||
|
actionName = 'dig down';
|
||||||
} else {
|
} else {
|
||||||
action = 'dig';
|
digBlock(turtleId);
|
||||||
|
actionName = 'dig';
|
||||||
}
|
}
|
||||||
} else if (command.includes('place') || command.includes('build')) {
|
} else if (command.includes('place') || command.includes('build')) {
|
||||||
action = 'place';
|
placeBlock(turtleId);
|
||||||
|
actionName = 'place';
|
||||||
|
// State machine commands (server-side)
|
||||||
} else if (command.includes('explore') || command.includes('start exploring')) {
|
} else if (command.includes('explore') || command.includes('start exploring')) {
|
||||||
action = 'explore';
|
setTurtleState(turtleId, 'exploring');
|
||||||
|
actionName = 'explore';
|
||||||
} else if (command.includes('mine') || command.includes('start mining')) {
|
} else if (command.includes('mine') || command.includes('start mining')) {
|
||||||
action = 'mine';
|
setTurtleState(turtleId, 'mining');
|
||||||
|
actionName = 'mine';
|
||||||
} else if (command.includes('return home') || command.includes('go home') || command.includes('come back')) {
|
} else if (command.includes('return home') || command.includes('go home') || command.includes('come back')) {
|
||||||
action = 'returnHome';
|
setTurtleState(turtleId, 'goHome');
|
||||||
|
actionName = 'go home';
|
||||||
} else if (command.includes('stop')) {
|
} else if (command.includes('stop')) {
|
||||||
action = 'stop';
|
setTurtleState(turtleId, 'idle');
|
||||||
} else if (command.includes('set home') || command.includes('mark home')) {
|
actionName = 'idle';
|
||||||
action = 'setHome';
|
|
||||||
} else if (command.includes('refuel')) {
|
} else if (command.includes('refuel')) {
|
||||||
action = 'refuel';
|
setTurtleState(turtleId, 'refueling');
|
||||||
} else if (command.includes('status') || command.includes('report')) {
|
actionName = 'refuel';
|
||||||
action = 'status';
|
} else if (command.includes('farm')) {
|
||||||
|
setTurtleState(turtleId, 'farming');
|
||||||
|
actionName = 'farm';
|
||||||
|
} else if (command.includes('dump')) {
|
||||||
|
setTurtleState(turtleId, 'dumpInventory');
|
||||||
|
actionName = 'dump inventory';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action) {
|
if (actionName) {
|
||||||
sendCommand(turtleId, action, param);
|
setLastCommand(actionName);
|
||||||
setLastCommand(`${action}${param ? ` ${param}` : ''}`);
|
speak(`Sending ${actionName} command`);
|
||||||
speak(`Sending ${action.replace(/([A-Z])/g, ' $1').toLowerCase()} command`);
|
|
||||||
} else {
|
} else {
|
||||||
speak('Command not recognized');
|
speak('Command not recognized');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user