Adds ratio stimuli difficulty to the frog minigame.
This commit is contained in:
@@ -35,29 +35,6 @@ var difficulty_settings: Array[DifficultySettings] = [
|
||||
@onready var frog: = %Frog
|
||||
|
||||
|
||||
# TODO Remove
|
||||
func _old_find_stimuli_and_distractions() -> void:
|
||||
var words_list: = Database.get_words_for_lesson(lesson_nb)
|
||||
words_list.shuffle()
|
||||
stimuli = []
|
||||
distractions = []
|
||||
for i in max_progression:
|
||||
var word = words_list[i].Word
|
||||
var GPs: = Database.get_GP_from_word(word)
|
||||
stimuli.append({
|
||||
Word = word,
|
||||
GPs = GPs,
|
||||
})
|
||||
var grapheme_distractions: = []
|
||||
for GP in GPs:
|
||||
var distractors: = Database.get_distractors_for_grapheme(GP.Grapheme, lesson_nb)
|
||||
distractors.shuffle()
|
||||
while distractors.size() > 4:
|
||||
distractors.pop_front()
|
||||
grapheme_distractions.append(distractors)
|
||||
distractions.append(grapheme_distractions)
|
||||
|
||||
|
||||
func _setup_word_progression() -> void:
|
||||
await _free_tracks()
|
||||
super()
|
||||
@@ -93,22 +70,12 @@ func _create_tracks() -> void:
|
||||
|
||||
for i in range(current_word.GPs.size()):
|
||||
var track: LilypadTrack = lilypad_track_scene.instantiate()
|
||||
track.name = str(i) + "_" + current_word.GPs[i].Grapheme
|
||||
lilypad_tracks_container.add_child(track)
|
||||
|
||||
track.top_to_bottom = i % 2
|
||||
|
||||
var track_stimuli: = []
|
||||
track_stimuli.append(current_word.GPs[i])
|
||||
track_stimuli.append_array(current_distractors[i])
|
||||
track.stimuli = track_stimuli
|
||||
track.difficulty_settings = difficulty_settings[difficulty]
|
||||
|
||||
var are_distractors: = []
|
||||
are_distractors.append(false)
|
||||
for j in range(current_distractors[i].size()):
|
||||
are_distractors.append(true)
|
||||
track.are_distractors = are_distractors
|
||||
track.gp = current_word.GPs[i]
|
||||
track.distractors = current_distractors[i]
|
||||
|
||||
track.lilypad_in_center.connect(_on_track_lilypad_in_center.bind(track))
|
||||
|
||||
@@ -127,7 +94,7 @@ func _on_track_lilypad_in_center(lilypad: Lilypad, track: LilypadTrack) -> void:
|
||||
frog.jump_to(lilypad.global_position)
|
||||
await frog.jumped
|
||||
|
||||
_log_new_response(lilypad.stimulus, track.stimuli[0])
|
||||
_log_new_response(lilypad.stimulus, track.gp)
|
||||
|
||||
if lilypad.is_distractor:
|
||||
await lilypad.wrong()
|
||||
|
||||
@@ -12,28 +12,22 @@ const lilypad_crossing_time: = 5.0
|
||||
@onready var audio_player: = $AudioStreamPlayer2D
|
||||
@onready var spawn_timer: = $SpawnTimer
|
||||
|
||||
|
||||
var top_to_bottom: = true
|
||||
var ready_to_spawn: = false
|
||||
var is_cleared: = false
|
||||
var is_enabled: = false:
|
||||
set = _set_enabled
|
||||
var is_highlighting: = false:
|
||||
set = _set_highlighting
|
||||
|
||||
var top_to_bottom: = true
|
||||
|
||||
var lilypads: Array[Lilypad] = []
|
||||
|
||||
var stimuli: = []:
|
||||
set = _set_stimuli
|
||||
var are_distractors: = []
|
||||
|
||||
var stimuli_queue: = []
|
||||
var stimuli_queue_size: = 0
|
||||
var is_stopped: bool = false
|
||||
|
||||
var difficulty_settings: FrogMinigame.DifficultySettings
|
||||
var gp: Dictionary = {}
|
||||
var distractors: Array[Dictionary] = []
|
||||
|
||||
var lilypads: Array[Lilypad] = []
|
||||
var lilypad_size: Vector2
|
||||
var is_stopped: bool = false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
if is_stopped:
|
||||
@@ -77,54 +71,49 @@ func right() -> void:
|
||||
for lilypad: Lilypad in lilypads:
|
||||
await lilypad.right()
|
||||
|
||||
#region Lilypads
|
||||
|
||||
func _spawn_lilypad() -> void:
|
||||
var lilypad: Lilypad = lilypad_class.instantiate()
|
||||
lilypads.append(lilypad)
|
||||
|
||||
lilypad.pressed.connect(_on_lilypad_pressed.bind(lilypad))
|
||||
lilypad.disappeared.connect(_on_lilypad_disappeared.bind(lilypad))
|
||||
add_child(lilypad)
|
||||
|
||||
lilypad.disabled = not is_enabled
|
||||
|
||||
var start_point: = global_position + Vector2(size.x / 2.0, size.y)
|
||||
var end_point: = global_position + Vector2(size.x / 2.0, 0.0)
|
||||
if top_to_bottom:
|
||||
start_point = global_position + Vector2(size.x / 2.0, 0.0)
|
||||
end_point = global_position + Vector2(size.x / 2.0, size.y)
|
||||
lilypad.global_position = start_point
|
||||
lilypad.global_position = global_position + Vector2(size.x / 2.0, 0.0)
|
||||
else:
|
||||
lilypad.global_position = global_position + Vector2(size.x / 2.0, size.y)
|
||||
|
||||
lilypad_size = lilypad.get_real_size()
|
||||
if size.x < lilypad_size.x:
|
||||
var s: float = size.x / lilypad_size.x
|
||||
lilypad.scale = Vector2(s, s)
|
||||
lilypad_size *= s
|
||||
|
||||
var potential_stimuli: = stimuli.duplicate()
|
||||
var are_potential_distractors: = are_distractors.duplicate()
|
||||
for stimulus in stimuli_queue:
|
||||
var ind: = potential_stimuli.find(stimulus)
|
||||
potential_stimuli.remove_at(ind)
|
||||
are_potential_distractors.remove_at(ind)
|
||||
|
||||
var i: = randi() % potential_stimuli.size()
|
||||
lilypad.stimulus = potential_stimuli[i]
|
||||
lilypad.is_distractor = are_potential_distractors[i]
|
||||
var is_stimulus: = randf() < difficulty_settings.stimuli_ratio
|
||||
lilypad.is_distractor = !is_stimulus
|
||||
if is_stimulus:
|
||||
lilypad.stimulus = gp
|
||||
else:
|
||||
lilypad.stimulus = distractors.pick_random()
|
||||
|
||||
if is_highlighting:
|
||||
lilypad.highlight()
|
||||
else:
|
||||
lilypad.stop_highlight()
|
||||
|
||||
stimuli_queue.append(potential_stimuli[i])
|
||||
if stimuli_queue.size() > stimuli_queue_size:
|
||||
stimuli_queue.pop_front()
|
||||
lilypad.pressed.connect(_on_lilypad_pressed.bind(lilypad))
|
||||
lilypad.disappeared.connect(_on_lilypad_disappeared.bind(lilypad))
|
||||
|
||||
|
||||
func _despawn_lilypad(lilypad: Lilypad) -> void:
|
||||
lilypads.erase(lilypad)
|
||||
lilypad.queue_free()
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setters
|
||||
|
||||
func _set_enabled(value: bool) -> void:
|
||||
is_enabled = value
|
||||
@@ -141,11 +130,9 @@ func _set_highlighting(value: bool) -> void:
|
||||
else:
|
||||
lilypad.stop_highlight()
|
||||
|
||||
#endregion
|
||||
|
||||
func _set_stimuli(value: Array) -> void:
|
||||
stimuli = value
|
||||
stimuli_queue_size = max(0, stimuli.size() - 3)
|
||||
|
||||
#region Connections
|
||||
|
||||
func _on_lilypad_pressed(lilypad: Lilypad) -> void:
|
||||
audio_player.play()
|
||||
@@ -178,3 +165,5 @@ func _on_spawn_timer_timeout() -> void:
|
||||
spawn_timer.start(randf_range(lilypad_size.y / _get_velocity(), lilypad_size.y * 2 / _get_velocity()))
|
||||
else:
|
||||
spawn_timer.start(randf_range(0.75, 1.5))
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -279,6 +279,7 @@ func get_distractors_for_grapheme(grapheme: String, lesson_nb: int) -> Array:
|
||||
INNER JOIN GPsInLessons
|
||||
ON stimuli.Grapheme=? AND distractor.type = stimuli.type
|
||||
AND distractor.Grapheme != stimuli.Grapheme
|
||||
AND distractor.Phoneme != stimuli.Phoneme
|
||||
AND GPsInLessons.GPID = distractor.ID
|
||||
AND Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?", [grapheme, lesson_nb])
|
||||
return db.query_result
|
||||
|
||||
Reference in New Issue
Block a user