forked from GDQuest/learn-gdscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLessonProgress.gd
93 lines (70 loc) · 2.43 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class_name LessonProgress
extends Resource
# Lesson resource identifier.
export var lesson_id := ""
# Identifiers of reached content blocks.
export var completed_blocks := [] # Array of String
# 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_blocks = []
completed_quizzes = []
completed_practices = []
func get_completed_blocks_count(blocks: 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_blocks := []
for block_data in blocks:
if block_data is Quiz:
available_blocks.append(block_data.quiz_id)
else:
available_blocks.append(block_data.content_id)
for block_id in completed_blocks:
var matched_id := ""
for block_path in available_blocks:
if block_path == block_id:
matched_id = block_path
break
if not matched_id.empty():
available_blocks.erase(matched_id)
completed += 1
return completed
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.quiz_id)
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.practice_id)
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