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:
@@ -23,6 +23,8 @@ var _current_difficulty := 1
|
||||
var _attempt_number := 1
|
||||
var _completed_count := 0
|
||||
var _last_exercise_id := ""
|
||||
var _outcomes: Array[String] = []
|
||||
var _pending_outcome := ""
|
||||
|
||||
@onready var _exercise_container: Control = %ExerciseContainer
|
||||
@onready var _overlay_container: Control = %OverlayContainer
|
||||
@@ -43,6 +45,10 @@ func get_completed_count() -> int:
|
||||
return _completed_count
|
||||
|
||||
|
||||
func get_outcomes() -> Array[String]:
|
||||
return _outcomes
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_mission = ExerciseEngine.get_mission(GameManager.pending_mission_id)
|
||||
_rule = ExerciseEngine.get_rule(_mission["rule_id"])
|
||||
@@ -126,6 +132,15 @@ func _handle_result(result: CorrectionResult) -> void:
|
||||
support_level = AttemptFlow.support_level_for_attempt(_attempt_number)
|
||||
is_terminal = AttemptFlow.should_end_exercise(_attempt_number)
|
||||
|
||||
if result.is_correct:
|
||||
_pending_outcome = (
|
||||
MissionScoring.OUTCOME_FIRST_TRY
|
||||
if _attempt_number == 1
|
||||
else MissionScoring.OUTCOME_WITH_HELP
|
||||
)
|
||||
elif is_terminal:
|
||||
_pending_outcome = MissionScoring.OUTCOME_REVEALED
|
||||
|
||||
ProgressManager.record_attempt(
|
||||
_skill_id, result.is_correct, _attempt_number > 1, _mission["exercise_type"]
|
||||
)
|
||||
@@ -154,8 +169,10 @@ func _on_feedback_continued(feedback: Control, is_terminal: bool) -> void:
|
||||
)
|
||||
_last_exercise_id = _current_exercise.get("id", "")
|
||||
_completed_count += 1
|
||||
_outcomes.append(_pending_outcome)
|
||||
|
||||
if _completed_count >= MISSION_LENGTH:
|
||||
GameManager.last_outcomes = _outcomes.duplicate()
|
||||
GameManager.goto(GameManager.SCENE_REWARD)
|
||||
else:
|
||||
_load_next_exercise()
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
extends Control
|
||||
## Collection d'objets gagnes avec les etoiles. Un objet non debloque reste
|
||||
## mysterieux mais indique comment l'obtenir (jamais de mystere frustrant).
|
||||
|
||||
@onready var _title_label: Label = %TitleLabel
|
||||
@onready var _progress_label: Label = %ProgressLabel
|
||||
@onready var _items_box: VBoxContainer = %ItemsBox
|
||||
@onready var _back_button: Button = %BackButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_title_label.text = UIText.get_text("collection.title")
|
||||
_back_button.text = UIText.get_text("collection.back_button")
|
||||
_back_button.pressed.connect(_on_back_pressed)
|
||||
|
||||
var owned: Array = ProgressManager.owned_items()
|
||||
var catalog := ExerciseEngine.get_reward_items()
|
||||
var found := 0
|
||||
for item in catalog:
|
||||
var is_owned := owned.has(item["item_id"])
|
||||
if is_owned:
|
||||
found += 1
|
||||
_items_box.add_child(_build_row(item, is_owned))
|
||||
_progress_label.text = (
|
||||
"%s %d/%d" % [UIText.get_text("collection.progress_label"), found, catalog.size()]
|
||||
)
|
||||
|
||||
|
||||
func _build_row(item: Dictionary, is_owned: bool) -> Control:
|
||||
var label := Label.new()
|
||||
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
label.custom_minimum_size = Vector2(560, 0)
|
||||
if is_owned:
|
||||
label.text = (
|
||||
"%s — %s\n%s"
|
||||
% [item["title"], UIText.get_text("collection.owned_marker"), item["description"]]
|
||||
)
|
||||
else:
|
||||
label.text = (
|
||||
"%s\n%s" % [UIText.get_text("collection.locked_title"), _unlock_hint(item["unlock"])]
|
||||
)
|
||||
return label
|
||||
|
||||
|
||||
func _unlock_hint(unlock: Dictionary) -> String:
|
||||
var count: int = int(unlock["count"])
|
||||
if unlock["type"] == "mission_stars":
|
||||
var mission := ExerciseEngine.get_mission(unlock.get("mission_id", ""))
|
||||
return UIText.get_text("collection.unlock_mission_stars") % [count, mission.get("title", "")]
|
||||
return UIText.get_text("collection.unlock_total_stars") % count
|
||||
|
||||
|
||||
func _on_back_pressed() -> void:
|
||||
GameManager.goto(GameManager.SCENE_WORLD_MAP)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b1bk5xhhar5nj
|
||||
@@ -0,0 +1,54 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/ui/collection.gd" id="1"]
|
||||
|
||||
[node name="Collection" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 24
|
||||
theme_override_constants/margin_top = 24
|
||||
theme_override_constants/margin_right = 24
|
||||
theme_override_constants/margin_bottom = 24
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="Margin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 12
|
||||
|
||||
[node name="TitleLabel" type="Label" parent="Margin/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="ProgressLabel" type="Label" parent="Margin/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Scroll" type="ScrollContainer" parent="Margin/VBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ItemsBox" type="VBoxContainer" parent="Margin/VBox/Scroll"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 16
|
||||
|
||||
[node name="BackButton" type="Button" parent="Margin/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 56)
|
||||
+42
-10
@@ -1,28 +1,60 @@
|
||||
extends Control
|
||||
## Ecran de recompense : une mission terminee rapporte toujours la meme
|
||||
## recompense, que l'enfant ait eu besoin d'aide ou non (cahier des charges
|
||||
## §2, principe 6 : pas de recompense liee a la vitesse ou a la performance).
|
||||
## Sauvegarde groupee ici, en fin de mission (docs/specs/decisions.md point 7).
|
||||
|
||||
const STARS_PER_MISSION := 1
|
||||
## Ecran de fin de mission : etoiles gagnees (1 a 3, selon la reussite et
|
||||
## l'aide utilisee, jamais selon la vitesse : cahier des charges §2), total,
|
||||
## nouveaux objets de la collection. Une mission terminee rapporte toujours
|
||||
## au moins une etoile. Sauvegarde groupee ici, en fin de mission
|
||||
## (docs/specs/decisions.md point 7).
|
||||
|
||||
@onready var _title_label: Label = %TitleLabel
|
||||
@onready var _stars_label: Label = %StarsLabel
|
||||
@onready var _message_label: Label = %MessageLabel
|
||||
@onready var _record_label: Label = %RecordLabel
|
||||
@onready var _total_label: Label = %TotalLabel
|
||||
@onready var _new_items_label: Label = %NewItemsLabel
|
||||
@onready var _collection_button: Button = %CollectionButton
|
||||
@onready var _continue_button: Button = %ContinueButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
ProgressManager.add_stars(STARS_PER_MISSION)
|
||||
var summary := ProgressManager.complete_mission(
|
||||
GameManager.pending_mission_id, GameManager.last_outcomes
|
||||
)
|
||||
ProgressManager.save_now()
|
||||
|
||||
_title_label.text = UIText.get_text("reward_screen.title")
|
||||
_stars_label.text = "%s %d" % [
|
||||
UIText.get_text("reward_screen.stars_label"), ProgressManager.stars()
|
||||
]
|
||||
_stars_label.text = (
|
||||
"%s %d/%d"
|
||||
% [UIText.get_text("reward_screen.stars_label"), summary["stars"], MissionScoring.MAX_STARS]
|
||||
)
|
||||
_message_label.text = UIText.get_text("reward_screen.message_%d" % summary["stars"])
|
||||
_record_label.text = UIText.get_text("reward_screen.record_label")
|
||||
_record_label.visible = summary["is_record"]
|
||||
_total_label.text = (
|
||||
"%s %d" % [UIText.get_text("reward_screen.total_label"), summary["total_stars"]]
|
||||
)
|
||||
|
||||
var new_items: Array = summary["new_items"]
|
||||
_new_items_label.visible = not new_items.is_empty()
|
||||
if not new_items.is_empty():
|
||||
var titles: Array[String] = []
|
||||
for item in ExerciseEngine.get_reward_items():
|
||||
if new_items.has(item["item_id"]):
|
||||
titles.append(item["title"])
|
||||
_new_items_label.text = (
|
||||
"%s\n%s" % [UIText.get_text("reward_screen.new_items_label"), "\n".join(titles)]
|
||||
)
|
||||
|
||||
_collection_button.text = UIText.get_text("reward_screen.collection_button")
|
||||
_collection_button.pressed.connect(_on_collection_pressed)
|
||||
_continue_button.text = UIText.get_text("reward_screen.continue_button")
|
||||
_continue_button.pressed.connect(_on_continue_pressed)
|
||||
|
||||
|
||||
func _on_collection_pressed() -> void:
|
||||
GameManager.pending_mission_id = ""
|
||||
GameManager.goto(GameManager.SCENE_COLLECTION)
|
||||
|
||||
|
||||
func _on_continue_pressed() -> void:
|
||||
GameManager.pending_mission_id = ""
|
||||
GameManager.goto(GameManager.SCENE_WORLD_MAP)
|
||||
|
||||
@@ -34,6 +34,35 @@ unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="MessageLabel" type="Label" parent="CenterContainer/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 2
|
||||
custom_minimum_size = Vector2(480, 0)
|
||||
|
||||
[node name="RecordLabel" type="Label" parent="CenterContainer/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TotalLabel" type="Label" parent="CenterContainer/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="NewItemsLabel" type="Label" parent="CenterContainer/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 2
|
||||
custom_minimum_size = Vector2(480, 0)
|
||||
|
||||
[node name="CollectionButton" type="Button" parent="CenterContainer/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(200, 56)
|
||||
|
||||
[node name="ContinueButton" type="Button" parent="CenterContainer/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
@@ -7,19 +7,23 @@ extends Control
|
||||
## peut basculer sur la carte CE1 pour revoir les notions precedentes.
|
||||
|
||||
const MARKER_HALF_WIDTH := 80.0
|
||||
const MARKER_HALF_HEIGHT := 36.0
|
||||
const MARKER_HALF_HEIGHT := 48.0
|
||||
|
||||
var _viewed_level := "CE1"
|
||||
|
||||
@onready var _title_label: Label = %TitleLabel
|
||||
@onready var _map_area: Control = %MapArea
|
||||
@onready var _level_toggle_button: Button = %LevelToggleButton
|
||||
@onready var _total_stars_label: Label = %TotalStarsLabel
|
||||
@onready var _collection_button: Button = %CollectionButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_viewed_level = ProgressManager.school_level()
|
||||
_level_toggle_button.visible = _viewed_level == "CE2"
|
||||
_level_toggle_button.pressed.connect(_on_level_toggle_pressed)
|
||||
_collection_button.text = UIText.get_text("world_map.collection_button")
|
||||
_collection_button.pressed.connect(_on_collection_pressed)
|
||||
_refresh()
|
||||
|
||||
|
||||
@@ -30,6 +34,9 @@ func _refresh() -> void:
|
||||
"world_map.review_ce1_button" if _viewed_level == "CE2" else "world_map.back_to_ce2_button"
|
||||
)
|
||||
_level_toggle_button.text = UIText.get_text(toggle_key)
|
||||
_total_stars_label.text = (
|
||||
"%s %d" % [UIText.get_text("world_map.total_stars_label"), ProgressManager.stars()]
|
||||
)
|
||||
_populate_missions()
|
||||
|
||||
|
||||
@@ -42,6 +49,10 @@ func _populate_missions() -> void:
|
||||
_map_area.add_child(_build_marker(mission))
|
||||
|
||||
|
||||
func _on_collection_pressed() -> void:
|
||||
GameManager.goto(GameManager.SCENE_COLLECTION)
|
||||
|
||||
|
||||
func _on_level_toggle_pressed() -> void:
|
||||
_viewed_level = "CE1" if _viewed_level == "CE2" else "CE2"
|
||||
_refresh()
|
||||
@@ -49,7 +60,17 @@ func _on_level_toggle_pressed() -> void:
|
||||
|
||||
func _build_marker(mission: Dictionary) -> Control:
|
||||
var button := Button.new()
|
||||
button.text = "%s\n%s" % [mission["title"], _status_label_for(mission)]
|
||||
button.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
button.text = (
|
||||
"%s\n%s\n%s %d/%d"
|
||||
% [
|
||||
mission["title"],
|
||||
_status_label_for(mission),
|
||||
UIText.get_text("world_map.mission_stars_label"),
|
||||
ProgressManager.mission_best_stars(mission["mission_id"]),
|
||||
MissionScoring.MAX_STARS,
|
||||
]
|
||||
)
|
||||
|
||||
var map_position: Dictionary = mission["map_position"]
|
||||
var x: float = map_position["x"]
|
||||
|
||||
@@ -36,6 +36,11 @@ layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="TotalStarsLabel" type="Label" parent="VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="MapArea" type="Control" parent="VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
@@ -46,6 +51,11 @@ unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
|
||||
[node name="CollectionButton" type="Button" parent="VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 48)
|
||||
|
||||
[node name="Guide" type="Control" parent="VBox" instance=ExtResource("2")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
Reference in New Issue
Block a user