Adds a distractor queue to the words minigame to avoid getting the same one several times in a row.
This commit is contained in:
@@ -3,10 +3,14 @@ class_name WordsMinigame
|
||||
|
||||
# Define the maximum number of GP inside each words
|
||||
@export var max_number_of_GPs: int = 6
|
||||
# Define the size of the distractor queue for each GP
|
||||
@export var distractors_queue_size: int = 6
|
||||
|
||||
var current_word_progression: int = 0: set = _set_current_word_progression
|
||||
var max_word_progression: int = 0
|
||||
|
||||
var current_gp_distractors_queue: Array[Dictionary] = []
|
||||
|
||||
# Find the stimuli and distractions of the minigame.
|
||||
func _find_stimuli_and_distractions() -> void:
|
||||
# Get the currently known words list
|
||||
@@ -104,6 +108,13 @@ func _set_current_word_progression(p_current_word_progression: int) -> void:
|
||||
await _on_current_word_progression_changed()
|
||||
|
||||
|
||||
func _reset_distractors_queue() -> void:
|
||||
current_gp_distractors_queue = distractions[current_progression][current_word_progression].duplicate()
|
||||
current_gp_distractors_queue.shuffle()
|
||||
while current_gp_distractors_queue.size() > distractors_queue_size:
|
||||
current_gp_distractors_queue.pop_front()
|
||||
|
||||
|
||||
# Gets the previous stimulus which is already found
|
||||
func _get_previous_stimulus() -> Dictionary:
|
||||
if stimuli.size() == 0 or current_progression == 0:
|
||||
@@ -118,6 +129,7 @@ func _get_current_stimulus() -> Dictionary:
|
||||
return stimuli[current_progression % stimuli.size()]
|
||||
|
||||
|
||||
# Get the distractors for current word
|
||||
func _get_current_distractors() -> Array:
|
||||
return distractions[current_progression]
|
||||
|
||||
@@ -132,8 +144,9 @@ func _get_GP() -> Dictionary:
|
||||
|
||||
# Get a random distractor for the current GP
|
||||
func _get_distractor() -> Dictionary:
|
||||
# TODO Make a pool to avoid getting the same distractor twice
|
||||
return _get_current_distractors()[current_word_progression].pick_random()
|
||||
if current_gp_distractors_queue.is_empty():
|
||||
_reset_distractors_queue()
|
||||
return current_gp_distractors_queue.pop_front()
|
||||
|
||||
|
||||
# Check if the provided GP is the expected answer
|
||||
@@ -152,7 +165,7 @@ func _play_stimulus() -> void:
|
||||
|
||||
|
||||
func _on_current_word_progression_changed() -> void:
|
||||
pass
|
||||
_reset_distractors_queue()
|
||||
|
||||
|
||||
func _on_current_progression_changed() -> void:
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
[node name="WordsMinigame" instance=ExtResource("1_c25or")]
|
||||
script = ExtResource("2_nc3s1")
|
||||
max_number_of_GPs = 6
|
||||
distractors_queue_size = 6
|
||||
lesson_nb = 4
|
||||
difficulty = 1
|
||||
|
||||
@@ -85,6 +85,7 @@ func _highlight() -> void:
|
||||
branch.highlight_berries(_get_GP())
|
||||
highlight_timer.start()
|
||||
|
||||
|
||||
func _get_difficulty_settings() -> DifficultySettings:
|
||||
return difficulty_settings[difficulty]
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ func _create_tracks() -> void:
|
||||
track.difficulty_settings = difficulty_settings[difficulty]
|
||||
track.gp = current_word.GPs[i]
|
||||
track.distractors = current_distractors[i]
|
||||
track.distractors_queue_size = distractors_queue_size
|
||||
|
||||
track.lilypad_in_center.connect(_on_track_lilypad_in_center.bind(track))
|
||||
|
||||
|
||||
@@ -60,10 +60,11 @@ shader_parameter/y_offset = 0.0
|
||||
[node name="FrogMinigame" instance=ExtResource("1_ng5er")]
|
||||
script = ExtResource("2_0xg3r")
|
||||
max_number_of_GPs = 6
|
||||
distractors_queue_size = 6
|
||||
lesson_nb = 12
|
||||
difficulty = 4
|
||||
max_number_of_lives = 5
|
||||
max_progression = 3
|
||||
max_progression = 5
|
||||
|
||||
[node name="MinigameUI" parent="." index="1"]
|
||||
empty_progression_icon = ExtResource("2_e38i1")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
extends Control
|
||||
class_name LilypadTrack
|
||||
|
||||
|
||||
signal lilypad_in_center(lilypad: Lilypad)
|
||||
|
||||
|
||||
@@ -24,6 +23,8 @@ var is_stopped: bool = false
|
||||
var difficulty_settings: FrogMinigame.DifficultySettings
|
||||
var gp: Dictionary = {}
|
||||
var distractors: Array[Dictionary] = []
|
||||
var distractors_queue: Array[Dictionary] = []
|
||||
var distractors_queue_size: int = 5
|
||||
|
||||
var lilypads: Array[Lilypad] = []
|
||||
var lilypad_size: Vector2
|
||||
@@ -71,6 +72,16 @@ func right() -> void:
|
||||
for lilypad: Lilypad in lilypads:
|
||||
await lilypad.right()
|
||||
|
||||
|
||||
func pick_distractor() -> Dictionary:
|
||||
if distractors_queue.is_empty():
|
||||
distractors_queue = distractors.duplicate()
|
||||
distractors_queue.shuffle()
|
||||
while distractors_queue.size() > distractors_queue_size:
|
||||
distractors_queue.pop_front()
|
||||
return distractors_queue.pop_front()
|
||||
|
||||
|
||||
#region Lilypads
|
||||
|
||||
func _spawn_lilypad() -> void:
|
||||
@@ -96,7 +107,7 @@ func _spawn_lilypad() -> void:
|
||||
if is_stimulus:
|
||||
lilypad.stimulus = gp
|
||||
else:
|
||||
lilypad.stimulus = distractors.pick_random()
|
||||
lilypad.stimulus = pick_distractor()
|
||||
|
||||
if is_highlighting:
|
||||
lilypad.highlight()
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
extends WordsMinigame
|
||||
|
||||
const monkey_scene: = preload("res://sources/minigames/monkeys/monkey.tscn")
|
||||
|
||||
|
||||
const audio_streams: = [
|
||||
preload("res://assets/minigames/monkeys/audio/monkey_sendcoco.mp3"),
|
||||
preload("res://assets/minigames/monkeys/audio/monkey_sendcoco_right.mp3"),
|
||||
@@ -184,6 +182,8 @@ func _on_coconut_thrown(monkey: Monkey) -> void:
|
||||
|
||||
|
||||
func _on_current_word_progression_changed() -> void:
|
||||
super()
|
||||
|
||||
var ind_good: = randi_range(0, monkeys.size() - 1)
|
||||
for i in monkeys.size():
|
||||
var monkey: = monkeys[i]
|
||||
|
||||
@@ -16,15 +16,16 @@ spacing_glyph = 20
|
||||
|
||||
[node name="MonkeysMinigame" instance=ExtResource("1_6nhsm")]
|
||||
script = ExtResource("2_12lw5")
|
||||
time_between_words = null
|
||||
time_between_words = 3.0
|
||||
throw_to_king_duration = 1.2
|
||||
throw_to_monkey_duration = 0.8
|
||||
throw_to_plank_duration = 0.8
|
||||
max_number_of_GPs = 6
|
||||
distractors_queue_size = 6
|
||||
lesson_nb = 12
|
||||
difficulty = 4
|
||||
max_number_of_lives = 5
|
||||
max_progression = 2
|
||||
max_progression = 5
|
||||
intro_kalulu_speech = ExtResource("3_ek5u5")
|
||||
help_kalulu_speech = ExtResource("3_khjvy")
|
||||
win_kalulu_speech = ExtResource("4_oe2vh")
|
||||
|
||||
Reference in New Issue
Block a user