Count up question bank answer timer
This commit is contained in:
@@ -20,6 +20,10 @@ var core_current_target_seconds := 90.0
|
||||
var core_current_had_wrong_attempt := false
|
||||
var current_question_started_at := 0.0
|
||||
var current_question_pause_started_at := 0.0
|
||||
var core_question_total_elapsed_seconds := 0.0
|
||||
var core_question_total_active_since := 0.0
|
||||
var core_question_display_target_seconds := 90.0
|
||||
var core_question_total_frozen := false
|
||||
var core_status_message := ""
|
||||
var simulation_block_index := 0
|
||||
var simulation_total_blocks := 12
|
||||
@@ -62,6 +66,10 @@ func start_core_run() -> bool:
|
||||
core_target_seconds = 90.0
|
||||
core_current_target_seconds = core_target_seconds
|
||||
core_current_had_wrong_attempt = false
|
||||
core_question_total_elapsed_seconds = 0.0
|
||||
core_question_total_active_since = 0.0
|
||||
core_question_display_target_seconds = core_target_seconds
|
||||
core_question_total_frozen = false
|
||||
core_status_message = ""
|
||||
if not advance_core_question():
|
||||
block_started = false
|
||||
@@ -161,6 +169,7 @@ func submit_core_attempt(choice_id: String, eliminated: Array, flagged: bool) ->
|
||||
if bool(answer.get("is_correct", false)):
|
||||
var mastered := not core_current_had_wrong_attempt
|
||||
answers[current_index] = answer
|
||||
_freeze_core_question_total_timer()
|
||||
_apply_core_answer_rewards(answer, mastered)
|
||||
session_changed.emit()
|
||||
return {
|
||||
@@ -311,6 +320,10 @@ func append_core_question(question: Dictionary) -> bool:
|
||||
current_question_started_at = Time.get_ticks_msec() / 1000.0
|
||||
current_question_pause_started_at = 0.0
|
||||
core_current_target_seconds = core_target_seconds
|
||||
core_question_display_target_seconds = core_current_target_seconds
|
||||
core_question_total_elapsed_seconds = 0.0
|
||||
core_question_total_active_since = current_question_started_at
|
||||
core_question_total_frozen = false
|
||||
core_current_had_wrong_attempt = false
|
||||
session_changed.emit()
|
||||
return true
|
||||
@@ -339,6 +352,21 @@ func get_core_timer_ratio() -> float:
|
||||
return clamp(ratio, 0.0, 1.0)
|
||||
|
||||
|
||||
func get_core_question_total_elapsed_seconds() -> float:
|
||||
if session_kind != "core":
|
||||
return 0.0
|
||||
var elapsed := core_question_total_elapsed_seconds
|
||||
if core_question_total_active_since > 0.0:
|
||||
elapsed += Time.get_ticks_msec() / 1000.0 - core_question_total_active_since
|
||||
return maxf(0.0, elapsed)
|
||||
|
||||
|
||||
func get_core_question_elapsed_ratio() -> float:
|
||||
if session_kind != "core" or core_question_display_target_seconds <= 0.0:
|
||||
return 0.0
|
||||
return clampf(get_core_question_total_elapsed_seconds() / core_question_display_target_seconds, 0.0, 1.0)
|
||||
|
||||
|
||||
func get_session_timer_ratio() -> float:
|
||||
if session_kind == "core":
|
||||
return get_core_timer_ratio()
|
||||
@@ -349,14 +377,31 @@ func get_session_timer_ratio() -> float:
|
||||
|
||||
func pause_current_question_timer() -> void:
|
||||
if session_kind == "core" and current_question_pause_started_at <= 0.0:
|
||||
current_question_pause_started_at = Time.get_ticks_msec() / 1000.0
|
||||
var now := Time.get_ticks_msec() / 1000.0
|
||||
current_question_pause_started_at = now
|
||||
_pause_core_question_total_timer(now)
|
||||
|
||||
|
||||
func resume_current_question_timer() -> void:
|
||||
if session_kind == "core" and current_question_pause_started_at > 0.0:
|
||||
var paused_duration := Time.get_ticks_msec() / 1000.0 - current_question_pause_started_at
|
||||
var now := Time.get_ticks_msec() / 1000.0
|
||||
var paused_duration := now - current_question_pause_started_at
|
||||
current_question_started_at += paused_duration
|
||||
current_question_pause_started_at = 0.0
|
||||
if not core_question_total_frozen:
|
||||
core_question_total_active_since = now
|
||||
|
||||
|
||||
func _pause_core_question_total_timer(now: float) -> void:
|
||||
if core_question_total_active_since <= 0.0:
|
||||
return
|
||||
core_question_total_elapsed_seconds += maxf(0.0, now - core_question_total_active_since)
|
||||
core_question_total_active_since = 0.0
|
||||
|
||||
|
||||
func _freeze_core_question_total_timer() -> void:
|
||||
_pause_core_question_total_timer(Time.get_ticks_msec() / 1000.0)
|
||||
core_question_total_frozen = true
|
||||
|
||||
|
||||
func _draw_core_question() -> Dictionary:
|
||||
|
||||
@@ -986,8 +986,7 @@ func _load_question() -> void:
|
||||
timer_footer.visible = show_timer
|
||||
if show_timer:
|
||||
if BlockSessionService.session_kind == "core":
|
||||
var core_seconds := int(ceil(BlockSessionService.core_current_target_seconds - BlockSessionService.get_current_elapsed_seconds()))
|
||||
_set_timer_display(maxi(0, core_seconds))
|
||||
_set_timer_display(int(floor(BlockSessionService.get_core_question_total_elapsed_seconds())))
|
||||
else:
|
||||
_set_timer_display(int(ceil(BlockSessionService.seconds_remaining)))
|
||||
_update_timer_bar()
|
||||
@@ -1297,9 +1296,7 @@ func _show_answer_review() -> void:
|
||||
_show_references(BlockSessionService.get_current_question().get("references", []))
|
||||
_ensure_answer_review_followups()
|
||||
_render_answer_review_sections()
|
||||
timer_bar.visible = false
|
||||
timer_label.visible = false
|
||||
timer_footer.visible = false
|
||||
_set_answer_review_timer_visibility()
|
||||
next_button.text = "Next"
|
||||
next_button.disabled = false
|
||||
if skip_button != null:
|
||||
@@ -1309,6 +1306,15 @@ func _show_answer_review() -> void:
|
||||
question_scroll.call_deferred("ensure_control_visible", explanation_label)
|
||||
|
||||
|
||||
func _set_answer_review_timer_visibility() -> void:
|
||||
var keep_core_timer := BlockSessionService.session_kind == "core"
|
||||
timer_bar.visible = keep_core_timer
|
||||
timer_label.visible = keep_core_timer
|
||||
timer_footer.visible = keep_core_timer
|
||||
if keep_core_timer:
|
||||
_update_timer_bar()
|
||||
|
||||
|
||||
func _show_explanation() -> void:
|
||||
var question := BlockSessionService.get_current_question()
|
||||
for button in choice_buttons:
|
||||
@@ -1619,19 +1625,27 @@ func _exit_run() -> void:
|
||||
func _update_timer_bar() -> void:
|
||||
if timer_bar == null:
|
||||
return
|
||||
var ratio := BlockSessionService.get_session_timer_ratio()
|
||||
var is_core_timer := BlockSessionService.session_kind == "core"
|
||||
var ratio := BlockSessionService.get_core_question_elapsed_ratio() if is_core_timer else BlockSessionService.get_session_timer_ratio()
|
||||
timer_bar.value = ratio * 100.0
|
||||
if BlockSessionService.session_kind == "core" and timer_label.visible:
|
||||
var remaining := int(ceil(BlockSessionService.core_current_target_seconds - BlockSessionService.get_current_elapsed_seconds()))
|
||||
_set_timer_display(maxi(0, remaining))
|
||||
if is_core_timer and timer_label.visible:
|
||||
_set_timer_display(int(floor(BlockSessionService.get_core_question_total_elapsed_seconds())))
|
||||
var color_state := "blue"
|
||||
var fill_color := Brand.ROYAL_BLUE
|
||||
if ratio < 0.25:
|
||||
color_state = "red"
|
||||
fill_color = Style.RED
|
||||
elif ratio <= 0.5:
|
||||
color_state = "amber"
|
||||
fill_color = Style.AMBER
|
||||
if is_core_timer:
|
||||
if ratio >= 1.0:
|
||||
color_state = "red"
|
||||
fill_color = Style.RED
|
||||
elif ratio >= 0.75:
|
||||
color_state = "amber"
|
||||
fill_color = Style.AMBER
|
||||
else:
|
||||
if ratio < 0.25:
|
||||
color_state = "red"
|
||||
fill_color = Style.RED
|
||||
elif ratio <= 0.5:
|
||||
color_state = "amber"
|
||||
fill_color = Style.AMBER
|
||||
if color_state != timer_color_state:
|
||||
timer_color_state = color_state
|
||||
timer_bar.add_theme_stylebox_override("fill", Style.button_box(fill_color, fill_color))
|
||||
|
||||
Reference in New Issue
Block a user