105 lines
2.6 KiB
GDScript
105 lines
2.6 KiB
GDScript
extends Node
|
|
|
|
signal session_changed
|
|
|
|
var active_questions: Array = []
|
|
var answers: Array = []
|
|
var current_index := 0
|
|
var mode := "Tutor"
|
|
var system_name := "All Systems"
|
|
var seconds_remaining := 0.0
|
|
var block_started := false
|
|
|
|
func start_block(selected_system: String, block_size: int, selected_mode: String) -> void:
|
|
system_name = selected_system
|
|
mode = selected_mode
|
|
active_questions = QuestionBankService.build_block(selected_system, block_size)
|
|
answers.clear()
|
|
answers.resize(active_questions.size())
|
|
current_index = 0
|
|
seconds_remaining = float(active_questions.size() * 90)
|
|
block_started = true
|
|
session_changed.emit()
|
|
|
|
|
|
func get_current_question() -> Dictionary:
|
|
if active_questions.is_empty() or current_index < 0 or current_index >= active_questions.size():
|
|
return {}
|
|
return active_questions[current_index]
|
|
|
|
|
|
func answer_current(choice_id: String, eliminated: Array, flagged: bool) -> Dictionary:
|
|
var question := get_current_question()
|
|
if question.is_empty():
|
|
return {}
|
|
|
|
var answer := {
|
|
"question": question.duplicate(true),
|
|
"selected_choice_id": choice_id,
|
|
"is_correct": choice_id == str(question.get("correct_choice_id", "")),
|
|
"eliminated_choice_ids": eliminated.duplicate(),
|
|
"flagged": flagged
|
|
}
|
|
answers[current_index] = answer
|
|
session_changed.emit()
|
|
return answer
|
|
|
|
|
|
func move_previous() -> bool:
|
|
if current_index > 0:
|
|
current_index -= 1
|
|
session_changed.emit()
|
|
return true
|
|
return false
|
|
|
|
|
|
func move_next() -> bool:
|
|
if current_index + 1 < active_questions.size():
|
|
current_index += 1
|
|
session_changed.emit()
|
|
return true
|
|
return false
|
|
|
|
|
|
func move_to(index: int) -> bool:
|
|
if index >= 0 and index < active_questions.size():
|
|
current_index = index
|
|
session_changed.emit()
|
|
return true
|
|
return false
|
|
|
|
|
|
func get_progress_text() -> String:
|
|
return "%d / %d" % [min(current_index + 1, active_questions.size()), active_questions.size()]
|
|
|
|
|
|
func finish_block() -> Dictionary:
|
|
var final_answers: Array = []
|
|
for index in range(active_questions.size()):
|
|
if answers[index] == null:
|
|
final_answers.append({
|
|
"question": active_questions[index].duplicate(true),
|
|
"selected_choice_id": "",
|
|
"is_correct": false,
|
|
"eliminated_choice_ids": [],
|
|
"flagged": false
|
|
})
|
|
else:
|
|
final_answers.append(answers[index])
|
|
|
|
var results := ProgressionService.calculate_block_rewards(final_answers, mode, system_name)
|
|
ProfileService.apply_block_results(results)
|
|
block_started = false
|
|
session_changed.emit()
|
|
return results
|
|
|
|
|
|
func has_answered_current() -> bool:
|
|
return get_answer_for_index(current_index) != null
|
|
|
|
|
|
func get_answer_for_index(index: int) -> Variant:
|
|
if index < 0 or index >= answers.size():
|
|
return null
|
|
return answers[index]
|