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;
|
||||
let action = null;
|
||||
let param = null;
|
||||
let actionName = null;
|
||||
|
||||
// Parse voice commands
|
||||
// Movement commands (server-side)
|
||||
if (command.includes('forward') || command.includes('go ahead')) {
|
||||
action = 'forward';
|
||||
moveForward(turtleId);
|
||||
actionName = 'forward';
|
||||
} else if (command.includes('back') || command.includes('backward')) {
|
||||
action = 'back';
|
||||
moveBack(turtleId);
|
||||
actionName = 'back';
|
||||
} 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')) {
|
||||
action = 'turnRight';
|
||||
turnRight(turtleId);
|
||||
actionName = 'turn right';
|
||||
} 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')) {
|
||||
action = 'down';
|
||||
moveDown(turtleId);
|
||||
actionName = 'down';
|
||||
} else if (command.includes('dig')) {
|
||||
if (command.includes('up')) {
|
||||
action = 'digUp';
|
||||
digBlockUp(turtleId);
|
||||
actionName = 'dig up';
|
||||
} else if (command.includes('down')) {
|
||||
action = 'digDown';
|
||||
digBlockDown(turtleId);
|
||||
actionName = 'dig down';
|
||||
} else {
|
||||
action = 'dig';
|
||||
digBlock(turtleId);
|
||||
actionName = 'dig';
|
||||
}
|
||||
} 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')) {
|
||||
action = 'explore';
|
||||
setTurtleState(turtleId, 'exploring');
|
||||
actionName = 'explore';
|
||||
} 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')) {
|
||||
action = 'returnHome';
|
||||
setTurtleState(turtleId, 'goHome');
|
||||
actionName = 'go home';
|
||||
} else if (command.includes('stop')) {
|
||||
action = 'stop';
|
||||
} else if (command.includes('set home') || command.includes('mark home')) {
|
||||
action = 'setHome';
|
||||
setTurtleState(turtleId, 'idle');
|
||||
actionName = 'idle';
|
||||
} else if (command.includes('refuel')) {
|
||||
action = 'refuel';
|
||||
} else if (command.includes('status') || command.includes('report')) {
|
||||
action = 'status';
|
||||
setTurtleState(turtleId, 'refueling');
|
||||
actionName = 'refuel';
|
||||
} else if (command.includes('farm')) {
|
||||
setTurtleState(turtleId, 'farming');
|
||||
actionName = 'farm';
|
||||
} else if (command.includes('dump')) {
|
||||
setTurtleState(turtleId, 'dumpInventory');
|
||||
actionName = 'dump inventory';
|
||||
}
|
||||
|
||||
if (action) {
|
||||
sendCommand(turtleId, action, param);
|
||||
setLastCommand(`${action}${param ? ` ${param}` : ''}`);
|
||||
speak(`Sending ${action.replace(/([A-Z])/g, ' $1').toLowerCase()} command`);
|
||||
if (actionName) {
|
||||
setLastCommand(actionName);
|
||||
speak(`Sending ${actionName} command`);
|
||||
} else {
|
||||
speak('Command not recognized');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user