-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathTestResourcePaths.gd
86 lines (74 loc) · 2.36 KB
/
TestResourcePaths.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
tool
extends EditorScript
const COURSE_RESOURCE_PATH := "res://course/course-learn-gdscript.tres"
const VISUAL_ELEMENT_EXTENSIONS := ["tscn", "png", "jpg", "jpeg", "svg", "gif"]
var _file_tester := File.new()
func _run() -> void:
print("[TEST] Testing all resource paths...")
if not ResourceLoader.exists(COURSE_RESOURCE_PATH):
printerr(
"Course resource at path '%s' does not exist. Aborting test." % [COURSE_RESOURCE_PATH]
)
return
var course = ResourceLoader.load(COURSE_RESOURCE_PATH, "", true)
if not course:
printerr(
"Failed to load the course resource at '%s'. Aborting test." % [COURSE_RESOURCE_PATH]
)
var error_messages := PoolStringArray()
var index := 1
for lesson in course.lessons:
for content_block in lesson.content_blocks:
if not _is_valid(lesson, content_block.visual_element_path, VISUAL_ELEMENT_EXTENSIONS):
error_messages.append(
(
"Lesson %s (%s): visual element at path '%s' is not valid."
% [index, lesson.title, content_block.visual_element_path]
)
)
var practice_index := 1
for practice in lesson.practices:
if not _is_valid(lesson, practice.validator_script_path, ["gd"]):
error_messages.append(
(
"Lesson %s (%s) / Practice %s (%s): validator script at path '%s' is not valid."
% [
index,
lesson.title,
practice_index,
practice.title,
practice.validator_script_path
]
)
)
if not _is_valid(lesson, practice.script_slice_path):
error_messages.append(
(
"Lesson %s (%s) / Practice %s (%s): script slice at path '%s' is not valid."
% [
index,
lesson.title,
practice_index,
practice.title,
practice.script_slice_path
]
)
)
index += 1
var count := error_messages.size()
if count > 0:
print("%s invalid resources found." % count)
print(error_messages.join("\n"))
else:
print("No invalid resources found!")
print("Done.")
# Returns true if the path is valid, whether it's relative or absolute.
func _is_valid(resource: Resource, path: String, valid_extensions := ["tres"]) -> bool:
if path.empty():
return true
if not path.get_extension().to_lower() in valid_extensions:
return false
var test_path := path
if test_path.is_rel_path():
test_path = resource.resource_path.get_base_dir().plus_file(test_path)
return _file_tester.file_exists(test_path)