refactor: enhance player position handling to include label for improved tracking
This commit is contained in:
@@ -613,22 +613,34 @@ export function getSessionStats(turtleId, limit = 10) {
|
||||
}
|
||||
|
||||
// Player Positions
|
||||
export function savePlayerPosition(playerId, position) {
|
||||
export function savePlayerPosition(playerId, position, label = null) {
|
||||
const stmt = db.prepare(`
|
||||
INSERT OR REPLACE INTO player_positions (player_id, x, y, z, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
INSERT OR REPLACE INTO player_positions (player_id, x, y, z, label, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
stmt.run(playerId, position.x, position.y, position.z, Date.now());
|
||||
stmt.run(playerId, position.x, position.y, position.z, label, Date.now());
|
||||
}
|
||||
|
||||
export function getPlayerPosition(playerId) {
|
||||
const stmt = db.prepare('SELECT x, y, z, updated_at FROM player_positions WHERE player_id = ?');
|
||||
return stmt.get(playerId);
|
||||
const stmt = db.prepare('SELECT player_id, x, y, z, label, updated_at FROM player_positions WHERE player_id = ?');
|
||||
const row = stmt.get(playerId);
|
||||
if (!row) return null;
|
||||
return {
|
||||
playerID: row.player_id,
|
||||
position: { x: row.x, y: row.y, z: row.z },
|
||||
label: row.label,
|
||||
lastUpdate: row.updated_at
|
||||
};
|
||||
}
|
||||
|
||||
export function getAllPlayerPositions() {
|
||||
const stmt = db.prepare('SELECT player_id, x, y, z, updated_at FROM player_positions');
|
||||
return stmt.all();
|
||||
const stmt = db.prepare('SELECT player_id, x, y, z, label, updated_at FROM player_positions');
|
||||
return stmt.all().map(row => ({
|
||||
playerID: row.player_id,
|
||||
position: { x: row.x, y: row.y, z: row.z },
|
||||
label: row.label,
|
||||
lastUpdate: row.updated_at
|
||||
}));
|
||||
}
|
||||
|
||||
// Cleanup function
|
||||
|
||||
Reference in New Issue
Block a user