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
|
// Player Positions
|
||||||
export function savePlayerPosition(playerId, position) {
|
export function savePlayerPosition(playerId, position, label = null) {
|
||||||
const stmt = db.prepare(`
|
const stmt = db.prepare(`
|
||||||
INSERT OR REPLACE INTO player_positions (player_id, x, y, z, updated_at)
|
INSERT OR REPLACE INTO player_positions (player_id, x, y, z, label, updated_at)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
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) {
|
export function getPlayerPosition(playerId) {
|
||||||
const stmt = db.prepare('SELECT x, y, z, updated_at FROM player_positions WHERE player_id = ?');
|
const stmt = db.prepare('SELECT player_id, x, y, z, label, updated_at FROM player_positions WHERE player_id = ?');
|
||||||
return stmt.get(playerId);
|
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() {
|
export function getAllPlayerPositions() {
|
||||||
const stmt = db.prepare('SELECT player_id, x, y, z, updated_at FROM player_positions');
|
const stmt = db.prepare('SELECT player_id, x, y, z, label, updated_at FROM player_positions');
|
||||||
return stmt.all();
|
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
|
// Cleanup function
|
||||||
|
|||||||
Reference in New Issue
Block a user