Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions achievements.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime, timezone
from typing import Dict, List, Optional


ACHIEVEMENTS = [
{"id": "first_solve", "title": "First Solve", "description": "Solve your first puzzle."},
{"id": "solve_5", "title": "Solver: 5", "description": "Solve 5 puzzles."},
Expand Down Expand Up @@ -44,20 +43,28 @@ def evaluate_achievements(state: Dict, levels: Optional[List[Dict]] = None) -> L
for aid, cond in thresholds:
if cond and aid not in unlocked:
meta = _ach_by_id(aid) or {"id": aid}
unlocked[aid] = {"unlocked_at": _now_iso(), "title": meta.get("title"), "description": meta.get("description")}
unlocked[aid] = {
"unlocked_at": _now_iso(),
"title": meta.get("title"),
"description": meta.get("description"),
}
newly.append({"id": aid, **unlocked[aid]})

# category completion achievements if levels provided
if levels:
# build category -> set(ids)
cats = {}
for l in levels:
cid = l.get("category") or "uncategorized"
cats.setdefault(cid, set()).add(l.get("id"))
for level in levels:
cid = level.get("category") or "uncategorized"
cats.setdefault(cid, set()).add(level.get("id"))
for cat, ids in cats.items():
if ids and ids.issubset(solved) and f"category_{cat}" not in unlocked:
aid = f"category_{cat}"
unlocked[aid] = {"unlocked_at": _now_iso(), "title": f"Master: {cat}", "description": f"Solve all puzzles in {cat}."}
unlocked[aid] = {
"unlocked_at": _now_iso(),
"title": f"Master: {cat}",
"description": f"Solve all puzzles in {cat}.",
}
newly.append({"id": aid, **unlocked[aid]})

return newly
Loading
Loading