style: Implement server-side turtle actions for movement and block manipulation
This commit is contained in:
@@ -288,6 +288,37 @@ export const useTurtleStore = create((set, get) => ({
|
||||
}
|
||||
},
|
||||
|
||||
// ========== Server-Side Movement & Actions ==========
|
||||
// All movement/actions are routed through the server's Turtle.js exec() pipeline
|
||||
|
||||
_turtleAction: async (turtleId, action, body = {}) => {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/turtle/${turtleId}/${action}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(` ❌ Error ${action}:`, error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
},
|
||||
|
||||
moveForward: async (turtleId) => get()._turtleAction(turtleId, 'forward'),
|
||||
moveBack: async (turtleId) => get()._turtleAction(turtleId, 'back'),
|
||||
moveUp: async (turtleId) => get()._turtleAction(turtleId, 'up'),
|
||||
moveDown: async (turtleId) => get()._turtleAction(turtleId, 'down'),
|
||||
turnLeft: async (turtleId) => get()._turtleAction(turtleId, 'turnLeft'),
|
||||
turnRight: async (turtleId) => get()._turtleAction(turtleId, 'turnRight'),
|
||||
digBlock: async (turtleId) => get()._turtleAction(turtleId, 'dig'),
|
||||
digBlockUp: async (turtleId) => get()._turtleAction(turtleId, 'digUp'),
|
||||
digBlockDown: async (turtleId) => get()._turtleAction(turtleId, 'digDown'),
|
||||
placeBlock: async (turtleId, text) => get()._turtleAction(turtleId, 'place', { text }),
|
||||
placeBlockUp: async (turtleId, text) => get()._turtleAction(turtleId, 'placeUp', { text }),
|
||||
placeBlockDown: async (turtleId, text) => get()._turtleAction(turtleId, 'placeDown', { text }),
|
||||
refuelTurtle: async (turtleId, count) => get()._turtleAction(turtleId, 'refuel-action', { count }),
|
||||
|
||||
// Fetch chunk analyses from server
|
||||
fetchChunkAnalyses: async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user