Add study session goals and summaries

This commit is contained in:
hz
2026-08-01 02:34:58 -05:00
parent ddc36a8048
commit 2bd2628009
27 changed files with 926 additions and 21 deletions
+71 -6
View File
@@ -11,12 +11,17 @@ var status_label: Label
var start_button: Button
var requested_count := 10
var targeted_setup := false
var goal_option: OptionButton
var target_label: Label
var pending_launch := false
func _ready() -> void:
set_anchors_preset(Control.PRESET_FULL_RECT)
add_theme_constant_override("separation", 16)
if not QuestionBankService.questions_changed.is_connected(_refresh_setup):
QuestionBankService.questions_changed.connect(_refresh_setup)
StudySessionService.session_started.connect(_on_session_started)
StudySessionService.session_failed.connect(_on_session_failed)
var title := Label.new()
title.text = "Block Setup"
@@ -27,9 +32,23 @@ func _ready() -> void:
Style.set_label(system_label, 22, Style.CYAN)
add_child(system_label)
var goal_row := HBoxContainer.new()
var goal_label := Label.new()
goal_label.text = "Finish line"
goal_row.add_child(goal_label)
goal_option = OptionButton.new()
goal_option.add_item("Questions")
goal_option.set_item_metadata(0, "question_count")
goal_option.add_item("Study duration")
goal_option.set_item_metadata(1, "duration")
goal_option.item_selected.connect(_on_goal_changed)
goal_row.add_child(goal_option)
add_child(goal_row)
var size_row := HBoxContainer.new()
size_row.add_child(Label.new())
size_row.get_child(0).text = "Question count"
target_label = Label.new()
target_label.text = "Question count"
size_row.add_child(target_label)
size_spin = SpinBox.new()
size_spin.min_value = 1
size_spin.max_value = 40
@@ -70,13 +89,18 @@ func _ready() -> void:
func on_show(payload: Variant = null) -> void:
if typeof(payload) == TYPE_DICTIONARY:
targeted_setup = true
targeted_setup = bool(payload.get("mastery_target", false))
selected_system = str(payload.get("step3_system", "All Systems"))
requested_count = int(payload.get("question_count", 10))
goal_option.set_meta("mastery_target", targeted_setup)
var requested_goal := str(payload.get("goal_type", "question_count"))
goal_option.select(1 if requested_goal == "duration" else 0)
_on_goal_changed(goal_option.selected)
size_spin.value = requested_count
QuestionBankService.load_targeted_questions(selected_system, requested_count,
int(payload.get("difficulty_min", 0)), int(payload.get("difficulty_max", 0)))
else:
goal_option.set_meta("mastery_target", false)
targeted_setup = false
selected_system = str(payload) if payload != null else "All Systems"
_refresh_setup()
@@ -87,8 +111,9 @@ func _refresh_setup() -> void:
return
system_label.text = "Zone: %s" % selected_system
var available := QuestionBankService.get_questions_for_system(selected_system).size()
size_spin.max_value = max(1, available)
if not QuestionBankService.is_loading and available > 0:
if str(goal_option.get_item_metadata(goal_option.selected)) != "duration":
size_spin.max_value = max(5, available)
if not QuestionBankService.is_loading and available > 0 and str(goal_option.get_item_metadata(goal_option.selected)) != "duration":
size_spin.value = min(requested_count, available) if targeted_setup else min(size_spin.value, available)
targeted_setup = false
start_button.disabled = available == 0 or QuestionBankService.is_loading
@@ -105,5 +130,45 @@ func _start_block() -> void:
if not QuestionBankService.has_questions():
status_label.text = "Questions have not loaded from the API yet."
return
BlockSessionService.start_block(selected_system, int(size_spin.value), mode_option.get_item_text(mode_option.selected))
pending_launch = true
start_button.disabled = true
status_label.text = "Preparing your study goal..."
var mastery_target := bool(goal_option.get_meta("mastery_target", false))
var goal_type := "weak_system" if mastery_target else str(goal_option.get_item_metadata(goal_option.selected))
var target := 10 if mastery_target else int(size_spin.value)
StudySessionService.start(goal_type, target, mode_option.get_item_text(mode_option.selected),
selected_system if selected_system != "All Systems" else "")
func _on_goal_changed(_index: int) -> void:
if str(goal_option.get_item_metadata(goal_option.selected)) == "duration":
target_label.text = "Minutes"
size_spin.min_value = 10
size_spin.max_value = 60
size_spin.step = 5
size_spin.value = 20
else:
target_label.text = "Question count"
size_spin.min_value = 5
size_spin.step = 1
_refresh_setup()
func _on_session_started() -> void:
if not pending_launch or not visible:
return
pending_launch = false
var goal_type := str(StudySessionService.progress.get("goalType", "question_count"))
var block_size := 40 if goal_type == "duration" else int(StudySessionService.progress.get("targetValue", size_spin.value))
BlockSessionService.start_block(selected_system, block_size, mode_option.get_item_text(mode_option.selected))
if goal_type == "duration":
BlockSessionService.seconds_remaining = float(int(StudySessionService.progress.get("secondsRemaining", 0)))
main.show_screen("player")
func _on_session_failed(message: String) -> void:
if not pending_launch or not visible:
return
pending_launch = false
start_button.disabled = false
status_label.text = message