Save best scores and last difficulty to a JSON profile

- profile package: best moves, best time and games played per
  deck/difficulty, stored in the user data folder
- Win panel shows the best (or New best!), language menu shows bests
- Profile memory always comes from the heap allocator (it outlives callers)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SansanandClaude Opus 5.5 committed 2026-10-01 21:35:43 +02:00
1 parent 685182b25d
commit 83ff9511ec
5 files changed
+225 -6

No files matched your search

+12
View File
@@ -1,11 +1,14 @@
package main
import "core:fmt"
import "core:reflect"
import raylib "vendor:raylib"
import assets "src/assets"
import audio "src/audio"
import card "src/card"
import decks "src/decks"
import memory "src/memory"
import profile "src/profile"
import screens "src/screens"
import themes "src/themes"
import ui "src/ui"
@@ -40,9 +43,16 @@ main :: proc() {
defer card.unload_art()
defer memory.unload()
if !profile.init() {
raylib.TraceLog(.WARNING, "PROFILE: Could not read saved scores, starting fresh")
}
screen := themes.Screen.MAIN_MENU
language := decks.Language.JAPANESE
difficulty := memory.Difficulty.NORMAL
if saved, ok := reflect.enum_from_name(memory.Difficulty, profile.data.difficulty); ok {
difficulty = saved
}
running := true
for running && !raylib.WindowShouldClose() {
dt := raylib.GetFrameTime()
@@ -82,6 +92,8 @@ main :: proc() {
}
ui.end_frame()
raylib.EndDrawing()
free_all(context.temp_allocator)
profile.set_difficulty(fmt.tprintf("%v", difficulty))
// Building card faces renders into textures, so do it outside of drawing
if deck, ok := start_deck.?; ok {