Adds a base scene for Hear and find minigames. Makes JellyfishMinigame extends HearAndFindMinigame. Adds logics for importing syllables from old version. Fixes minigames UI for 10 max progress

This commit is contained in:
Dylan Sarrazyn
2024-03-05 16:54:20 +01:00
committed by BimDav
parent 6c751f0bf2
commit 6ca09d4183
18 changed files with 249 additions and 128 deletions
File diff suppressed because one or more lines are too long
Binary file not shown.
-2
View File
@@ -1,7 +1,5 @@
extends Minigame
@export var difficulty: = 3
@onready var sentence: = %Sentence
@onready var ants_spawn: = %AntsSpawn
@onready var ants_start: = %AntsStart
@@ -0,0 +1,14 @@
extends AudioStreamPlayer
class_name MinigameAudioStreamPlayer
func play_phoneme(phoneme : String) -> void:
var phoneme_audiostream = Database.get_audio_stream_for_phoneme(phoneme) as AudioStream
if not phoneme_audiostream:
push_warning("AudioStream not found for phoneme " + phoneme)
return
stream = phoneme_audiostream
play()
if playing:
await finished
+5 -2
View File
@@ -4,7 +4,9 @@ class_name Minigame
@export var minigame_name: = "Minigame"
@export var lesson_nb: = 10
@export var lesson_nb: = 1
@export_range(0, 4) var difficulty: = 0
@export_range(0, 1) var stimuli_ratio : float = 0.7
@export var minigame_number: = 1
@export_group("Difficulty")
@@ -27,7 +29,8 @@ class_name Minigame
@export var lose_kalulu_speech: AudioStream = preload("res://language_resources/fr/minigames/kalulu/kalulu_lose_minigame_all.mp3")
@onready var minigame_ui: = $MinigameUI
@onready var audio_player: = $AudioStreamPlayer
@onready var opening_curtain: = $OpeningCurtain
@onready var audio_player: MinigameAudioStreamPlayer = $AudioStreamPlayer
@onready var fireworks: = $Fireworks
# Game root shall contain all the game tree.
+4 -1
View File
@@ -1,7 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://8awe4usnucyv"]
[gd_scene load_steps=6 format=3 uid="uid://8awe4usnucyv"]
[ext_resource type="Script" path="res://sources/minigames/base/base_minigame.gd" id="1_jdfsm"]
[ext_resource type="PackedScene" uid="uid://weree6bnlt6f" path="res://sources/minigames/base/minigame_ui.tscn" id="2_a3tib"]
[ext_resource type="Script" path="res://sources/minigames/base/MinigameAudioStreamPlayer.gd" id="2_dkgx4"]
[ext_resource type="PackedScene" path="res://sources/minigames/base/opening_curtain.tscn" id="3_p5ryr"]
[ext_resource type="PackedScene" uid="uid://d1gkvqxe1n8o8" path="res://sources/utils/fx/fireworks.tscn" id="4_yekwo"]
[node name="BaseMinigame" type="Control"]
@@ -17,6 +19,7 @@ minigame_number = null
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
bus = &"Effects"
script = ExtResource("2_dkgx4")
[node name="MinigameUI" parent="." instance=ExtResource("2_a3tib")]
@@ -0,0 +1,95 @@
extends Minigame
class_name HearAndFindMinigame
func _find_stimuli_and_distractions() -> void:
var current_lesson_stimuli = []
var previous_lesson_stimuli = []
var all_GPs = Database.get_GP_before_and_for_lesson(lesson_nb, false)
var all_syllables = Database.get_syllables_for_lesson(lesson_nb, false)
# Find the GPs for current lesson
for gp in all_GPs:
# Adds the vowels (Type = 1)
if gp.Type == 1:
if gp.LessonNb == lesson_nb:
current_lesson_stimuli.append(gp)
else:
previous_lesson_stimuli.append(gp)
# Find the syllables for current lesson
for syllable in all_syllables:
if syllable.LessonNb == lesson_nb:
current_lesson_stimuli.append(syllable)
else:
previous_lesson_stimuli.append(syllable)
# If there is no previous stimuli, only adds from current lesson
if previous_lesson_stimuli.is_empty():
while stimuli.size() < max_progression:
stimuli.append(current_lesson_stimuli[randi() % current_lesson_stimuli.size()])
else:
# Calculate the number of stimuli to add from this lesson (70% of the maximum progression)
@warning_ignore("narrowing_conversion")
var number_of_stimuli: int = max_progression * stimuli_ratio
while stimuli.size() < number_of_stimuli:
stimuli.append(current_lesson_stimuli[randi() % current_lesson_stimuli.size()])
# Gets other stimuli from previous errors or lessons
# TODO Handle previous errors
while stimuli.size() < max_progression:
stimuli.append(previous_lesson_stimuli[randi() % previous_lesson_stimuli.size()])
# Shuffle the stimuli
stimuli.shuffle()
# For each stimuli get the distractors
for stimulus in stimuli:
var stimulus_distractors := []
var GPs : Array
if stimulus.has("GPs") and stimulus.GPs and stimulus.GPs.size() == 2:
GPs = stimulus.GPs
# Difficulty 1
# Any previously learned item w/ all letters different
for gp in all_GPs:
if gp.Grapheme != stimulus.Grapheme and gp.Phoneme != stimulus.Phoneme:
stimulus_distractors.append(gp)
if GPs:
for syllable in all_syllables:
if syllable.GPs[0] not in GPs and syllable.GPs[1] not in GPs:
stimulus_distractors.append(syllable)
# Higher difficulties only changes syllables distractors
if difficulty > 1 and GPs:
for syllable in all_syllables:
# Difficulty 2-3
# If the item has 2 GP ('cha'), distractors should have only a single letter change ('la' or 'che')
if (syllable.GPs[0] == stimulus.GPs[0] and syllable.GPs[1] != stimulus.GPs[1]) or (syllable.GPs[0] != stimulus.GPs[0] and syllable.GPs[1] == stimulus.GPs[1]):
stimulus_distractors.append(syllable)
# Difficulty 4-5
# If the item has 2 GP, inversed TARGET, i.e., for 'il', 'li' is a distractor
if difficulty > 3 and syllable.GPs[0] == stimulus.GPs[1] and syllable.GPs[1] == stimulus.GPs[0]:
stimulus_distractors.append(syllable)
# Adds fake distractors (allow to have empty jellyfishes) if there are less than 4 distractors
while stimulus_distractors.size() < 4:
stimulus_distractors.append({})
distractions.append(stimulus_distractors)
func _get_current_stimulus() -> Dictionary :
if stimuli.size() == 0:
return {}
return stimuli[current_progression % stimuli.size()]
func _play_current_stimulus_phoneme()-> void:
var current_stimulus: = _get_current_stimulus()
if not current_stimulus or not current_stimulus.has("Phoneme"):
return
await audio_player.play_phoneme(current_stimulus.Phoneme)
@@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://clbi7qphyh0so"]
[ext_resource type="PackedScene" uid="uid://8awe4usnucyv" path="res://sources/minigames/base/base_minigame.tscn" id="1_fbfdj"]
[ext_resource type="Script" path="res://sources/minigames/base/hear_and_find/hear_and_find_minigame.gd" id="2_v8ldm"]
[node name="HearAndFindMinigame" instance=ExtResource("1_fbfdj")]
script = ExtResource("2_v8ldm")
max_number_of_lives = 3
max_progression = 10
+3 -2
View File
@@ -344,7 +344,8 @@ anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -210.0
offset_bottom = 962.0
offset_right = -70.0
offset_bottom = 440.0
grow_horizontal = 0
size_flags_horizontal = 8
mouse_filter = 2
@@ -364,7 +365,7 @@ patch_margin_bottom = 33
[node name="ProgressionContainer" type="VBoxContainer" parent="MainControl/Interface/ProgressionMargin/MarginContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(170, 2.08165e-12)
custom_minimum_size = Vector2(135, 0)
layout_mode = 2
[node name="ProgressionIconsRect" type="TextureRect" parent="MainControl/Interface/ProgressionMargin/MarginContainer/ProgressionContainer"]
@@ -1,8 +1,6 @@
@tool
extends Minigame
@export var difficulty: = 1
const hole_class: = preload("res://sources/minigames/crabs/hole/hole.tscn")
const difficulty_settings: = {
0: {"crab_rows": [2, 1]},
-2
View File
@@ -1,7 +1,5 @@
extends Minigame
@export var difficulty: = 1
@onready var start: = %Start
@onready var end: = %End
+4
View File
@@ -72,6 +72,10 @@ func highlight() -> void:
highlight_fx.play()
func stop_highlight() -> void:
highlight_fx.stop()
func right() -> void:
right_fx.play()
await right_fx.finished
+6 -5
View File
@@ -6,14 +6,15 @@
[ext_resource type="PackedScene" uid="uid://cge0uyn30tcpv" path="res://sources/utils/fx/highlight.tscn" id="3_5uhvd"]
[ext_resource type="Script" path="res://sources/utils/percent_margin_container.gd" id="3_vllju"]
[ext_resource type="PackedScene" uid="uid://bgio7muqck2bu" path="res://sources/utils/auto_size_label.tscn" id="4_26xiq"]
[ext_resource type="SpriteFrames" uid="uid://dquynn3nx52o" path="res://sources/minigames/jellyfish/red_jellyfish_animations.tres" id="4_d8s11"]
[ext_resource type="SpriteFrames" uid="uid://dkemftb4jdxvs" path="res://sources/minigames/jellyfish/green_jellyfish_animations.tres" id="5_0850m"]
[ext_resource type="PackedScene" uid="uid://dlmbxcgiv8tpr" path="res://sources/utils/fx/wrong.tscn" id="6_w1tlu"]
[node name="Jellyfish" type="MarginContainer"]
custom_minimum_size = Vector2(466.955, 466.955)
custom_minimum_size = Vector2(527.703, 527.703)
offset_right = 200.0
offset_bottom = 200.0
script = ExtResource("1_06uwq")
color = 1
[node name="HighlightFX" parent="." instance=ExtResource("3_5uhvd")]
layout_mode = 2
@@ -31,10 +32,10 @@ sprites = [NodePath("AnimatedSprite2D")]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="SpriteControl"]
unique_name_in_owner = true
scale = Vector2(2.50538, 2.50538)
sprite_frames = ExtResource("4_d8s11")
scale = Vector2(2.42857, 2.42857)
sprite_frames = ExtResource("5_0850m")
animation = &"idle"
frame_progress = 0.106154
frame_progress = 0.79521
centered = false
[node name="PercentMarginContainer" type="Container" parent="."]
@@ -1,10 +1,10 @@
extends Minigame
extends HearAndFindMinigame
const jellyfish_scene: = preload("res://sources/minigames/jellyfish/jellyfish.tscn")
class DifficultySettings:
var spawn_time: = 4.0
var stimuli_ratio: = 0.6
var stimuli_ratio: = 0.75
var velocity: = 150
func _init(p_spawn_time: float, p_stimuli_ratio: float, p_velocity: int) -> void:
@@ -12,7 +12,6 @@ class DifficultySettings:
stimuli_ratio = p_stimuli_ratio
velocity = p_velocity
var difficulty_settings: = {
0: DifficultySettings.new(4, 0.75, 150),
1: DifficultySettings.new(3, 0.66, 175),
@@ -21,54 +20,11 @@ var difficulty_settings: = {
4: DifficultySettings.new(1, 0.25, 300),
}
@export var lesson_nb: = 4
@export var difficulty: = 0
var blocking_jellyfish: Array[Jellyfish] = []
@onready var spawning_space: Control = %SpawningSpace
@onready var spawn_timer: = $SpawnTimer
func _find_stimuli_and_distractions() -> void:
# Gets the stimuli (only vowels for now) for the current lesson
var current_lesson_stimuli = Database.get_vowels_for_lesson(lesson_nb)
# Calculate the number of stimuli to add from this lesson (70% of the maximum progression)
@warning_ignore("narrowing_conversion")
var number_of_stimuli: int = max_progression * 0.7
# Adds the right number of stimuli from current lesson
while stimuli.size() < number_of_stimuli:
stimuli.append(current_lesson_stimuli[randi() % current_lesson_stimuli.size()])
# Gets other stimuli from previous errors or lessons
var previous_lesson_stimuli = Database.get_vowels_before_lesson(lesson_nb)
while stimuli.size() < max_progression:
stimuli.append(previous_lesson_stimuli[randi() % previous_lesson_stimuli.size()])
# Shuffle the stimuli
stimuli.shuffle()
# For each stimuli get the distractors
var all_learned_stimuli = previous_lesson_stimuli
all_learned_stimuli.append_array(current_lesson_stimuli)
for stimulus in stimuli:
var stimulus_distractors := []
for distractor in all_learned_stimuli:
if stimulus.Grapheme != distractor.Grapheme and stimulus.Phoneme != distractor.Phoneme:
stimulus_distractors.append(distractor)
# Adds fake distractors (allow to have empty jellyfishes) if there are less than 4 distractors
while stimulus_distractors.size() < 4:
stimulus_distractors.append({})
distractions.append(stimulus_distractors)
print(stimuli)
print(distractions)
@onready var highlight_timer := $HighlightTimer
func _start() -> void:
@@ -93,10 +49,16 @@ func _process(delta: float) -> void:
func _highlight():
# TODO Revoir, il faut highlight les méduses jusqu'à ce que la bonne réponse soit trouvée ? Ou pendant un certain temps ? Ou on laisse comme ça ?
for jellyfish: Jellyfish in spawning_space.get_children():
if jellyfish.stimulus and jellyfish.stimulus.Grapheme == _get_current_stimulus().Grapheme:
jellyfish.highlight()
highlight_timer.start()
func _stop_highlight():
for jellyfish: Jellyfish in spawning_space.get_children():
jellyfish.stop_highlight()
highlight_timer.stop()
func _spawn() -> void:
@@ -159,34 +121,6 @@ func _get_difficulty_settings() -> DifficultySettings:
return difficulty_settings[difficulty]
func _get_current_stimulus() -> Dictionary :
if stimuli.size() == 0:
return {}
return stimuli[current_progression % stimuli.size()]
# TODO Peut être à déplacer dans un script attaché à l'AudioStreamPlayer de BaseMinigame
func _play_phoneme(phoneme : String) -> void:
var phoneme_audiostream = Database.get_audio_stream_for_phoneme(phoneme) as AudioStream
if not phoneme_audiostream:
push_warning("AudioStream not found for phoneme " + phoneme)
return
audio_player.stream = phoneme_audiostream
audio_player.play()
if audio_player.playing:
await audio_player.finished
func _play_current_stimulus_phoneme()-> void:
var current_stimulus: = _get_current_stimulus()
if not current_stimulus or not current_stimulus.has("Phoneme"):
return
await _play_phoneme(current_stimulus.Phoneme)
# ------------ Connections ------------
@@ -209,6 +143,7 @@ func _on_jellyfish_pressed(jellyfish: Jellyfish) -> void:
jellyfish.happy()
jellyfish.right()
current_progression += 1
_stop_highlight()
else:
jellyfish.hit()
jellyfish.wrong()
@@ -216,7 +151,7 @@ func _on_jellyfish_pressed(jellyfish: Jellyfish) -> void:
# Play the pressed jellyfish phoneme
if jellyfish.stimulus and jellyfish.stimulus.Phoneme:
await _play_phoneme(jellyfish.stimulus.Phoneme)
await audio_player.play_phoneme(jellyfish.stimulus.Phoneme)
# Remove the jellyfish
await jellyfish.delete()
@@ -230,6 +165,10 @@ func _on_jellyfish_pressed(jellyfish: Jellyfish) -> void:
_play_current_stimulus_phoneme()
func _on_highlight_timer_timeout():
_highlight()
# ------------ UI Callbacks ------------
@@ -1,6 +1,6 @@
[gd_scene load_steps=9 format=3 uid="uid://dtcgj6ee8jt2t"]
[ext_resource type="PackedScene" uid="uid://8awe4usnucyv" path="res://sources/minigames/base/base_minigame.tscn" id="1_hauef"]
[ext_resource type="PackedScene" uid="uid://clbi7qphyh0so" path="res://sources/minigames/base/hear_and_find/hear_and_find_minigame.tscn" id="1_hauef"]
[ext_resource type="AudioStream" uid="uid://bmijth0bydhw7" path="res://language_resources/fr/minigames/jellyfish/audio/kalulu_help_jellyfish_language.mp3" id="2_7li38"]
[ext_resource type="Script" path="res://sources/minigames/jellyfish/jellyfish_minigame.gd" id="2_gnjlp"]
[ext_resource type="AudioStream" uid="uid://bluyy10ia8sek" path="res://language_resources/fr/minigames/jellyfish/audio/kalulu_intro_jellyfish_language.mp3" id="3_6sswr"]
@@ -11,10 +11,8 @@
[node name="JellyfishMinigame" instance=ExtResource("1_hauef")]
script = ExtResource("2_gnjlp")
lesson_nb = 12
difficulty = 4
max_number_of_lives = 3
max_progression = 9
lesson_nb = 6
difficulty = 1
intro_kalulu_speech = ExtResource("3_6sswr")
help_kalulu_speech = ExtResource("2_7li38")
win_kalulu_speech = ExtResource("3_ar7nu")
@@ -47,4 +45,8 @@ grow_vertical = 2
[node name="SpawnTimer" type="Timer" parent="." index="4"]
[node name="HighlightTimer" type="Timer" parent="." index="5"]
wait_time = 5.0
[connection signal="timeout" from="SpawnTimer" to="." method="_on_spawn_timer_timeout"]
[connection signal="timeout" from="HighlightTimer" to="." method="_on_highlight_timer_timeout"]
@@ -23,7 +23,6 @@ enum Audio {
SendToMonkey,
}
@export var difficulty: = 1
@export var throw_to_king_duration: = 1.2
@export var throw_to_monkey_duration: = 0.4
@export var throw_to_planck_duration: = 0.8
@@ -24,7 +24,6 @@ const audio_streams: = [
preload("res://assets/minigames/parakeets/audio/parakeet_win.mp3"),
]
@export var difficulty: = 1
@export var fly_duration: = 3.0
@onready var branches: = $GameRoot/TreeTrunk/Branches
+85 -28
View File
@@ -31,17 +31,21 @@ var db_path: = base_path + language + "/language.db":
db.path = db_path
db.foreign_keys = true
db.open_db()
_init_db()
var words_path: = base_path + language + "/words/"
var additional_word_list: Dictionary
@onready var db: = SQLite.new()
func _ready() -> void:
func _init_db() -> void:
load_additional_word_list()
# db_path = db_path
#_import_words_csv()
#_import_look_and_learn_data()
_import_syllables()
func get_additional_word_list_path() -> String:
@@ -72,7 +76,7 @@ func _exit_tree() -> void:
func get_GP_for_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs
var query: = "Select Grapheme, Phoneme, Type, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb == ?"
if distinct:
@@ -82,7 +86,7 @@ func get_GP_for_lesson(lesson_nb: int, distinct: bool) -> Array:
func get_GP_before_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs
var query: = "Select Grapheme, Phoneme, Type, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb < ?"
if distinct:
@@ -92,7 +96,7 @@ func get_GP_before_lesson(lesson_nb: int, distinct: bool) -> Array:
func get_GP_before_and_for_lesson(lesson_nb: int, distinct: bool) -> Array:
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs
var query: = "Select Grapheme, Phoneme, Type, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?"
if distinct:
@@ -101,24 +105,6 @@ func get_GP_before_and_for_lesson(lesson_nb: int, distinct: bool) -> Array:
return db.query_result
func get_vowels_for_lesson(lesson_nb: int) -> Array:
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb == ?
WHERE Type=1"
db.query_with_bindings(query, [lesson_nb])
return db.query_result
func get_vowels_before_lesson(lesson_nb: int) -> Array:
var query: = "Select Grapheme, Phoneme, LessonNb FROM GPs
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPs.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb < ?
WHERE Type=1"
db.query_with_bindings(query, [lesson_nb])
return db.query_result
func get_GP_from_word(word: String) -> Array:
db.query_with_bindings("SELECT Grapheme, Phoneme FROM Words INNER JOIN GPsInWords ON Words.ID = GPsInWords.WordID AND Words.Word=? INNER JOIN GPs WHERE GPS.ID = GPsInWords.GPID ORDER BY Position", [word])
return db.query_result
@@ -129,6 +115,39 @@ func get_words_containing_grapheme(grapheme: String) -> Array:
return db.query_result
func get_syllables_for_lesson(lesson_nb: int, only_new: = false) -> Array:
var query: = "SELECT Syllable as Grapheme, GROUP_CONCAT(p, '-') AS Phoneme, GROUP_CONCAT(g, '.') AS GPs, nb as LessonNb
FROM (
SELECT Syllables.ID as sID, Syllables.Syllable, GPs.Grapheme AS g, GPs.Phoneme AS p, VerifiedCount.LessonNb AS nb
FROM Syllables
INNER JOIN GPsInSyllables ON Syllables.ID = GPsInSyllables.SyllableID
INNER JOIN Gps ON GPs.ID = GPsInSyllables.GPID
INNER JOIN (SELECT SyllableID, count() as Count FROM GPsInSyllables
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPsInSyllables.GPID
GROUP BY SyllableID
) TotalCount ON TotalCount.SyllableID = Syllables.ID
INNER JOIN (SELECT SyllableID, count() as Count, max(LessonNb) AS LessonNb FROM GPsInSyllables
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPsInSyllables.GPID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?
GROUP BY SyllableID
) VerifiedCount ON VerifiedCount.SyllableID = Syllables.ID AND VerifiedCount.Count = TotalCount.Count
ORDER BY GPsInSyllables.Position
)"
if only_new:
query += " INNER JOIN GPsInSyllables ON GPsInSyllables.SyllableID = sID
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPsInSyllables.GPID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb = ?
GROUP BY sID"
db.query_with_bindings(query, [lesson_nb, lesson_nb])
else:
query += " GROUP BY sID"
db.query_with_bindings(query, [lesson_nb])
var result = db.query_result
for syllable in result:
syllable.GPs = syllable.GPs.split(".")
return result
func get_words_for_lesson(lesson_nb: int, only_new: = false) -> Array:
var query: = "SELECT * FROM Words
INNER JOIN
@@ -180,11 +199,6 @@ func get_distractors_for_grapheme(grapheme: String, lesson_nb: int) -> Array:
AND Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?", [grapheme, lesson_nb])
return db.query_result
func get_audio_stream_for_path(path: String) -> AudioStream:
var full_path : String = base_path.path_join(language).path_join(path)
if not FileAccess.file_exists(full_path):
return null
return load(full_path)
func get_min_lesson_for_gp_id(gp_id: int) -> int:
db.query_with_bindings("SELECT Lessons.LessonNb as i FROM Lessons
@@ -228,6 +242,10 @@ func get_lessons_count() -> int:
return db.query_result[0].i
func get_audio_stream_for_path(path: String) -> AudioStream:
return load(base_path + language + "/" + path)
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)
@@ -333,7 +351,6 @@ func _import_look_and_learn_data() -> void:
Grapheme = e.GRAPHEME,
Phoneme = e.PHONEME,
}))
func _update_gps_with_type() -> void:
@@ -352,6 +369,46 @@ func _update_gps_with_type() -> void:
db.query_with_bindings("UPDATE GPs SET Type=? WHERE id=?", [type, id])
func _import_syllables() -> void:
var file = FileAccess.open("res://data3/words_list.json", FileAccess.READ)
var dict = JSON.parse_string(file.get_line())
for e in dict.values():
if e.NB_GRAPHEME == 2 and e.NB_LETTER <= 3:
# Inserts syllable
db.query_with_bindings("SELECT * FROM Syllables WHERE Syllable=?", [e.GRAPHEME])
if db.query_result.is_empty():
db.insert_row("Syllables", {Syllable=e.GRAPHEME})
# Inserts GPs in syllable
db.query_with_bindings("SELECT * FROM Syllables WHERE Syllable=?", [e.GRAPHEME])
var syllable_id = db.query_result[0]["ID"]
# Checks if GPsInSyllables is already inserted
db.query_with_bindings("SELECT ID FROM GPsInSyllables WHERE SyllableID=?", [syllable_id])
if db.query_result.is_empty():
var GP_list_str: String = e.GPMATCH
var GP_list: = GP_list_str.split(".")
for i in GP_list.size():
var GP_str = GP_list[i]
var GP = GP_str.split("-")
# Checks if GP exists
db.query_with_bindings("SELECT * FROM GPs WHERE Grapheme=? AND Phoneme=?", [GP[0], GP[1]])
if db.query_result.is_empty():
push_error("GP not found for " + GP_str)
continue
var GP_id = db.query_result[0]["ID"]
db.insert_row("GPsInSyllables", {
SyllableID = syllable_id,
GPID = GP_id,
Position = i,
})
func _import_words() -> void:
var file = FileAccess.open("res://data3/words_list.json", FileAccess.READ)
var dict = JSON.parse_string(file.get_line())