From 9735fd8776f9007ef404df34ab6f34d421e206c3 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 03:41:27 -0500 Subject: [PATCH] style: Implement server-side turtle actions for movement and block manipulation --- client/src/store/turtleStore.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/client/src/store/turtleStore.js b/client/src/store/turtleStore.js index c430b45..e167984 100644 --- a/client/src/store/turtleStore.js +++ b/client/src/store/turtleStore.js @@ -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 {