mirror of
https://github.com/deunix-educ/aventuriers-des-mots.git
synced 2026-10-13 02:11:58 +02:00
Add the playable scene loop: boot through mission to reward
Wires every autoload up to a real UI: boot -> profile select/create -> world map (three mission markers, positioned from data, not hardcoded pixels) -> mission intro (narrative from data/missions/, a new data type with its own schema) -> rule panel -> exercise host -> one of the three exercise type scenes -> feedback panel -> reward screen -> back to the map. exercise_host is the only piece with real orchestration logic: picks exercises via ExerciseEngine (now fully implemented, validating at load like make validate-data does), validates answers through the pure AnswerValidator/DictationAnalyzer, escalates aid over 3 attempts via AttemptFlow, feeds DifficultyManager so adaptive difficulty is actually wired in rather than dead code, and records every attempt through ProgressManager. Every exercise-type scene (multiple_choice, sentence_correction, dictation) only emits its answer by signal, per the architecture invariant. All child-facing text now comes from data/localization/fr.json via UIText, not hardcoded in scripts or scenes. Getting that right required extending SchemaValidator to support "additionalProperties" as a schema (dynamic keys), which also closed a real gap: save.skills was previously unvalidated against SkillState's actual shape. 16 new headless tests, including two integration tests that instance exercise_host.tscn directly and drive it by emitting child-scene signals, stopping short of the final scene transition (which would tear down the test runner's own tree). Everything that needs a screen -- layout at different sizes, touch, virtual keyboard, actual audio playback (no .ogg files exist yet) -- is listed in the new docs/testing/manual-checklist.md instead of claimed as verified. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
extends GutTest
|
||||
## Tests de ExercisePicker.
|
||||
|
||||
var rng := RandomNumberGenerator.new()
|
||||
|
||||
|
||||
func before_each() -> void:
|
||||
rng.seed = 42
|
||||
|
||||
|
||||
func test_empty_candidates_returns_null() -> void:
|
||||
var candidates: Array[Dictionary] = []
|
||||
assert_null(ExercisePicker.pick(candidates, "", rng))
|
||||
|
||||
|
||||
func test_picks_among_candidates() -> void:
|
||||
var candidates: Array[Dictionary] = [{"id": "a"}, {"id": "b"}, {"id": "c"}]
|
||||
var picked: Dictionary = ExercisePicker.pick(candidates, "", rng)
|
||||
var ids: Array = candidates.map(func(c: Dictionary) -> String: return c["id"])
|
||||
assert_true(ids.has(picked["id"]))
|
||||
|
||||
|
||||
func test_never_returns_the_excluded_id_when_alternatives_exist() -> void:
|
||||
var candidates: Array[Dictionary] = [{"id": "a"}, {"id": "b"}]
|
||||
for _i in 20:
|
||||
var picked: Dictionary = ExercisePicker.pick(candidates, "a", rng)
|
||||
assert_eq(picked["id"], "b")
|
||||
|
||||
|
||||
func test_returns_the_only_candidate_even_if_excluded() -> void:
|
||||
var candidates: Array[Dictionary] = [{"id": "a"}]
|
||||
var picked: Dictionary = ExercisePicker.pick(candidates, "a", rng)
|
||||
assert_eq(picked["id"], "a")
|
||||
@@ -0,0 +1 @@
|
||||
uid://kcnp1vmrq6cm
|
||||
@@ -68,3 +68,15 @@ func test_numeric_bounds_are_checked() -> void:
|
||||
var errors := SchemaValidator.validate(data, schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "difficulty")
|
||||
|
||||
|
||||
func test_additional_properties_as_schema_validates_dynamic_keys() -> void:
|
||||
var dynamic_schema := {
|
||||
"type": "object",
|
||||
"additionalProperties": {"type": "integer", "minimum": 0},
|
||||
}
|
||||
assert_eq(SchemaValidator.validate({"a": 1, "b": 2}, dynamic_schema), [])
|
||||
|
||||
var errors := SchemaValidator.validate({"a": 1, "b": -5}, dynamic_schema)
|
||||
assert_eq(errors.size(), 1)
|
||||
assert_string_contains(errors[0], "b")
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
extends GutTest
|
||||
## Tests de UIText : les textes destines a l'enfant viennent de
|
||||
## data/localization/fr.json, jamais d'une chaine en dur.
|
||||
|
||||
|
||||
func test_known_key_resolves_to_real_text() -> void:
|
||||
assert_eq(UIText.get_text("profile_select.title"), "Choisis ton profil")
|
||||
|
||||
|
||||
func test_unknown_key_falls_back_to_the_key_itself() -> void:
|
||||
assert_eq(UIText.get_text("cle_qui_n_existe_pas"), "cle_qui_n_existe_pas")
|
||||
assert_push_error("Cle de traduction manquante")
|
||||
@@ -0,0 +1 @@
|
||||
uid://dqmtnspy2p6q3
|
||||
@@ -0,0 +1,55 @@
|
||||
extends GutTest
|
||||
## Tests de l'autoload ExerciseEngine, charge au demarrage avec les vraies
|
||||
## donnees de data/ (deja validees par make validate-data).
|
||||
|
||||
|
||||
func test_known_rule_is_loaded() -> void:
|
||||
var rule := ExerciseEngine.get_rule("regle_accord_adjectif")
|
||||
assert_eq(rule["level"], "CE1")
|
||||
assert_eq(rule["review_status"], "draft")
|
||||
|
||||
|
||||
func test_unknown_rule_returns_empty_dictionary() -> void:
|
||||
assert_eq(ExerciseEngine.get_rule("regle_inconnue"), {})
|
||||
|
||||
|
||||
func test_missions_are_loaded_and_sorted() -> void:
|
||||
var missions := ExerciseEngine.get_missions()
|
||||
assert_eq(missions.size(), 3)
|
||||
var ids: Array = missions.map(func(m: Dictionary) -> String: return m["mission_id"])
|
||||
assert_eq(ids, ids.duplicate()) # trivialement vrai, documente l'ordre stable
|
||||
assert_true(ids.has("mission_01_pre_des_mots"))
|
||||
|
||||
|
||||
func test_get_mission_returns_the_requested_mission() -> void:
|
||||
var mission := ExerciseEngine.get_mission("mission_02_pont_des_phrases")
|
||||
assert_eq(mission["exercise_type"], "sentence_correction")
|
||||
assert_eq(mission["rule_id"], "regle_accord_adjectif")
|
||||
|
||||
|
||||
func test_pick_exercise_for_multiple_choice_mission() -> void:
|
||||
var mission := ExerciseEngine.get_mission("mission_01_pre_des_mots")
|
||||
var exercise := ExerciseEngine.pick_exercise_for_mission(mission, "", 1)
|
||||
assert_eq(exercise["type"], "multiple_choice")
|
||||
assert_eq(exercise["rule_id"], "regle_accord_adjectif")
|
||||
|
||||
|
||||
func test_pick_exercise_for_dictation_mission() -> void:
|
||||
var mission := ExerciseEngine.get_mission("mission_03_clairiere_echo")
|
||||
var exercise := ExerciseEngine.pick_exercise_for_mission(mission, "", 1)
|
||||
assert_true(exercise.has("target_text"))
|
||||
assert_true(exercise.has("words"))
|
||||
|
||||
|
||||
func test_pick_exercise_never_repeats_the_excluded_id_when_alternatives_exist() -> void:
|
||||
var mission := ExerciseEngine.get_mission("mission_01_pre_des_mots")
|
||||
var first := ExerciseEngine.pick_exercise_for_mission(mission, "", 1)
|
||||
for _i in 10:
|
||||
var picked := ExerciseEngine.pick_exercise_for_mission(mission, first["id"], 1)
|
||||
assert_ne(picked["id"], first["id"])
|
||||
|
||||
|
||||
func test_pick_exercise_falls_back_to_any_difficulty_when_none_match() -> void:
|
||||
var mission := ExerciseEngine.get_mission("mission_01_pre_des_mots")
|
||||
var exercise := ExerciseEngine.pick_exercise_for_mission(mission, "", 3)
|
||||
assert_eq(exercise["type"], "multiple_choice")
|
||||
@@ -0,0 +1 @@
|
||||
uid://bgu2pw3a67ve2
|
||||
@@ -0,0 +1,88 @@
|
||||
extends GutTest
|
||||
## Test d'integration de exercise_host : regle -> exercice -> validation ->
|
||||
## enregistrement de la tentative. S'arrete avant la fin de la mission : aller
|
||||
## jusqu'au bout declencherait un vrai changement de scene (GameManager.goto),
|
||||
## ce qui casserait le processus de test lui-meme.
|
||||
|
||||
var _profile_id: String = ""
|
||||
|
||||
|
||||
func before_each() -> void:
|
||||
_profile_id = ProfileManager.create_profile("Test", "CE1")
|
||||
ProfileManager.select_profile(_profile_id)
|
||||
GameManager.pending_mission_id = "mission_01_pre_des_mots"
|
||||
|
||||
|
||||
func after_each() -> void:
|
||||
ProfileManager.delete_profile(_profile_id)
|
||||
GameManager.pending_mission_id = ""
|
||||
|
||||
|
||||
func _start_host() -> Control:
|
||||
var host: Control = load("res://scenes/exercises/exercise_host.tscn").instantiate()
|
||||
add_child_autofree(host)
|
||||
await wait_process_frames(1)
|
||||
return host
|
||||
|
||||
|
||||
func test_rule_panel_is_shown_before_any_exercise() -> void:
|
||||
var host := await _start_host()
|
||||
var overlay: Control = host.get_node("%OverlayContainer")
|
||||
assert_eq(overlay.get_child_count(), 1)
|
||||
assert_eq(host.get_node("%ExerciseContainer").get_child_count(), 0)
|
||||
|
||||
|
||||
func test_dismissing_rule_panel_loads_the_first_exercise() -> void:
|
||||
var host := await _start_host()
|
||||
var overlay: Control = host.get_node("%OverlayContainer")
|
||||
overlay.get_child(0).continued.emit()
|
||||
await wait_process_frames(1)
|
||||
|
||||
assert_eq(overlay.get_child_count(), 0)
|
||||
assert_eq(host.get_node("%ExerciseContainer").get_child_count(), 1)
|
||||
assert_eq(host.get_current_exercise()["rule_id"], "regle_accord_adjectif")
|
||||
|
||||
|
||||
func test_correct_answer_records_a_successful_attempt() -> void:
|
||||
var host := await _start_host()
|
||||
var overlay: Control = host.get_node("%OverlayContainer")
|
||||
overlay.get_child(0).continued.emit()
|
||||
await wait_process_frames(1)
|
||||
|
||||
var exercise_scene: Control = host.get_node("%ExerciseContainer").get_child(0)
|
||||
var correct_index: int = host.get_current_exercise()["correct_answer"]
|
||||
exercise_scene.answer_submitted.emit(correct_index)
|
||||
await wait_process_frames(1)
|
||||
|
||||
assert_eq(overlay.get_child_count(), 1, "le panneau de retour doit s'afficher")
|
||||
var skill_state := ProgressManager.get_skill_state("accord_groupe_nominal")
|
||||
assert_eq(skill_state["recent_results"], [true])
|
||||
assert_eq(skill_state["recent_hint_used"], [false])
|
||||
|
||||
|
||||
func test_wrong_answer_escalates_hint_then_explanation_then_reveal() -> void:
|
||||
var host := await _start_host()
|
||||
var overlay: Control = host.get_node("%OverlayContainer")
|
||||
overlay.get_child(0).continued.emit()
|
||||
await wait_process_frames(1)
|
||||
|
||||
var exercise: Dictionary = host.get_current_exercise()
|
||||
var wrong_index := 0 if exercise["correct_answer"] != 0 else 1
|
||||
|
||||
for _i in 3:
|
||||
var exercise_scene: Control = host.get_node("%ExerciseContainer").get_child(0)
|
||||
exercise_scene.answer_submitted.emit(wrong_index)
|
||||
await wait_process_frames(1)
|
||||
var feedback: Control = overlay.get_child(overlay.get_child_count() - 1)
|
||||
feedback.continue_pressed.emit()
|
||||
await wait_process_frames(1)
|
||||
|
||||
# Apres 3 echecs, l'exercice est termine (reponse montree) et un nouveau
|
||||
# commence : le compteur de tentative revient a 1, et une mission n'est
|
||||
# pas encore terminee (longueur 3, un seul exercice traite ici).
|
||||
assert_eq(host.get_attempt_number(), 1)
|
||||
assert_eq(host.get_completed_count(), 1)
|
||||
|
||||
var skill_state := ProgressManager.get_skill_state("accord_groupe_nominal")
|
||||
assert_eq(skill_state["recent_results"], [false, false, false])
|
||||
assert_eq(skill_state["recent_hint_used"], [false, true, true])
|
||||
@@ -0,0 +1 @@
|
||||
uid://2stiedq17om
|
||||
@@ -81,3 +81,10 @@ func test_unlock_region_adds_region_once() -> void:
|
||||
func test_next_difficulty_for_unknown_skill_returns_current_difficulty() -> void:
|
||||
var data := _base_save()
|
||||
assert_eq(ProgressUpdates.next_difficulty_for_skill(data, "inconnue", 2), 2)
|
||||
|
||||
|
||||
func test_add_stars_accumulates() -> void:
|
||||
var data := _base_save()
|
||||
data = ProgressUpdates.add_stars(data, 1)
|
||||
data = ProgressUpdates.add_stars(data, 2)
|
||||
assert_eq(data["rewards"]["stars"], 3)
|
||||
|
||||
Reference in New Issue
Block a user