mirror of
https://github.com/deunix-educ/aventuriers-des-mots.git
synced 2026-10-13 02:11:58 +02:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user