Add mission scoring, rewards collection and save schema v2

Phase "score et récompenses" of the post-0.1.0 plan (user feedback:
wants a more game-like experience with scoring and rewards).

- MissionScoring: 1-3 stars from how each exercise was solved (never
  speed; a finished mission always gives at least one star).
- Save schema v2: mission_results (best/last stars, completions) with a
  v1->v2 migration that keeps existing stars and items.
- Total only grows by the improvement over a mission's best score.
- Data-driven collection (data/rewards, reward_item schema, validated
  incl. mission cross-check) unlocked by RewardRules.
- Reward screen, collection screen, stars on the world map.
- Version 0.2.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Denis Defolie
2026-10-11 22:20:59 +02:00
parent 57182172a9
commit 65a0cb46f9
47 changed files with 897 additions and 36 deletions
+26
View File
@@ -10,6 +10,7 @@ extends Node
var _rules: Dictionary = {}
var _exercises_by_rule_and_type: Dictionary = {}
var _dictations_by_rule: Dictionary = {}
var _reward_items: Array[Dictionary] = []
var _missions: Dictionary = {}
var _mission_order: Array[String] = []
var _rng := RandomNumberGenerator.new()
@@ -21,6 +22,7 @@ func _ready() -> void:
_load_exercises()
_load_dictations()
_load_missions()
_load_rewards()
func get_rule(rule_id: String) -> Dictionary:
@@ -44,6 +46,12 @@ func get_missions_for_level(level: String) -> Array[Dictionary]:
return missions
## Catalogue des objets de la collection, du plus facile au plus difficile
## a obtenir (ordre stable : seuil puis identifiant).
func get_reward_items() -> Array[Dictionary]:
return _reward_items
func get_mission(mission_id: String) -> Dictionary:
return _missions.get(mission_id, {})
@@ -141,3 +149,21 @@ func _load_missions() -> void:
mission_ids.append(mission["mission_id"])
mission_ids.sort()
_mission_order = mission_ids
func _load_rewards() -> void:
for path in DataLoader.find_json_files("res://data/rewards"):
var errors := DataLoader.validate_file(path, "reward_item")
if not errors.is_empty():
push_error("Objet de collection ignore (%s) : %s" % [path, errors])
continue
var item: Dictionary = DataLoader.read_json(path)
_reward_items.append(item)
_reward_items.sort_custom(
func(a: Dictionary, b: Dictionary) -> bool:
var count_a: int = a["unlock"]["count"]
var count_b: int = b["unlock"]["count"]
if count_a != count_b:
return count_a < count_b
return String(a["item_id"]) < String(b["item_id"])
)
+5
View File
@@ -11,11 +11,16 @@ const SCENE_WORLD_MAP := "res://scenes/world/world_map.tscn"
const SCENE_MISSION_INTRO := "res://scenes/world/mission_intro.tscn"
const SCENE_EXERCISE_HOST := "res://scenes/exercises/exercise_host.tscn"
const SCENE_REWARD := "res://scenes/ui/reward_screen.tscn"
const SCENE_COLLECTION := "res://scenes/ui/collection.tscn"
## Mission choisie sur la carte, lue par mission_intro puis exercise_host et
## reward_screen. Remise a vide par reward_screen au retour sur la carte.
var pending_mission_id: String = ""
## Resultat de chaque exercice de la mission qui vient de se terminer
## (MissionScoring.OUTCOME_*), transmis par exercise_host a reward_screen.
var last_outcomes: Array[String] = []
func goto(scene_path: String) -> void:
# Differe le changement de scene : l'appeler depuis le _ready() de la
+29 -2
View File
@@ -37,8 +37,35 @@ func unlock_region(region_id: String) -> void:
_current_save = ProgressUpdates.unlock_region(_current_save, region_id)
func add_stars(amount: int) -> void:
_current_save = ProgressUpdates.add_stars(_current_save, amount)
## Enregistre la fin d'une mission : score en etoiles (MissionScoring),
## meilleur score par mission, total, puis objets de la collection
## debloques (RewardRules). Renvoie de quoi afficher l'ecran de recompense.
## L'ecriture sur disque reste a la charge de save_now().
func complete_mission(mission_id: String, outcomes: Array[String]) -> Dictionary:
var earned := MissionScoring.stars_for(outcomes)
var previous_best := mission_best_stars(mission_id)
_current_save = ProgressUpdates.record_mission_result(_current_save, mission_id, earned)
var new_items := RewardRules.newly_unlocked(
ExerciseEngine.get_reward_items(), stars(), _current_save["mission_results"], owned_items()
)
_current_save = ProgressUpdates.grant_items(_current_save, new_items)
return {
"stars": earned,
"previous_best": previous_best,
"is_record": previous_best > 0 and earned > previous_best,
"total_stars": stars(),
"new_items": new_items,
}
func mission_best_stars(mission_id: String) -> int:
var results: Dictionary = _current_save.get("mission_results", {})
return int(results.get(mission_id, {}).get("best_stars", 0))
func owned_items() -> Array:
return _current_save.get("rewards", {}).get("items", [])
func stars() -> int: