feat: player statistics screen with run history

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-24 14:51:44 +09:00
parent 0dce30f23f
commit afdda5d72b
4 changed files with 84 additions and 1 deletions

View File

@@ -76,6 +76,39 @@ func (d *DB) SaveRun(player string, floor, score int) error {
})
}
type PlayerStats struct {
TotalRuns int
BestFloor int
TotalGold int
TotalKills int
Victories int
}
func (d *DB) GetStats(player string) (PlayerStats, error) {
var stats PlayerStats
err := d.db.View(func(tx *bolt.Tx) error {
b := tx.Bucket(bucketRankings)
if b == nil {
return nil
}
return b.ForEach(func(k, v []byte) error {
var r RunRecord
if json.Unmarshal(v, &r) == nil && r.Player == player {
stats.TotalRuns++
if r.Floor > stats.BestFloor {
stats.BestFloor = r.Floor
}
stats.TotalGold += r.Score
if r.Floor >= 20 {
stats.Victories++
}
}
return nil
})
})
return stats, err
}
func (d *DB) TopRuns(limit int) ([]RunRecord, error) {
var runs []RunRecord
err := d.db.View(func(tx *bolt.Tx) error {