Adds evolutive difficulties for the students.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,51 @@
|
||||
extends Resource
|
||||
class_name UserDifficulty
|
||||
|
||||
signal difficulty_changed()
|
||||
|
||||
const min_difficulty: = 0
|
||||
const max_difficulty: = 4
|
||||
const consecutive_wins_to_promote: = 2
|
||||
const consecutive_losses_to_demote: = 2
|
||||
|
||||
class UserMinigameHistory:
|
||||
var difficulty: int = 0
|
||||
var consecutives_losses: int = 0
|
||||
var consecutives_wins: int = 0
|
||||
var history : Array[bool] = []
|
||||
|
||||
func add_game(is_won: bool) -> void:
|
||||
history.append(is_won)
|
||||
|
||||
if is_won:
|
||||
consecutives_losses = 0
|
||||
consecutives_wins += 1
|
||||
if consecutives_wins >= consecutive_wins_to_promote:
|
||||
consecutives_wins = 0
|
||||
if difficulty != max_difficulty:
|
||||
difficulty += 1
|
||||
else:
|
||||
consecutives_wins = 0
|
||||
consecutives_losses += 1
|
||||
if consecutives_losses <= consecutive_losses_to_demote:
|
||||
consecutives_losses = 0
|
||||
if difficulty != min_difficulty:
|
||||
difficulty -= 1
|
||||
|
||||
|
||||
# Stores the user difficulty for all the minigames
|
||||
@export
|
||||
var minigames_histories: Dictionary = {}
|
||||
|
||||
|
||||
# Gets the difficulty of the user for the given minigame
|
||||
func get_difficulty(minigame_name: String) -> int:
|
||||
return minigames_histories.get(minigame_name, UserMinigameHistory.new()).difficulty
|
||||
|
||||
|
||||
# Adds a game to the minigame history of the user and update difficulty if needed
|
||||
func add_game(minigame_name: String, minigame_won: bool) -> void:
|
||||
var history : UserMinigameHistory = minigames_histories.get(minigame_name, UserMinigameHistory.new())
|
||||
history.add_game(minigame_won)
|
||||
minigames_histories[minigame_name] = history
|
||||
difficulty_changed.emit()
|
||||
@@ -12,7 +12,8 @@ const remediation_score: int = -2
|
||||
# Defines the score for each GP for the syllables and words minigames
|
||||
# Key is the ID of the GP
|
||||
# Value is the score of the GP
|
||||
var gps_scores: Dictionary = { 2: -2}
|
||||
@export
|
||||
var gps_scores: Dictionary = {}
|
||||
|
||||
|
||||
# Gets the score of a GP if it is below or equals to the remediation score
|
||||
|
||||
@@ -101,6 +101,9 @@ func _ready() -> void:
|
||||
lesson_nb = transition_data.get("current_lesson_number", lesson_nb)
|
||||
transition_data = {}
|
||||
|
||||
# Difficulty
|
||||
difficulty = UserDataManager.get_difficulty_for_minigame(minigame_name)
|
||||
|
||||
intro_kalulu_speech = Database.load_external_sound(Database.get_kalulu_speech_path(minigame_name, "intro"))
|
||||
help_kalulu_speech = Database.load_external_sound(Database.get_kalulu_speech_path(minigame_name, "help"))
|
||||
win_kalulu_speech = Database.load_external_sound(Database.get_kalulu_speech_path(minigame_name, "win"))
|
||||
@@ -169,9 +172,13 @@ func _win() -> void:
|
||||
if UserDataManager.student_progression:
|
||||
UserDataManager.student_progression.game_completed(lesson_nb, minigame_number)
|
||||
|
||||
# Remediation
|
||||
if scores:
|
||||
UserDataManager.update_remediation_scores(scores)
|
||||
|
||||
# Difficulty
|
||||
UserDataManager.update_difficulty_for_minigame(minigame_name, true)
|
||||
|
||||
audio_player.stream = win_sound_fx
|
||||
audio_player.play()
|
||||
|
||||
@@ -185,9 +192,13 @@ func _win() -> void:
|
||||
|
||||
|
||||
func _lose() -> void:
|
||||
# Remediation
|
||||
if scores:
|
||||
UserDataManager.update_remediation_scores(scores)
|
||||
|
||||
# Difficulty
|
||||
UserDataManager.update_difficulty_for_minigame(minigame_name, false)
|
||||
|
||||
audio_player.stream = lose_sound_fx
|
||||
audio_player.play()
|
||||
await audio_player.finished
|
||||
@@ -197,7 +208,6 @@ func _lose() -> void:
|
||||
|
||||
_reset()
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logs
|
||||
|
||||
@@ -14,12 +14,14 @@ var student: String = "" :
|
||||
_load_student_settings()
|
||||
_load_student_progression()
|
||||
_load_student_remediation()
|
||||
_load_student_difficulty()
|
||||
|
||||
var _device_settings: DeviceSettings
|
||||
var teacher_settings: TeacherSettings
|
||||
var student_settings: UserSettings
|
||||
var student_progression: UserProgression
|
||||
var _student_remediation: UserRemediation
|
||||
var _student_difficulty: UserDifficulty
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -309,11 +311,45 @@ func get_GP_remediation_score(GPID: int) -> int:
|
||||
func update_remediation_scores(scores: Dictionary) -> void:
|
||||
if not _student_remediation:
|
||||
push_warning("No student remediation data for " + str(student))
|
||||
return
|
||||
if scores:
|
||||
_student_remediation.update_scores(scores)
|
||||
|
||||
#endregion
|
||||
|
||||
#region Student Difficulty
|
||||
|
||||
func _get_student_difficulty_path() -> String:
|
||||
return get_student_folder().path_join("difficulty.tres")
|
||||
|
||||
func _load_student_difficulty() -> void:
|
||||
if FileAccess.file_exists(_get_student_difficulty_path()):
|
||||
_student_difficulty = load(_get_student_difficulty_path())
|
||||
|
||||
if not _student_difficulty:
|
||||
_student_difficulty = UserDifficulty.new()
|
||||
DirAccess.make_dir_recursive_absolute(get_student_folder())
|
||||
_save_student_difficulty()
|
||||
|
||||
_student_difficulty.difficulty_changed.connect(_save_student_difficulty)
|
||||
|
||||
func _save_student_difficulty() -> void:
|
||||
ResourceSaver.save(_student_difficulty, _get_student_difficulty_path())
|
||||
|
||||
func get_difficulty_for_minigame(minigame_name: String) -> int:
|
||||
if not _student_difficulty:
|
||||
push_warning("No student difficulty data for " + str(student))
|
||||
return 0
|
||||
return _student_difficulty.get_difficulty(minigame_name)
|
||||
|
||||
func update_difficulty_for_minigame(minigame_name: String, minigame_won: bool) -> void:
|
||||
if not _student_difficulty:
|
||||
push_warning("No student difficulty data for " + str(student))
|
||||
return
|
||||
_student_difficulty.add_game(minigame_name, minigame_won)
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sound settings
|
||||
|
||||
func set_master_volume(value: float) -> void:
|
||||
|
||||
Reference in New Issue
Block a user