From 73f8a21a81c5ceb9cbc9b59a117c416817134e61 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 02:47:36 -0500 Subject: [PATCH] style: Refactor gpsLocate method for improved position handling and code clarity --- server/Turtle.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/server/Turtle.js b/server/Turtle.js index 1cdd681..eaa90f1 100644 --- a/server/Turtle.js +++ b/server/Turtle.js @@ -745,15 +745,9 @@ export class Turtle extends EventEmitter { * GPS locate */ async gpsLocate() { - const result = await this.exec('return gps.locate(5)'); - if (result && typeof result === 'object' && result[1] != null) { - this.position = { x: Math.floor(result[1]), y: Math.floor(result[2]), z: Math.floor(result[3]) }; - } else if (typeof result === 'number') { - // Some versions return x,y,z as separate values - const pos = await this.exec('local x,y,z = gps.locate(5); return {x=x, y=y, z=z}'); - if (pos && pos.x != null) { - this.position = { x: Math.floor(pos.x), y: Math.floor(pos.y), z: Math.floor(pos.z) }; - } + const result = await this.exec('local x,y,z = gps.locate(5); if x then return {x=x, y=y, z=z} else return nil end'); + if (result && result.x != null) { + this.position = { x: Math.floor(result.x), y: Math.floor(result.y), z: Math.floor(result.z) }; } return this._position; }