Files
aventuriers-des-mots/autoload/progress_manager.gd
T
Denis Defolie ebabe91821 Add profile and save persistence, wired into the three autoloads
scripts/profiles/: SaveIO handles real file I/O in user://saves (one
file per profile_id, atomic write via temp-file-then-rename, backup
copy before each overwrite, corrupted-main falls back to backup,
schema-invalid content is rejected like corruption). SaveMigration
and SaveFactory are pure; SaveMigration refuses a schema_version it
doesn't recognize (older or newer) rather than guessing. ProgressUpdates
is pure and wires ReviewScheduler/DifficultyManager onto a save's
skills dict, including per-session overdue-review marking.

The three autoloads (SaveManager, ProfileManager, ProgressManager)
stay thin: in-memory current-profile state and orchestration only,
no logic of their own, so the actual behavior lives in the tested
pure/file-IO modules above rather than in untestable glue.

26 new headless tests, including the failure modes called out in the
launch prompt: a truncated .tmp file never corrupts the readable
save, a corrupted main file falls back to its backup, two profiles
never mix (down through the real autoload layer, not just SaveIO),
and an unknown future schema_version is rejected outright.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 17:12:50 +02:00

59 lines
2.0 KiB
GDScript

extends Node
## Competences, missions debloquees et planification des revisions du profil
## selectionne. Delegue les calculs a ProgressUpdates (scripts/profiles/), qui
## s'appuie sur ReviewScheduler et DifficultyManager (scripts/pedagogy/).
## L'ecriture sur disque reste groupee : save_now() est appele en fin de
## mission, pas a chaque tentative (docs/specs/decisions.md, point 7).
var _current_save: Dictionary = {}
var _current_profile_id: String = ""
## Charge la sauvegarde existante d'un profil et demarre une nouvelle seance
## (voir ProgressUpdates.start_session). Faux si le profil n'a pas de
## sauvegarde lisible.
func load_profile(profile_id: String) -> bool:
var data: Variant = SaveManager.load(profile_id)
if data == null:
return false
_current_profile_id = profile_id
_current_save = ProgressUpdates.start_session(data)
return true
func record_attempt(
skill_id: String, success: bool, hint_used: bool, exercise_type: String
) -> void:
var attempt := {
"skill": skill_id,
"success": success,
"hint_used": hint_used,
"exercise_type": exercise_type,
}
_current_save = ProgressUpdates.record_attempt(_current_save, attempt)
func unlock_region(region_id: String) -> void:
_current_save = ProgressUpdates.unlock_region(_current_save, region_id)
func next_difficulty_for_skill(skill_id: String, current_difficulty: int) -> int:
return ProgressUpdates.next_difficulty_for_skill(_current_save, skill_id, current_difficulty)
func get_skill_state(skill_id: String) -> Dictionary:
var skills: Dictionary = _current_save.get("skills", {})
return skills.get(skill_id, ReviewScheduler.initial_state())
func current_save() -> Dictionary:
return _current_save
## A appeler en fin de mission (pas apres chaque tentative) pour persister la
## progression du profil courant.
func save_now() -> bool:
if _current_profile_id.is_empty():
return false
return SaveManager.save(_current_profile_id, _current_save)