feat: Add player positions tracking to database

This commit is contained in:
MayaTheShy
2026-02-20 00:18:52 -05:00
parent b08ff805b4
commit a1d2b62d5f

View File

@@ -133,6 +133,17 @@ export function initializeDatabase() {
)
`);
// Player positions table (for tracking pocket computer users)
db.exec(`
CREATE TABLE IF NOT EXISTS player_positions (
player_id INTEGER PRIMARY KEY,
x INTEGER NOT NULL,
y INTEGER NOT NULL,
z INTEGER NOT NULL,
updated_at INTEGER NOT NULL
)
`);
// Create indexes for better performance
db.exec(`
CREATE INDEX IF NOT EXISTS idx_world_blocks_discovered
@@ -455,6 +466,25 @@ export function getSessionStats(turtleId, limit = 10) {
return stmt.all(turtleId, limit);
}
// Player Positions
export function savePlayerPosition(playerId, position) {
const stmt = db.prepare(`
INSERT OR REPLACE INTO player_positions (player_id, x, y, z, updated_at)
VALUES (?, ?, ?, ?, ?)
`);
stmt.run(playerId, position.x, position.y, position.z, 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);
}
export function getAllPlayerPositions() {
const stmt = db.prepare('SELECT player_id, x, y, z, updated_at FROM player_positions');
return stmt.all();
}
// Cleanup function
export function closeDatabase() {
db.close();