forked from GDQuest/learn-gdscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLessonProgress.gd
63 lines (47 loc) · 1.71 KB
/
LessonProgress.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class_name LessonProgress
extends Resource
# Lesson resource identifier.
export var lesson_id := ""
# Set when the user got to the bottom of the lesson and clicked on any practice.
export var completed_reading := false
# Identifiers of completed quiz resources.
export var completed_quizzes := [] # Array of String
# Identifiers of completed practice resources.
export var completed_practices := [] # Array of String
func _init() -> void:
completed_quizzes = []
completed_practices = []
func get_completed_quizzes_count(quizzes: Array) -> int:
var completed := 0
# We collect them beforehand so that we can clear the list as we go and ensure only
# unique entries are counted.
var available_quizzes := []
for quiz_data in quizzes:
available_quizzes.append(quiz_data.resource_path)
for quiz_id in completed_quizzes:
var matched_id := ""
for quiz_path in available_quizzes:
if quiz_path == String(quiz_id): # Can be an int from old pre-beta versions.
matched_id = quiz_path
break
if not matched_id.empty():
available_quizzes.erase(matched_id)
completed += 1
return completed
func get_completed_practices_count(practices: Array) -> int:
var completed := 0
# We collect them beforehand so that we can clear the list as we go and ensure only
# unique entries are counted.
var available_practices := []
for practice_data in practices:
available_practices.append(practice_data.resource_path)
for practice_id in completed_practices:
var matched_id := ""
for practice_path in available_practices:
if practice_path == practice_id:
matched_id = practice_path
break
if not matched_id.empty():
available_practices.erase(matched_id)
completed += 1
return completed