feat: Add player positions tracking to database
This commit is contained in:
@@ -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
|
// Create indexes for better performance
|
||||||
db.exec(`
|
db.exec(`
|
||||||
CREATE INDEX IF NOT EXISTS idx_world_blocks_discovered
|
CREATE INDEX IF NOT EXISTS idx_world_blocks_discovered
|
||||||
@@ -455,6 +466,25 @@ export function getSessionStats(turtleId, limit = 10) {
|
|||||||
return stmt.all(turtleId, limit);
|
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
|
// Cleanup function
|
||||||
export function closeDatabase() {
|
export function closeDatabase() {
|
||||||
db.close();
|
db.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user