refactor: remove legacy turtleData getter and update command handling for eval commands
This commit is contained in:
@@ -37,18 +37,6 @@ const worldBlocks = new Map(); // "x,y,z" -> {name, metadata, discoveredBy, time
|
||||
const turtleHomes = new Map(); // turtleID -> {x, y, z} home position
|
||||
const turtleConfig = new Map(); // turtleID -> {maxDistance, facing, etc}
|
||||
|
||||
// Legacy compat: turtleData getter (returns serialized Turtle data)
|
||||
const turtleData = {
|
||||
has(id) { return turtles.has(id); },
|
||||
get(id) { const t = turtles.get(id); return t ? t.toJSON() : undefined; },
|
||||
set(id, _val) { /* no-op, use getOrCreateTurtle */ },
|
||||
delete(id) { return turtles.delete(id); },
|
||||
get size() { return turtles.size; },
|
||||
entries() { return Array.from(turtles.entries()).map(([id, t]) => [id, t.toJSON()])[Symbol.iterator](); },
|
||||
values() { return Array.from(turtles.values()).map(t => t.toJSON())[Symbol.iterator](); },
|
||||
keys() { return turtles.keys(); },
|
||||
};
|
||||
|
||||
// Load saved homes into memory
|
||||
for (const home of savedHomes) {
|
||||
turtleHomes.set(home.turtle_id, { x: home.x, y: home.y, z: home.z });
|
||||
@@ -340,7 +328,7 @@ app.get('/api/turtle/:id/commands', (req, res) => {
|
||||
const turtle = turtles.get(turtleID);
|
||||
|
||||
if (turtle) {
|
||||
// Combine eval commands + legacy commands
|
||||
// Get pending eval commands for webbridge
|
||||
const commands = turtle.pendingCommands || [];
|
||||
|
||||
// Clean up old commands (older than 30 seconds)
|
||||
@@ -348,12 +336,10 @@ app.get('/api/turtle/:id/commands', (req, res) => {
|
||||
turtle.pendingCommands = commands.filter(cmd => (now - cmd.timestamp) < 30000);
|
||||
|
||||
if (turtle.pendingCommands.length > 0) {
|
||||
console.log(`📤 Sending ${turtle.pendingCommands.length} command(s) to turtle ${turtleID}`);
|
||||
console.log(`📤 Sending ${turtle.pendingCommands.length} eval command(s) to turtle ${turtleID}`);
|
||||
turtle.pendingCommands.forEach(cmd => {
|
||||
if (cmd.type === 'eval') {
|
||||
console.log(` - EVAL ${(cmd.uuid || '').substring(0, 8)}`);
|
||||
} else {
|
||||
console.log(` - ${cmd.command}`, cmd.param ? `(${JSON.stringify(cmd.param)})` : '');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user