Files
aventuriers-des-mots/scripts/pedagogy/reward_rules.gd
T
Denis Defolie 65a0cb46f9 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>
2026-10-11 22:20:59 +02:00

35 lines
1.3 KiB
GDScript

class_name RewardRules
extends RefCounted
## Regles de deblocage des objets de la collection, a partir du catalogue
## valide de data/rewards/. Code pur : renvoie ce qui vient d'etre debloque,
## ProgressManager se charge de l'enregistrer.
## catalog : liste d'objets conformes a reward_item.schema.json.
## best_stars_by_mission : mission_id -> {"best_stars": int, ...}.
## owned : item_id deja possedes (jamais redebloques).
static func newly_unlocked(
catalog: Array[Dictionary], total_stars: int, best_stars_by_mission: Dictionary, owned: Array
) -> Array[String]:
var unlocked: Array[String] = []
for item in catalog:
var item_id: String = item["item_id"]
if owned.has(item_id) or unlocked.has(item_id):
continue
if _is_unlocked(item["unlock"], total_stars, best_stars_by_mission):
unlocked.append(item_id)
return unlocked
static func _is_unlocked(
unlock: Dictionary, total_stars: int, best_stars_by_mission: Dictionary
) -> bool:
var count: int = int(unlock["count"])
match unlock["type"]:
"total_stars":
return total_stars >= count
"mission_stars":
var result: Dictionary = best_stars_by_mission.get(unlock.get("mission_id", ""), {})
return int(result.get("best_stars", 0)) >= count
return false