Files
mice/engine/scoring.py
T
enne2 486cd6b7c5 Add non-regression test states and Bluetooth diagnostic script
- Introduced a new JSON file containing non-regression test states with detailed unit information, including positions, ages, and movement directions across multiple frames.
- Added a shell script for Bluetooth diagnostics that checks system information, Bluetooth binaries, running processes, D-Bus status, Bluetooth controller details, and audio stack status, providing a comprehensive overview for troubleshooting.
2026-05-17 23:36:24 +02:00

48 lines
2.0 KiB
Python

import datetime
from runtime_paths import persistent_data_path
SCORES_FILE = persistent_data_path("scores.txt", default_text="")
class Scoring:
def __init__(self, game):
self.game = game
# ==================== SCORING ====================
def save_score(self):
# Save to traditional scores.txt file
with SCORES_FILE.open("a", encoding="utf-8") as f:
profile_integration = getattr(self.game, 'profile_integration', None)
if profile_integration and hasattr(profile_integration, 'get_profile_name'):
name = profile_integration.get_profile_name()
device_id = profile_integration.get_device_id()
f.write(f"{datetime.datetime.now()} - {self.game.points} - {name} - {device_id}\n")
else:
f.write(f"{datetime.datetime.now()} - {self.game.points} - Guest\n")
def read_score(self):
table = []
try:
with SCORES_FILE.open(encoding="utf-8") as f:
rows = f.read().splitlines()
for row in rows:
parts = row.split(" - ")
if len(parts) >= 2:
# Handle both old format (date - score) and new format (date - score - name - device)
if len(parts) >= 4:
table.append([parts[0], parts[1], parts[2], parts[3]]) # date, score, name, device
elif len(parts) >= 3:
table.append([parts[0], parts[1], parts[2], "Unknown"]) # date, score, name, unknown device
else:
table.append([parts[0], parts[1], "Guest", "Unknown"]) # date, score, guest, unknown device
table.sort(key=lambda x: int(x[1]), reverse=True)
except FileNotFoundError:
pass
return table[:5] # Return top 5 scores instead of 3
def add_point(self, value):
self.game.points += value