Adds DB requests for sentences with silent GPs and GPs in sentences.

This commit is contained in:
Dylan Sarrazyn
2024-06-17 13:01:19 +02:00
parent 048a7ddcde
commit 000f5769e3
6 changed files with 163 additions and 100 deletions
File diff suppressed because one or more lines are too long
@@ -0,0 +1,13 @@
extends Label
signal pressed(pos: Vector2)
var gp: Dictionary
func _ready() -> void:
if gp:
text = gp.Grapheme
func _on_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("left_click"):
pressed.emit(get_global_mouse_position())
@@ -0,0 +1,18 @@
[gd_scene load_steps=4 format=3 uid="uid://hnhiv6odqvnk"]
[ext_resource type="FontFile" uid="uid://c7hsjkvr1pbud" path="res://assets/fonts/ScriptEcoleNormal.otf" id="1_1xclp"]
[ext_resource type="Script" path="res://sources/minigames/penguin/penguin_label.gd" id="2_eu3c0"]
[sub_resource type="LabelSettings" id="LabelSettings_yg4cf"]
font = ExtResource("1_1xclp")
font_size = 200
outline_size = 50
outline_color = Color(0, 0, 0, 1)
[node name="PenguinLabel" type="Label"]
mouse_filter = 0
text = "test"
label_settings = SubResource("LabelSettings_yg4cf")
script = ExtResource("2_eu3c0")
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
+58 -53
View File
@@ -2,76 +2,80 @@ extends Minigame
# Namespace
const Penguin: = preload("res://sources/minigames/penguin/penguin.gd")
const PenguinLabel: = preload("res://sources/minigames/penguin/penguin_label.gd")
const penguin_scene: PackedScene = preload("res://sources/minigames/penguin/penguin.tscn")
const label_scene: PackedScene = preload("res://sources/minigames/penguin/penguin_label.tscn")
const silent_phoneme: = "#"
@onready var main_penguin: Penguin = $GameRoot/Penguin
@onready var labels_container: HBoxContainer = $GameRoot/Control/LabelsContainer
@onready var penguins_positions: Control = $GameRoot/PenguinsPositions
var current_word_progression: int = 0: set = _set_current_word_progression
var max_word_progression: int = 0
var penguins: Array[Penguin] = []
var labels: Array[Label] = []
# Find words with silent GPs
func _find_stimuli_and_distractions() -> void:
var words_list: Array[Dictionary] = Database.get_words_with_silent_gp_for_lesson(lesson_nb)
var sentences_list: Array = Database.get_sentences_for_lesson_with_silent_GPs(lesson_nb)
if words_list.is_empty():
if sentences_list.is_empty():
return
var current_lesson_words: = []
var previous_lesson_words: = []
var current_lesson_sentences: = []
var previous_lesson_sentences: = []
for word: Dictionary in words_list:
if word.LessonNb == lesson_nb:
current_lesson_words.append(word)
for sentence: Dictionary in sentences_list:
if sentence.LessonNb == lesson_nb:
current_lesson_sentences.append(sentence)
else:
previous_lesson_words.append(word)
previous_lesson_sentences.append(sentence)
# Shuffle everything
current_lesson_words.shuffle()
previous_lesson_words.shuffle()
current_lesson_sentences.shuffle()
previous_lesson_sentences.shuffle()
# If there is no previous stimuli, only adds from current lesson
if previous_lesson_words.is_empty():
if previous_lesson_sentences.is_empty():
while stimuli.size() < max_progression:
stimuli.append(current_lesson_words.pick_random())
stimuli.append(current_lesson_sentences.pick_random())
else:
if not current_lesson_words.is_empty():
if not current_lesson_sentences.is_empty():
# If there are more stimuli in current lesson than needed
if current_lesson_words.size() >= current_lesson_stimuli_number:
if current_lesson_sentences.size() >= current_lesson_stimuli_number:
for i in current_lesson_stimuli_number:
stimuli.append(current_lesson_words[i])
stimuli.append(current_lesson_sentences[i])
else:
stimuli.append_array(current_lesson_words)
stimuli.append_array(current_lesson_sentences)
# If there are not enough stimuli from current lesson, we want at least half the target number of stimuli
var minimal_stimuli : int = floori(current_lesson_stimuli_number/2.0)
if stimuli.size() < minimal_stimuli:
while stimuli.size() < minimal_stimuli:
stimuli.append(current_lesson_words.pick_random())
stimuli.append(current_lesson_sentences.pick_random())
# Gets other stimuli from previous errors or lessons
var spaces_left : int = max_progression - stimuli.size()
if previous_lesson_words.size() >= spaces_left:
if previous_lesson_sentences.size() >= spaces_left:
for i in spaces_left:
stimuli.append(previous_lesson_words[i])
stimuli.append(previous_lesson_sentences[i])
else:
stimuli.append_array(previous_lesson_words)
stimuli.append_array(previous_lesson_sentences)
# If there are not enough stimuli, fill the rest with current lesson
if current_lesson_words:
if current_lesson_sentences:
while stimuli.size() < max_progression:
stimuli.append(current_lesson_words.pick_random())
stimuli.append(current_lesson_sentences.pick_random())
# Shuffle the stimuli
stimuli.shuffle()
print(stimuli)
# Find the GPs and distractors for each word
for stimulus: Dictionary in stimuli:
stimulus.GPs = Database.get_GP_from_word(stimulus.ID as int)
for sentence: Dictionary in stimuli:
sentence.GPs = Database.get_GPs_from_sentence(sentence.ID as int)
# Launch the minigame
@@ -87,23 +91,22 @@ func _setup_word_progression() -> void:
max_word_progression = 0
# Make penguins go away TODO Animations
for penguin: Penguin in penguins:
penguin.queue_free()
penguins.clear()
for label: PenguinLabel in labels:
label.queue_free()
labels.clear()
var stimulus: = _get_current_stimulus()
var i: = 1
for GP: Dictionary in stimulus.GPs:
# Instantiate a new penguin TODO Animations
var penguin: Penguin = penguin_scene.instantiate()
penguins_positions.get_node("Pos" + str(i)).add_child(penguin)
penguin.gp = GP
penguin.pressed.connect(_on_snowball_thrown.bind(penguin))
var label: PenguinLabel = label_scene.instantiate()
label.gp = GP
penguins.append(penguin)
labels_container.add_child(label)
i += 1
label.pressed.connect(_on_snowball_thrown.bind(label))
labels.append(label)
if GP.Phoneme == silent_phoneme:
max_word_progression += 1
@@ -111,14 +114,16 @@ func _setup_word_progression() -> void:
func _highlight() -> void:
for penguin: Penguin in penguins:
if self._is_silent(penguin.gp) and not penguin.is_pressed:
penguin.highlight()
pass
#for penguin: Penguin in penguins:
# if self._is_silent(penguin.gp) and not penguin.is_pressed:
# penguin.highlight()
func _stop_highlight() -> void:
for penguin: Penguin in penguins:
penguin.highlight(false)
pass
#for penguin: Penguin in penguins:
# penguin.highlight(false)
# Get the current stimulus which needs to be found to increase progression
@@ -139,31 +144,31 @@ func _set_current_word_progression(p_current_word_progression: int) -> void:
#region Connections
func _on_snowball_thrown(pos: Vector2, penguin: Penguin) -> void:
# Disables all penguins
for p: Penguin in penguins:
p.set_button_enabled(false)
func _on_snowball_thrown(pos: Vector2, label: PenguinLabel) -> void:
# Disables all penguins TODO
#for p: Penguin in penguins:
# p.set_button_enabled(false)
# Throw the snowball
await main_penguin.throw(pos)
# Checks if the GP pressed is silent
if _is_silent(penguin.gp):
if _is_silent(label.gp):
main_penguin.happy()
penguin.happy()
await penguin.right()
#penguin.happy()
#await penguin.right()
current_word_progression += 1
else:
main_penguin.sad()
penguin.sad()
await penguin.wrong()
#penguin.sad()
#await penguin.wrong()
current_lives -= 1
# Re-enables all penguins
for p: Penguin in penguins:
p.set_button_enabled(true)
# Re-enables all penguins TODO
#for p: Penguin in penguins:
# p.set_button_enabled(true)
main_penguin.idle()
+23 -34
View File
@@ -36,38 +36,27 @@ texture = ExtResource("4_e3y2j")
[node name="Penguin" parent="GameRoot" index="1" instance=ExtResource("4_txvyj")]
position = Vector2(702, 1694)
[node name="PenguinsPositions" type="Control" parent="GameRoot" index="2"]
anchors_preset = 0
offset_left = 320.0
offset_right = 360.0
offset_bottom = 40.0
[node name="Control" type="Control" parent="GameRoot" index="2"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 325.0
offset_right = -264.0
offset_bottom = -680.0
grow_horizontal = 2
grow_vertical = 2
[node name="Pos6" type="Marker2D" parent="GameRoot/PenguinsPositions" index="0"]
position = Vector2(1600, 788)
[node name="Pos5" type="Marker2D" parent="GameRoot/PenguinsPositions" index="1"]
position = Vector2(1400, 788)
[node name="Pos4" type="Marker2D" parent="GameRoot/PenguinsPositions" index="2"]
position = Vector2(1200, 788)
[node name="Pos3" type="Marker2D" parent="GameRoot/PenguinsPositions" index="3"]
position = Vector2(1000, 788)
[node name="Pos2" type="Marker2D" parent="GameRoot/PenguinsPositions" index="4"]
position = Vector2(800, 788)
[node name="Pos1" type="Marker2D" parent="GameRoot/PenguinsPositions" index="5"]
position = Vector2(600, 788)
[node name="Label" type="Label" parent="GameRoot" index="3"]
layout_mode = 0
offset_left = 757.0
offset_top = 217.0
offset_right = 2113.0
offset_bottom = 780.0
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 90
text = "TEST"
horizontal_alignment = 1
vertical_alignment = 1
[node name="LabelsContainer" type="HBoxContainer" parent="GameRoot/Control" index="0"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -314.0
offset_top = -305.0
offset_right = 314.0
offset_bottom = 305.0
grow_horizontal = 2
grow_vertical = 2
+39 -1
View File
@@ -155,6 +155,16 @@ func get_GP_from_word(ID: int) -> Array:
return db.query_result
func get_GPs_from_sentence(sentenceID: int) -> Array:
db.query_with_bindings("SELECT GPs.ID, GPs.Grapheme, GPs.Phoneme, GPs.Type, GPsInWords.WordID, GPsInWords.Position AS GPPosition, WordsInSentences.Position AS WordPosition FROM GPs
INNER JOIN GPsInWords ON GPsInWords.GPID = GPs.ID
INNER JOIN WordsInSentences ON WordsInSentences.WordID = GPsInWords.WordID
INNER JOIN Sentences ON Sentences.ID = WordsInSentences.SentenceID
WHERE Sentences.ID = ?
ORDER BY WordPosition ASC, GPPosition ASC", [sentenceID])
return db.query_result
func get_words_containing_grapheme(grapheme: String) -> Array:
db.query_with_bindings("SELECT Word FROM Words INNER JOIN GPsInWords INNER JOIN GPs on Words.ID = GPsInWords.WordID AND GPs.Grapheme=? AND GPS.ID = GPsInWords.GPID", [grapheme])
return db.query_result
@@ -291,7 +301,35 @@ func get_sentences_for_lesson(p_lesson_nb: int, only_new: = false, sentences_by_
return ret
func get_sentences_for_lesson_with_silent_GPs(lesson_nb: int, min_length: int = 2, max_length:int = 5) -> Array[Dictionary]:
var query: = "SELECT Sentences.*, VerifiedCount.MaxLessonNb AS LessonNb FROM Sentences
INNER JOIN
(SELECT SentenceID, count() as WordsCount FROM WordsInSentences
GROUP BY SentenceID
) WordCount ON WordCount.SentenceID = Sentences.ID
INNER JOIN
(SELECT SentenceID, count() as Count FROM GPsInWords
INNER JOIN WordsInSentences ON GPsInWords.WordID = WordsInSentences.WordID
INNER JOIN Sentences ON WordsInSentences.SentenceID = Sentences.ID
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPsInWords.GPID
GROUP BY SentenceID
) TotalCount ON TotalCount.SentenceID = Sentences.ID
INNER JOIN
(SELECT SentenceID, count() as Count, max(LessonNb) as MaxLessonNb, group_concat(GPs.Phoneme) as SentencePhoneme FROM GPsInWords
INNER JOIN GPsInLessons ON GPsInLessons.GPID = GPsInWords.GPID
INNER JOIN WordsInSentences ON GPsInWords.WordID = WordsInSentences.WordID
INNER JOIN Sentences ON WordsInSentences.SentenceID = Sentences.ID
INNER JOIN Lessons ON Lessons.ID = GPsInLessons.LessonID AND Lessons.LessonNb <= ?
INNER JOIN GPs ON GPs.ID = GPsInWords.GPID
GROUP BY SentenceID
) VerifiedCount ON VerifiedCount.SentenceID = Sentences.ID AND VerifiedCount.Count = TotalCount.Count
WHERE Sentences.Exception = 0
AND WordsCount >=?
AND WordsCount <=?
AND VerifiedCount.SentencePhoneme LIKE '%#%'"
db.query_with_bindings(query, [lesson_nb, min_length, max_length])
return db.query_result
func get_pseudowords_for_lesson(p_lesson_nb: int) -> Array: