look and learn images, sounds and videos unified methods
This commit is contained in:
@@ -7,15 +7,15 @@ const description_line_class: = preload("res://sources/language_tool/image_and_s
|
||||
|
||||
func _ready() -> void:
|
||||
var _description_line: = description_line_class.instantiate()
|
||||
DirAccess.make_dir_recursive_absolute(_description_line.resource_folder + _description_line.language_folder + _description_line.image_folder)
|
||||
DirAccess.make_dir_recursive_absolute(_description_line.resource_folder + _description_line.language_folder + _description_line.sound_folder)
|
||||
DirAccess.make_dir_recursive_absolute(Database.base_path + Database.language + Database.look_and_learn_images)
|
||||
DirAccess.make_dir_recursive_absolute(Database.base_path + Database.language + Database.look_and_learn_sounds)
|
||||
_description_line.queue_free()
|
||||
|
||||
Database.db.query("Select * FROM GPs")
|
||||
for res in Database.db.query_result:
|
||||
var description_line: = description_line_class.instantiate()
|
||||
description_container.add_child(description_line)
|
||||
description_line.set_gp(res["Grapheme"] + "-" + res["Phoneme"])
|
||||
description_line.set_gp(res)
|
||||
|
||||
|
||||
func _on_back_button_pressed() -> void:
|
||||
|
||||
@@ -10,22 +10,13 @@ signal delete
|
||||
@onready var file_dialog: = $FileDialog
|
||||
@onready var sound_player: = $AudioStreamPlayer
|
||||
|
||||
const resource_folder: = "user://language_resources/"
|
||||
const language_folder: = "french/"
|
||||
const image_folder: = "look_and_learn/images/"
|
||||
const sound_folder: = "look_and_learn/sounds/"
|
||||
const image_extension: = ".png"
|
||||
const sound_extension: = ".mp3"
|
||||
|
||||
var gp: = ""
|
||||
|
||||
|
||||
var gp: Dictionary
|
||||
|
||||
|
||||
func _image_file_selected(file_path: String) -> void:
|
||||
file_dialog.files_selected.connect(_image_file_selected.bind(file_dialog))
|
||||
if FileAccess.file_exists(file_path):
|
||||
var current_file: = _image_file_path()
|
||||
var current_file: = Database.get_gp_look_and_learn_image_path(gp)
|
||||
if FileAccess.file_exists(current_file):
|
||||
DirAccess.remove_absolute(current_file)
|
||||
|
||||
@@ -45,13 +36,9 @@ func set_sound_preview(sound_path: String) -> void:
|
||||
sound_player.stream = sound
|
||||
|
||||
|
||||
func _image_file_path() -> String:
|
||||
return resource_folder + language_folder + image_folder + gp + image_extension
|
||||
|
||||
|
||||
func _sound_file_selected(file_path: String) -> void:
|
||||
if FileAccess.file_exists(file_path):
|
||||
var current_file: = resource_folder + language_folder + sound_folder + gp + sound_extension
|
||||
var current_file: = Database.get_gp_look_and_learn_sound_path(gp)
|
||||
if FileAccess.file_exists(current_file):
|
||||
DirAccess.remove_absolute(current_file)
|
||||
|
||||
@@ -61,27 +48,26 @@ func _sound_file_selected(file_path: String) -> void:
|
||||
sound_preview.show()
|
||||
|
||||
|
||||
func _sound_file_path() -> String:
|
||||
return resource_folder + language_folder + sound_folder + gp + sound_extension
|
||||
func set_gp(value: Dictionary) -> void:
|
||||
gp = value
|
||||
gp_menu_button.text = gp["Grapheme"] + "-" + gp["Phoneme"]
|
||||
|
||||
var image_path: = Database.get_gp_look_and_learn_image_path(gp)
|
||||
if FileAccess.file_exists(image_path):
|
||||
set_image_preview(image_path)
|
||||
|
||||
func set_gp(p_gp: String) -> void:
|
||||
gp = p_gp
|
||||
gp_menu_button.text = gp
|
||||
|
||||
if FileAccess.file_exists(_image_file_path()):
|
||||
set_image_preview(_image_file_path())
|
||||
if FileAccess.file_exists(_sound_file_path()):
|
||||
set_sound_preview(_sound_file_path())
|
||||
var sound_path: = Database.get_gp_look_and_learn_sound_path(gp)
|
||||
if FileAccess.file_exists(sound_path):
|
||||
set_sound_preview(sound_path)
|
||||
sound_preview.show()
|
||||
else:
|
||||
sound_preview.hide()
|
||||
|
||||
|
||||
func _on_image_upload_button_pressed() -> void:
|
||||
if gp != "":
|
||||
if not gp.is_empty():
|
||||
file_dialog.filters = []
|
||||
file_dialog.add_filter("*" + image_extension, "Images")
|
||||
file_dialog.add_filter("*" + Database.image_extension, "Images")
|
||||
|
||||
for connection in file_dialog.file_selected.get_connections():
|
||||
connection["signal"].disconnect(connection["callable"])
|
||||
@@ -92,9 +78,9 @@ func _on_image_upload_button_pressed() -> void:
|
||||
|
||||
|
||||
func _on_sound_upload_button_pressed() -> void:
|
||||
if gp != "":
|
||||
if not gp.is_empty():
|
||||
file_dialog.filters = []
|
||||
file_dialog.add_filter("*" + sound_extension, "Sounds")
|
||||
file_dialog.add_filter("*" + Database.sound_extension, "Sounds")
|
||||
|
||||
for connection in file_dialog.file_selected.get_connections():
|
||||
connection["signal"].disconnect(connection["callable"])
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://d2fegfgf5gefe"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://d2fegfgf5gefe"]
|
||||
|
||||
[ext_resource type="Script" path="res://sources/language_tool/image_and_sound_gp_description.gd" id="1_rm4b8"]
|
||||
[ext_resource type="PackedScene" uid="uid://dbl3r8426473v" path="res://sources/language_tool/plus_button.tscn" id="1_uutsu"]
|
||||
[ext_resource type="Texture2D" uid="uid://5fffpm7hc12k" path="res://assets/menus/upload.png" id="2_0hqnp"]
|
||||
[ext_resource type="Texture2D" uid="uid://b8tctfnsj3prx" path="res://assets/menus/minus_button.png" id="4_10coa"]
|
||||
|
||||
[node name="ImageAndSoundGPDescription" type="HBoxContainer"]
|
||||
script = ExtResource("1_rm4b8")
|
||||
@@ -41,12 +40,6 @@ custom_minimum_size = Vector2(200, 100)
|
||||
layout_mode = 2
|
||||
expand_mode = 1
|
||||
|
||||
[node name="ImageCheckBox" type="CheckBox" parent="ImageContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
button_mask = 0
|
||||
|
||||
[node name="ImageUploadButton" parent="ImageContainer/HBoxContainer" instance=ExtResource("1_uutsu")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
@@ -55,7 +48,7 @@ layout_mode = 2
|
||||
texture = ExtResource("2_0hqnp")
|
||||
|
||||
[node name="MarginContainer3" type="MarginContainer" parent="."]
|
||||
custom_minimum_size = Vector2(776, 0)
|
||||
custom_minimum_size = Vector2(996, 0)
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 20
|
||||
theme_override_constants/margin_top = 10
|
||||
@@ -72,12 +65,6 @@ layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 70
|
||||
text = "Play"
|
||||
|
||||
[node name="SoundCheckBox" type="CheckBox" parent="MarginContainer3/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
button_mask = 0
|
||||
|
||||
[node name="SoundUploadButton" parent="MarginContainer3/HBoxContainer" instance=ExtResource("1_uutsu")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
@@ -85,13 +72,6 @@ layout_mode = 2
|
||||
[node name="TextureRect" parent="MarginContainer3/HBoxContainer/SoundUploadButton" index="0"]
|
||||
texture = ExtResource("2_0hqnp")
|
||||
|
||||
[node name="Button" parent="." instance=ExtResource("1_uutsu")]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TextureRect" parent="Button" index="0"]
|
||||
texture = ExtResource("4_10coa")
|
||||
|
||||
[node name="FileDialog" type="FileDialog" parent="."]
|
||||
title = "Open a File"
|
||||
initial_position = 2
|
||||
@@ -107,8 +87,6 @@ access = 2
|
||||
[connection signal="pressed" from="ImageContainer/HBoxContainer/ImageUploadButton" to="." method="_on_image_upload_button_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer3/HBoxContainer/SoundPreview" to="." method="_on_sound_preview_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer3/HBoxContainer/SoundUploadButton" to="." method="_on_sound_upload_button_pressed"]
|
||||
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
|
||||
|
||||
[editable path="ImageContainer/HBoxContainer/ImageUploadButton"]
|
||||
[editable path="MarginContainer3/HBoxContainer/SoundUploadButton"]
|
||||
[editable path="Button"]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Control
|
||||
|
||||
@export var lesson_nb: = 1
|
||||
@export var current_button_pressed: = 0
|
||||
|
||||
@onready var animation_player: = $AnimationPlayer
|
||||
@@ -19,8 +20,7 @@ const video_extension: = ".ogv"
|
||||
const image_extension: = ".png"
|
||||
const sound_extension: = ".mp3"
|
||||
|
||||
var current_grapheme: = "a"
|
||||
var current_phoneme: = "a"
|
||||
var gp_list: Array[Dictionary]
|
||||
|
||||
var current_video: = 0
|
||||
var videos: = []
|
||||
@@ -29,36 +29,33 @@ var current_image_and_sound: = 0
|
||||
var images: = []
|
||||
var sounds: = []
|
||||
|
||||
var current_tracing: = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
setup()
|
||||
|
||||
|
||||
func setup() -> void:
|
||||
grapheme_label.text = current_grapheme.to_lower() + " " + current_grapheme.to_upper()
|
||||
grapheme_particles.emitting = true
|
||||
gp_list = Database.get_GP_for_lesson(lesson_nb, true)
|
||||
|
||||
videos = []
|
||||
if FileAccess.file_exists(_video_file_path()):
|
||||
videos.append(load(_video_file_path()))
|
||||
current_video = 0
|
||||
current_image_and_sound = 0
|
||||
current_tracing = 0
|
||||
|
||||
images = []
|
||||
sounds = []
|
||||
if FileAccess.file_exists(_image_file_path()) and FileAccess.file_exists(_sound_file_path()):
|
||||
images.append(load(_image_file_path()))
|
||||
sounds.append(load(_sound_file_path()))
|
||||
videos = []
|
||||
for gp in gp_list:
|
||||
var gp_image: = Database.get_gp_look_and_learn_image(gp)
|
||||
var gp_sound: = Database.get_gp_look_and_learn_sound(gp)
|
||||
if gp_image and gp_sound:
|
||||
images.append(gp_image)
|
||||
sounds.append(gp_sound)
|
||||
|
||||
|
||||
func _image_file_path() -> String:
|
||||
return resource_folder + language_folder + image_folder + current_grapheme + "-" + current_phoneme + image_extension
|
||||
|
||||
|
||||
func _sound_file_path() -> String:
|
||||
return resource_folder + language_folder + sound_folder + current_grapheme + "-" + current_phoneme + sound_extension
|
||||
|
||||
|
||||
func _video_file_path() -> String:
|
||||
return resource_folder + language_folder + video_folder + current_grapheme + "-" + current_phoneme + video_extension
|
||||
var gp_video: = Database.get_gp_look_and_learn_video(gp)
|
||||
if gp_video:
|
||||
videos.append(gp_video)
|
||||
|
||||
|
||||
func play_videos() -> void:
|
||||
@@ -83,7 +80,8 @@ func play_images_and_sounds() -> void:
|
||||
|
||||
|
||||
func load_tracing() -> void:
|
||||
tracing_manager.setup(current_grapheme)
|
||||
tracing_manager.setup(gp_list[current_tracing]["Grapheme"])
|
||||
current_tracing += 1
|
||||
|
||||
|
||||
func play_tracing() -> void:
|
||||
@@ -112,4 +110,9 @@ func _on_audio_stream_player_finished() -> void:
|
||||
|
||||
|
||||
func _on_tracing_manager_finished() -> void:
|
||||
animation_player.play("end_tracing")
|
||||
if current_tracing < gp_list.size():
|
||||
tracing_manager.setup(gp_list[current_tracing]["Grapheme"])
|
||||
tracing_manager.start()
|
||||
current_tracing += 1
|
||||
else:
|
||||
animation_player.play("end_tracing")
|
||||
|
||||
@@ -783,7 +783,6 @@ anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_12st1")
|
||||
current_button_pressed = 2
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
|
||||
@@ -10,6 +10,13 @@ const _symbols_to_string = {
|
||||
}
|
||||
const base_path: = "res://language_resources/"
|
||||
|
||||
const look_and_learn_images: = "/look_and_learn/images/"
|
||||
const look_and_learn_sounds: = "/look_and_learn/sounds/"
|
||||
const look_and_learn_videos: = "/look_and_learn/video/"
|
||||
const video_extension: = ".ogv"
|
||||
const image_extension: = ".png"
|
||||
const sound_extension: = ".mp3"
|
||||
|
||||
var language: = "french":
|
||||
set(value):
|
||||
language = value
|
||||
@@ -156,6 +163,52 @@ func get_audio_stream_for_phoneme(phoneme: String) -> AudioStream:
|
||||
return load(words_path + file_name)
|
||||
|
||||
|
||||
func get_gp_look_and_learn_image(gp: Dictionary) -> Texture:
|
||||
var path: = get_gp_look_and_learn_image_path(gp)
|
||||
if FileAccess.file_exists(path):
|
||||
if ResourceLoader.exists(path):
|
||||
return load(path)
|
||||
else:
|
||||
var image: = Image.load_from_file(path)
|
||||
var texture: = ImageTexture.create_from_image(image)
|
||||
return texture
|
||||
|
||||
return null
|
||||
|
||||
|
||||
func get_gp_look_and_learn_sound(gp: Dictionary) -> AudioStream:
|
||||
var path: = get_gp_look_and_learn_sound_path(gp)
|
||||
if FileAccess.file_exists(path):
|
||||
if ResourceLoader.exists(path):
|
||||
return load(path)
|
||||
else:
|
||||
var sound: = AudioStreamOggVorbis.load_from_file(path)
|
||||
return sound
|
||||
|
||||
return AudioStreamOggVorbis.new()
|
||||
|
||||
|
||||
func get_gp_look_and_learn_video(gp: Dictionary) -> VideoStream:
|
||||
var path: = get_gp_look_and_learn_video_path(gp)
|
||||
if FileAccess.file_exists(path):
|
||||
var video: = load(path)
|
||||
return video
|
||||
|
||||
return null
|
||||
|
||||
|
||||
func get_gp_look_and_learn_image_path(gp: Dictionary) -> String:
|
||||
return base_path + language + look_and_learn_images + gp["Grapheme"] + "-" + gp["Phoneme"] + image_extension
|
||||
|
||||
|
||||
func get_gp_look_and_learn_sound_path(gp: Dictionary) -> String:
|
||||
return base_path + language + look_and_learn_sounds + gp["Grapheme"] + "-" + gp["Phoneme"] + sound_extension
|
||||
|
||||
|
||||
func get_gp_look_and_learn_video_path(gp: Dictionary) -> String:
|
||||
return base_path + language + look_and_learn_videos + gp["Grapheme"] + "-" + gp["Phoneme"] + video_extension
|
||||
|
||||
|
||||
func _phoneme_to_string(phoneme: String) -> String:
|
||||
if _symbols_to_string.has(phoneme):
|
||||
return _symbols_to_string[phoneme]
|
||||
|
||||
Reference in New Issue
Block a user