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,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
|
||||
|
||||
Reference in New Issue
Block a user