Files
Kalulu/resources/user/student_progression.gd
T
Adrien Ufferte 50f6b4335a Data Synchronization in bulk
+ Allow connecting/playing offline
+ Clean asset name nomenclature
+ Debug asset name nomenclature when loading files
2025-06-05 11:18:22 +02:00

99 lines
2.6 KiB
GDScript

extends Resource
class_name StudentProgression
signal unlocks_changed()
enum Status{
Locked,
Unlocked,
Completed,
}
@export var version: float = 1.0
@export var unlocks: Dictionary = {}
func _init() -> void:
init_unlocks()
# Make sure the unlocks are correct
func init_unlocks() -> bool:
var has_changes: bool = false
if not unlocks:
unlocks = {}
# Verifiy the lessons
var number_of_lessons: int = Database.get_lessons_count()
if unlocks.size() != number_of_lessons:
for index: int in number_of_lessons:
if not unlocks.has(index+1):
unlocks[index + 1] = {
"look_and_learn": Status.Locked,
"games": [
Status.Locked,
Status.Locked,
Status.Locked,
]
}
while unlocks.size() > number_of_lessons:
unlocks.erase(unlocks.size())
has_changes = true
# Make sure that the first garden is always accessible
if unlocks[1]["look_and_learn"] == Status.Locked:
unlocks[1]["look_and_learn"] = Status.Unlocked
has_changes = true
return has_changes
func get_max_unlocked_lesson() -> int:
var max_unlocked_level: int = 1
for index: int in range(unlocks.size()):
if unlocks[index + 1]["look_and_learn"] >= Status.Unlocked:
max_unlocked_level = index
else:
break
return max_unlocked_level
func is_lesson_completed(lesson_number: int) -> bool:
return unlocks[lesson_number]["look_and_learn"] == Status.Completed and unlocks[lesson_number]["games"][0] == Status.Completed and unlocks[lesson_number]["games"][1] == Status.Completed and unlocks[lesson_number]["games"][2] == Status.Completed
# Return true if the progression is saved or false if the look and learn was already completed
func look_and_learn_completed(lesson_number: int) -> bool:
if unlocks[lesson_number]["look_and_learn"] == Status.Completed:
return false
unlocks[lesson_number]["look_and_learn"] = Status.Completed
for index: int in range(3):
unlocks[lesson_number]["games"][index] = Status.Unlocked
unlocks_changed.emit()
return true
# Return true if the progression is saved or false if the game was already completed
func game_completed(lesson_number: int, game_number: int) -> bool:
# If the game is already completed, do nothing
if unlocks[lesson_number]["games"][game_number] == Status.Completed:
return false
unlocks[lesson_number]["games"][game_number] = Status.Completed
var all_completed: bool = true
for index: int in range(3):
all_completed = all_completed and unlocks[lesson_number]["games"][index] == Status.Completed
if all_completed and unlocks.has(lesson_number + 1):
unlocks[lesson_number + 1]["look_and_learn"] = Status.Unlocked
unlocks_changed.emit()
return true