Clean code to avoid variables with 1 char name, and some other cleaning (hard-tying, commenting etc...)
This commit is contained in:
@@ -49,8 +49,8 @@ func _reorder_by(property_name: String) -> void:
|
||||
elements_container.add_child(element)
|
||||
|
||||
|
||||
func sorting_function(a: Node, b: Node, property_name: String) -> bool:
|
||||
return a.get(property_name) < b.get(property_name)
|
||||
func sorting_function(node_a: Node, node_b: Node, property_name: String) -> bool:
|
||||
return node_a.get(property_name) < node_b.get(property_name)
|
||||
|
||||
|
||||
func _on_list_title_add_pressed() -> void:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#TODO CLEAN WARNINGS
|
||||
extends Control
|
||||
|
||||
var element_scene: PackedScene = preload("res://sources/language_tool/gp_list_element.tscn")
|
||||
@@ -56,14 +57,14 @@ func _on_save_button_pressed() -> void:
|
||||
var query: String = "Select * FROM GPs"
|
||||
Database.db.query(query)
|
||||
var result: Array[Dictionary] = Database.db.query_result
|
||||
for e in result:
|
||||
var found: = false
|
||||
for res: Dictionary in result:
|
||||
var found: bool = false
|
||||
for element: GPListElement in elements_container.get_children():
|
||||
if element.grapheme == e.Grapheme and element.phoneme == e.Phoneme and element.type == e.Type and element.exception == e.Exception:
|
||||
if element.grapheme == res.Grapheme and element.phoneme == res.Phoneme and element.type == res.Type and element.exception == res.Exception:
|
||||
found = true
|
||||
break
|
||||
if not found:
|
||||
Database.db.delete_rows("GPs", "ID=%s" % e.ID)
|
||||
Database.db.delete_rows("GPs", "ID=%s" % res.ID)
|
||||
undo_redo.clear_history()
|
||||
|
||||
|
||||
@@ -86,16 +87,16 @@ func _on_grapheme_gui_input(event: InputEvent) -> void:
|
||||
|
||||
|
||||
func _reorder_by(property_name: String) -> void:
|
||||
var c: = elements_container.get_children()
|
||||
c.sort_custom(sorting_function.bind(property_name))
|
||||
for e in elements_container.get_children():
|
||||
elements_container.remove_child(e)
|
||||
for e in c:
|
||||
elements_container.add_child(e)
|
||||
var child: = elements_container.get_children()
|
||||
child.sort_custom(sorting_function.bind(property_name))
|
||||
for element in elements_container.get_children():
|
||||
elements_container.remove_child(element)
|
||||
for element in child:
|
||||
elements_container.add_child(element)
|
||||
|
||||
|
||||
func sorting_function(a, b, property_name) -> bool:
|
||||
return a.get(property_name) < b.get(property_name)
|
||||
func sorting_function(a_node, b_node, property_name) -> bool:
|
||||
return a_node.get(property_name) < b_node.get(property_name)
|
||||
|
||||
|
||||
func _on_type_gui_input(event: InputEvent) -> void:
|
||||
@@ -126,8 +127,8 @@ func _on_list_title_save_pressed() -> void:
|
||||
|
||||
|
||||
func _on_list_title_import_path_selected(path: String, match_to_file: bool) -> void:
|
||||
var file: = FileAccess.open(path, FileAccess.READ)
|
||||
var line: = file.get_csv_line()
|
||||
var file: FileAccess = FileAccess.open(path, FileAccess.READ)
|
||||
var line: PackedStringArray = file.get_csv_line()
|
||||
if line.size() < 4 or line[0] != "Grapheme" or line[1] != "Phoneme" or line[2] != "Type" or line[3] != "Exception":
|
||||
error_label.text = "Column names should be Grapheme, Phoneme, Type, Exception"
|
||||
return
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Control
|
||||
|
||||
const LESSON_EXERCICE_CONTAINER_SCENE: = preload("res://sources/language_tool/lesson_exercises_container.tscn")
|
||||
const LESSON_EXERCICE_CONTAINER_SCENE: PackedScene = preload("res://sources/language_tool/lesson_exercises_container.tscn")
|
||||
|
||||
@onready var lessons_container: VBoxContainer = %LessonsContainer
|
||||
|
||||
@@ -11,7 +11,7 @@ func _ready() -> void:
|
||||
if Database.db.query_result[0].nb != Minigame.Type.size():
|
||||
Database.db.query("DROP TABLE ExerciseTypes")
|
||||
|
||||
var query: = "SELECT name FROM sqlite_master WHERE type='table' AND name='ExerciseTypes'"
|
||||
var query: String = "SELECT name FROM sqlite_master WHERE type='table' AND name='ExerciseTypes'"
|
||||
Database.db.query(query)
|
||||
if Database.db.query_result.is_empty():
|
||||
Database.db.query("CREATE TABLE ExerciseTypes (ID INTEGER PRIMARY KEY ASC AUTOINCREMENT UNIQUE NOT NULL, Type TEXT NOT NULL)")
|
||||
@@ -39,13 +39,13 @@ func _ready() -> void:
|
||||
FOREIGN KEY('LessonID') REFERENCES 'Lessons'('ID') ON UPDATE CASCADE ON DELETE CASCADE
|
||||
)")
|
||||
|
||||
var sentences_by_lesson: = Database.get_sentences_by_lessons()
|
||||
var sentences_by_lesson: Dictionary = Database.get_sentences_by_lessons()
|
||||
Database.db.query("Select * FROM Lessons")
|
||||
for e in Database.db.query_result:
|
||||
for result: Dictionary in Database.db.query_result:
|
||||
var container: LessonExerciceContainer = LESSON_EXERCICE_CONTAINER_SCENE.instantiate()
|
||||
lessons_container.add_child(container)
|
||||
container.sentences_by_lesson = sentences_by_lesson
|
||||
container.lesson_number = e.LessonNb
|
||||
container.lesson_number = result.LessonNb
|
||||
container._on_save_button_pressed()
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#TODO CLEAN WARNINGS
|
||||
extends Control
|
||||
|
||||
@onready var lessons_container: VBoxContainer = $%LessonsContainer
|
||||
@@ -43,8 +44,8 @@ func _on_plus_button_pressed() -> void:
|
||||
lessons_container.add_child(lesson_container)
|
||||
lesson_container.lesson_dropped.connect(_on_lesson_dropped)
|
||||
var max_nb: int = -1
|
||||
for e in lessons.values():
|
||||
max_nb = max(max_nb, e.number)
|
||||
for element in lessons.values():
|
||||
max_nb = max(max_nb, element.number)
|
||||
lesson_container.number = max_nb + 1
|
||||
lessons[max_nb + 1] = lesson_container
|
||||
|
||||
|
||||
@@ -110,19 +110,19 @@ func _on_export_filename_selected(filename: String) -> void:
|
||||
summary_file.store_line("Lesson %s --------------------" % lesson)
|
||||
summary_file.store_line("\t \t Words ---")
|
||||
var words: String = ""
|
||||
for e: Dictionary in Database.get_words_for_lesson(lesson, true):
|
||||
words += e.Word + ", "
|
||||
for element: Dictionary in Database.get_words_for_lesson(lesson, true):
|
||||
words += element.Word + ", "
|
||||
summary_file.store_line(words.trim_suffix(", "))
|
||||
summary_file.store_line("\n")
|
||||
summary_file.store_line("\t \t Syllables ---")
|
||||
var syllables: String = ""
|
||||
for e: Dictionary in Database.get_syllables_for_lesson(lesson, true):
|
||||
syllables += e.Grapheme + ", "
|
||||
for element: Dictionary in Database.get_syllables_for_lesson(lesson, true):
|
||||
syllables += element.Grapheme + ", "
|
||||
summary_file.store_line(syllables.trim_suffix(", "))
|
||||
summary_file.store_line("\n")
|
||||
summary_file.store_line("\t \t Sentences ---")
|
||||
for e: Dictionary in Database.get_sentences(lesson, true, sentences_by_lesson):
|
||||
summary_file.store_line(e.Sentence as String)
|
||||
for element: Dictionary in Database.get_sentences(lesson, true, sentences_by_lesson):
|
||||
summary_file.store_line(element.Sentence as String)
|
||||
summary_file.store_line("\n\n")
|
||||
summary_file.close()
|
||||
|
||||
@@ -497,8 +497,8 @@ func _create_syllable_csv() -> void:
|
||||
var phonemes: PackedStringArray = (element.Phonemes as String).split(" ")
|
||||
for index: int in graphemes.size() - 1:
|
||||
gpmatch += graphemes[index] + "-" + phonemes[index] + "."
|
||||
var i: int = graphemes.size() - 1
|
||||
gpmatch += graphemes[i] + "-" + phonemes[i] + ")"
|
||||
var last_index: int = graphemes.size() - 1
|
||||
gpmatch += graphemes[last_index] + "-" + phonemes[last_index] + ")"
|
||||
var lesson: int = -1
|
||||
@warning_ignore("unsafe_method_access")
|
||||
for gp_id: String in element.GPIDs.split(' '):
|
||||
@@ -732,8 +732,8 @@ func read_csv_record(file: FileAccess) -> String:
|
||||
record += line
|
||||
|
||||
var quote_count: int = 0
|
||||
for c: String in line:
|
||||
if c == "\"":
|
||||
for char: String in line:
|
||||
if char == "\"":
|
||||
quote_count += 1
|
||||
|
||||
open_quotes = (quote_count % 2 != 0)
|
||||
|
||||
@@ -121,29 +121,38 @@ func _on_place_point_button_pressed() -> void:
|
||||
|
||||
|
||||
func _on_add_segment_button_pressed() -> void:
|
||||
var segment_build: SegmentBuild = SEGMENT_BUILD_SCENE.instantiate()
|
||||
segments_container.add_child(segment_build)
|
||||
|
||||
segment_build.modify.connect(_on_segment_modify.bind(segment_build))
|
||||
segment_build.delete.connect(_on_segment_delete.bind(segment_build))
|
||||
|
||||
current_segment = segment_build
|
||||
|
||||
var line: Line2D = Line2D.new()
|
||||
line.width = 25
|
||||
line.begin_cap_mode = Line2D.LINE_CAP_ROUND
|
||||
line.end_cap_mode = Line2D.LINE_CAP_ROUND
|
||||
line.joint_mode = Line2D.LINE_JOINT_ROUND
|
||||
lines.add_child(line)
|
||||
|
||||
var i: int = segments_container.get_child_count()
|
||||
var r: float = float(i % points_per_gradient) / float(points_per_gradient)
|
||||
var color: Color = gradient.sample(r)
|
||||
segment_build.set_color(color)
|
||||
line.default_color = color
|
||||
|
||||
# Create a new segment build instance from the scene
|
||||
var new_segment: SegmentBuild = SEGMENT_BUILD_SCENE.instantiate()
|
||||
segments_container.add_child(new_segment)
|
||||
|
||||
# Connect signals for modifying and deleting the segment
|
||||
new_segment.modify.connect(_on_segment_modify.bind(new_segment))
|
||||
new_segment.delete.connect(_on_segment_delete.bind(new_segment))
|
||||
|
||||
# Store the new segment as the currently selected one
|
||||
current_segment = new_segment
|
||||
|
||||
# Create a new visual line for the segment
|
||||
var segment_line: Line2D = Line2D.new()
|
||||
segment_line.width = 25
|
||||
segment_line.begin_cap_mode = Line2D.LINE_CAP_ROUND
|
||||
segment_line.end_cap_mode = Line2D.LINE_CAP_ROUND
|
||||
segment_line.joint_mode = Line2D.LINE_JOINT_ROUND
|
||||
lines.add_child(segment_line)
|
||||
|
||||
# Compute the segment's color based on its position in the container
|
||||
var segment_index: int = segments_container.get_child_count()
|
||||
var gradient_position: float = float(segment_index % points_per_gradient) / float(points_per_gradient)
|
||||
var segment_color: Color = gradient.sample(gradient_position)
|
||||
|
||||
# Apply the color to the segment and its line
|
||||
new_segment.set_color(segment_color)
|
||||
segment_line.default_color = segment_color
|
||||
|
||||
# Sync segment states with any associated UI or logic
|
||||
match_segment_with_buttons()
|
||||
|
||||
|
||||
# Notify that something has changed (e.g., for undo, saving, etc.)
|
||||
changed.emit()
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#TODO CLEAN WARNINGS
|
||||
extends "res://sources/language_tool/word_list.gd"
|
||||
|
||||
var not_found_list: = ""
|
||||
@onready var export_not_found_button: = %ExportNotFoundButton
|
||||
@onready var file_dialog_export: = $FileDialogExport
|
||||
var not_found_list: String = ""
|
||||
@onready var export_not_found_button: Button = %ExportNotFoundButton
|
||||
@onready var file_dialog_export: FileDialog = $FileDialogExport
|
||||
|
||||
|
||||
func create_sub_elements_list() -> void:
|
||||
@@ -15,10 +16,10 @@ func create_sub_elements_list() -> void:
|
||||
INNER JOIN GPs ON GPs.ID = GPsInWords.GPID
|
||||
GROUP BY Words.ID
|
||||
ORDER BY Words.Word")
|
||||
for e in Database.db.query_result:
|
||||
sub_elements_list[e.ID] = {
|
||||
grapheme = e.Word,
|
||||
phoneme = e.Phonemes
|
||||
for result: Dictionary in Database.db.query_result:
|
||||
sub_elements_list[result.ID] = {
|
||||
grapheme = result.Word,
|
||||
phoneme = result.Phonemes
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +28,13 @@ func get_lesson_for_element(id: int) -> int:
|
||||
|
||||
|
||||
func _on_list_title_new_search(new_text: String) -> void:
|
||||
for e in elements_container.get_children():
|
||||
var found: = false
|
||||
for word in e.word.split(" "):
|
||||
for element: SentenceListElement in elements_container.get_children():
|
||||
var found: bool = false
|
||||
for word: String in element.word.split(" "):
|
||||
if word.begins_with(new_text):
|
||||
found = true
|
||||
break
|
||||
e.visible = found
|
||||
element.visible = found
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -42,11 +43,11 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func connect_not_found() -> void:
|
||||
for element in elements_container.get_children():
|
||||
for element: SentenceListElement in elements_container.get_children():
|
||||
if not element.not_found.is_connected(_on_not_found):
|
||||
element.not_found.connect(_on_not_found)
|
||||
if not _element.not_found.is_connected(_on_not_found_csv):
|
||||
_element.not_found.connect(_on_not_found_csv)
|
||||
if _element is SentenceListElement and not (_element as SentenceListElement).not_found.is_connected(_on_not_found_csv):
|
||||
(_element as SentenceListElement).not_found.connect(_on_not_found_csv)
|
||||
|
||||
|
||||
func _on_plus_button_pressed() -> void:
|
||||
@@ -92,7 +93,7 @@ func _on_list_title_import_path_selected(path: String, match_to_file: bool) -> v
|
||||
var query: String = "Select * FROM Sentences"
|
||||
Database.db.query(query)
|
||||
var result: Array[Dictionary] = Database.db.query_result
|
||||
for element in result:
|
||||
for element: Dictionary in result:
|
||||
if not element.Sentence in all_data:
|
||||
Database.db.delete_rows("Sentences", "ID=%s" % element.ID)
|
||||
inserted_one = true
|
||||
@@ -107,8 +108,8 @@ func _on_export_not_found_button_pressed() -> void:
|
||||
file_dialog_export.filters = []
|
||||
file_dialog_export.add_filter("*.txt", "txt")
|
||||
|
||||
for connection in file_dialog_export.file_selected.get_connections():
|
||||
connection["signal"].disconnect(connection["callable"])
|
||||
for connection: Dictionary in file_dialog_export.file_selected.get_connections():
|
||||
(connection["signal"] as Signal).disconnect(connection["callable"] as Callable)
|
||||
|
||||
file_dialog_export.file_selected.connect(_on_export_filename_selected)
|
||||
|
||||
@@ -116,6 +117,6 @@ func _on_export_not_found_button_pressed() -> void:
|
||||
|
||||
|
||||
func _on_export_filename_selected(path: String) -> void:
|
||||
var file: = FileAccess.open(path, FileAccess.WRITE)
|
||||
var file: FileAccess = FileAccess.open(path, FileAccess.WRITE)
|
||||
file.store_string(not_found_list)
|
||||
file.close()
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dbmcpgfokf0in"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dbmcpgfokf0in"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dfw7m0a7148fu" path="res://sources/language_tool/word_list.tscn" id="1_bfjhw"]
|
||||
[ext_resource type="PackedScene" uid="uid://cy14lm72cd7cy" path="res://sources/language_tool/sentence_list_element.tscn" id="2_4jv4m"]
|
||||
[ext_resource type="Script" uid="uid://7pymixi5vsat" path="res://sources/language_tool/sentence_list.gd" id="2_q3ll5"]
|
||||
[ext_resource type="PackedScene" uid="uid://dx33ijlgd8m3w" path="res://sources/language_tool/word_list_element.tscn" id="3_jl0ks"]
|
||||
|
||||
[node name="SentenceList" instance=ExtResource("1_bfjhw")]
|
||||
script = ExtResource("2_q3ll5")
|
||||
element_scene = ExtResource("2_4jv4m")
|
||||
|
||||
[node name="ExportNotFoundButton" type="Button" parent="VBoxContainer" index="5"]
|
||||
unique_name_in_owner = true
|
||||
@@ -49,7 +47,7 @@ text = "Word"
|
||||
[node name="Graphemes" parent="NewGPLayer/VBoxContainer2/Title/TabContainer/NormalContainer" index="3"]
|
||||
text = "Graphemes"
|
||||
|
||||
[node name="EditButton" parent="NewGPLayer/VBoxContainer2/Title/TabContainer/NormalContainer" index="4"]
|
||||
[node name="EditButton" parent="NewGPLayer/VBoxContainer2/Title/TabContainer/NormalContainer" index="6"]
|
||||
modulate = Color(1, 1, 1, 0)
|
||||
|
||||
[node name="NewGP" parent="NewGPLayer/VBoxContainer2" index="1" instance=ExtResource("3_jl0ks")]
|
||||
@@ -60,7 +58,6 @@ layout_mode = 2
|
||||
initial_position = 2
|
||||
size = Vector2i(1500, 1000)
|
||||
popup_window = true
|
||||
ok_button_text = "Enregistrer"
|
||||
access = 2
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/ExportNotFoundButton" to="." method="_on_export_not_found_button_pressed"]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends WordListElement
|
||||
class_name SentenceListElement
|
||||
|
||||
signal not_found(text: String)
|
||||
|
||||
@@ -12,15 +13,26 @@ func _ready() -> void:
|
||||
graphemes_label.hide()
|
||||
|
||||
|
||||
|
||||
|
||||
func update_lesson() -> void:
|
||||
var m: int = -1
|
||||
for gp_id: int in gp_ids:
|
||||
var i: int = Database.get_min_lesson_for_word_id(gp_id)
|
||||
if i < 0:
|
||||
m = -1
|
||||
var highest_min_lesson: int = -1
|
||||
|
||||
# Iterate over each word ID (gp_id)
|
||||
for word_id: int in gp_ids:
|
||||
# Get the minimum lesson in which this word appears
|
||||
var min_lesson_for_word: int = Database.get_min_lesson_for_word_id(word_id)
|
||||
|
||||
# If word not found in any lesson, invalidate the result and stop
|
||||
if min_lesson_for_word < 0:
|
||||
highest_min_lesson = -1
|
||||
break
|
||||
m = maxi(m, i)
|
||||
lesson = m
|
||||
|
||||
# Keep track of the highest minimum lesson required
|
||||
highest_min_lesson = max(highest_min_lesson, min_lesson_for_word)
|
||||
|
||||
# Update the global lesson value
|
||||
lesson = highest_min_lesson
|
||||
|
||||
|
||||
func _add_from_additional_word_list(new_text: String) -> int:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#TODO CLEAN WARNINGS
|
||||
extends Control
|
||||
|
||||
@export var gradient: Gradient
|
||||
@@ -66,8 +67,8 @@ func _load_segments(segment_container: SegmentContainer, path: String) -> void:
|
||||
if element == "":
|
||||
break
|
||||
|
||||
var s: PackedStringArray = element.split(" ")
|
||||
points.append(Vector2(float(s[0]), float(s[1])))
|
||||
var point: PackedStringArray = element.split(" ")
|
||||
points.append(Vector2(float(point[0]), float(point[1])))
|
||||
if not points.is_empty():
|
||||
segment_container.load_segment(points)
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
extends Control
|
||||
class_name WordList
|
||||
|
||||
@export var element_scene: PackedScene = preload("res://sources/language_tool/word_list_element.tscn")
|
||||
|
||||
|
||||
@@ -195,14 +195,14 @@ func _on_validate_button_pressed() -> void:
|
||||
|
||||
|
||||
func update_lesson() -> void:
|
||||
var m: int = -1
|
||||
var index: int = -1
|
||||
for gp_id: int in gp_ids:
|
||||
var i: int = Database.get_min_lesson_for_gp_id(gp_id)
|
||||
if i < 0:
|
||||
m = -1
|
||||
var min_index: int = Database.get_min_lesson_for_gp_id(gp_id)
|
||||
if min_index < 0:
|
||||
index = -1
|
||||
break
|
||||
m = maxi(m, i)
|
||||
lesson = m
|
||||
index = maxi(index, min_index)
|
||||
lesson = index
|
||||
|
||||
|
||||
func gp_ids_from_string(p_gp_ids: String) -> Array[int]:
|
||||
|
||||
Reference in New Issue
Block a user