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:
@@ -0,0 +1,29 @@
|
||||
class_name MissionScoring
|
||||
extends RefCounted
|
||||
## Score d'une mission en etoiles (1 a 3), calcule a partir de ce qui s'est
|
||||
## passe sur chaque exercice. Code pur. Le score valorise la reussite sans
|
||||
## aide, jamais la vitesse ni la duree (cahier des charges §2) ; ce n'est
|
||||
## pas une note scolaire (§9). Une mission terminee rapporte toujours au
|
||||
## moins une etoile : l'erreur n'est jamais punie.
|
||||
|
||||
const OUTCOME_FIRST_TRY := "first_try"
|
||||
const OUTCOME_WITH_HELP := "with_help"
|
||||
const OUTCOME_REVEALED := "revealed"
|
||||
|
||||
const MIN_STARS := 1
|
||||
const MAX_STARS := 3
|
||||
|
||||
|
||||
## 3 etoiles : tous les exercices reussis du premier coup.
|
||||
## 2 etoiles : tous reussis, au moins un apres un indice ou une explication.
|
||||
## 1 etoile : au moins une reponse a ete montree (mission terminee quand meme).
|
||||
static func stars_for(outcomes: Array[String]) -> int:
|
||||
if outcomes.is_empty():
|
||||
return MIN_STARS
|
||||
var all_first_try := true
|
||||
for outcome in outcomes:
|
||||
if outcome == OUTCOME_REVEALED:
|
||||
return 1
|
||||
if outcome != OUTCOME_FIRST_TRY:
|
||||
all_first_try = false
|
||||
return MAX_STARS if all_first_try else 2
|
||||
@@ -0,0 +1 @@
|
||||
uid://53b456qsmdmt
|
||||
@@ -0,0 +1,34 @@
|
||||
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
|
||||
@@ -0,0 +1 @@
|
||||
uid://daxy0fqgngwvj
|
||||
Reference in New Issue
Block a user