Use SQL queries to remove doubles
This commit is contained in:
@@ -57,8 +57,8 @@ func _setup_minigame() -> void:
|
||||
|
||||
# Find the stimuli and distractions of the minigame.
|
||||
func _find_stimuli_and_distractions() -> void:
|
||||
stimuli = Database.copy_without_double_graphemes(Database.get_GP_for_lesson(lesson_nb))
|
||||
distractions = Database.copy_without_double_graphemes(Database.get_GP_before_lesson(lesson_nb))
|
||||
stimuli = Database.get_GP_for_lesson(lesson_nb, true)
|
||||
distractions = Database.get_GP_before_lesson(lesson_nb, true)
|
||||
|
||||
|
||||
# Launch the minigame
|
||||
|
||||
@@ -24,13 +24,19 @@ func _exit_tree() -> void:
|
||||
db.close_db()
|
||||
|
||||
|
||||
func get_GP_for_lesson(lesson_nb: int) -> Array:
|
||||
db.query_with_bindings("Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb == ?", [lesson_nb])
|
||||
func get_GP_for_lesson(lesson_nb: int, distinct: bool) -> Array:
|
||||
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb == ?"
|
||||
if distinct:
|
||||
query += "GROUP BY Grapheme"
|
||||
db.query_with_bindings(query, [lesson_nb])
|
||||
return db.query_result
|
||||
|
||||
|
||||
func get_GP_before_lesson(lesson_nb: int) -> Array:
|
||||
db.query_with_bindings("Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb < ?", [lesson_nb])
|
||||
func get_GP_before_lesson(lesson_nb: int, distinct: bool) -> Array:
|
||||
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs INNER JOIN Lessons ON Lessons.GPID = GPs.ID AND Lessons.LessonNb < ?"
|
||||
if distinct:
|
||||
query += "GROUP BY Grapheme"
|
||||
db.query_with_bindings(query, [lesson_nb])
|
||||
return db.query_result
|
||||
|
||||
|
||||
@@ -54,16 +60,6 @@ func get_distractors_for_grapheme(grapheme: String, lesson_nb: int) -> Array:
|
||||
return db.query_result
|
||||
|
||||
|
||||
func copy_without_double_graphemes(input: Array) -> Array:
|
||||
var output: = []
|
||||
var graphemes: = {}
|
||||
for val in input:
|
||||
if not graphemes.has(val.Grapheme):
|
||||
output.append(val)
|
||||
graphemes[val.Grapheme] = true
|
||||
return output
|
||||
|
||||
|
||||
func get_audio_stream_for_word(word: String) -> AudioStream:
|
||||
var GPs: = get_GP_from_word(word)
|
||||
var file_name: = _phoneme_to_string(GPs[0].Phoneme)
|
||||
|
||||
Reference in New Issue
Block a user