65 lines
1.6 KiB
GDScript
65 lines
1.6 KiB
GDScript
extends SceneTree
|
|
|
|
const SEARCH_ROOTS := [
|
|
"res://src",
|
|
"res://game",
|
|
"res://content",
|
|
"res://scenes",
|
|
"res://tests",
|
|
]
|
|
|
|
var _failures: Array[String] = []
|
|
var _loaded_resource_count := 0
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
for root: String in SEARCH_ROOTS:
|
|
if DirAccess.dir_exists_absolute(root):
|
|
_load_directory(root)
|
|
|
|
if _failures.is_empty():
|
|
print("Resource loading: %d passed, 0 failed." % _loaded_resource_count)
|
|
quit(0)
|
|
else:
|
|
for failure: String in _failures:
|
|
push_error(failure)
|
|
print("Resource loading: %d failed." % _failures.size())
|
|
quit(1)
|
|
|
|
|
|
func _load_directory(directory_path: String) -> void:
|
|
var directory := DirAccess.open(directory_path)
|
|
if directory == null:
|
|
_failures.append("cannot open %s" % directory_path)
|
|
return
|
|
|
|
var subdirectories := directory.get_directories()
|
|
for subdirectory: String in subdirectories:
|
|
_load_directory(directory_path.path_join(subdirectory))
|
|
|
|
var files := directory.get_files()
|
|
for file_name: String in files:
|
|
if not (
|
|
file_name.ends_with(".gd")
|
|
or file_name.ends_with(".tscn")
|
|
or file_name.ends_with(".tres")
|
|
or file_name.ends_with(".res")
|
|
):
|
|
continue
|
|
var resource_path := directory_path.path_join(file_name)
|
|
var resource := ResourceLoader.load(resource_path)
|
|
if resource == null:
|
|
_failures.append("cannot load %s" % resource_path)
|
|
continue
|
|
if resource is PackedScene:
|
|
var instance := (resource as PackedScene).instantiate()
|
|
if instance == null:
|
|
_failures.append("cannot instantiate %s" % resource_path)
|
|
continue
|
|
instance.free()
|
|
_loaded_resource_count += 1
|