GDScript: Implement get_dependencies()

The parser and analyzer now track the dependencies of the script and
return the list when the resource loader ask for them.

What is considered a dependency:

- Any `preload()` call.
- The base script this one extends.
- Any identifier, including types, that refers to global scripts.
- Any autoload singleton reference.
This commit is contained in:
George Marques 2024-04-18 11:48:07 -03:00
parent 2efbc6bfb3
commit dc73440f89
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
4 changed files with 29 additions and 7 deletions

View file

@ -2884,7 +2884,7 @@ String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) con
return "";
}
void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<String> *r_dependencies, bool p_add_types) {
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_MSG(file.is_null(), "Cannot open file '" + p_path + "'.");
@ -2898,8 +2898,13 @@ void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<S
return;
}
GDScriptAnalyzer analyzer(&parser);
if (OK != analyzer.analyze()) {
return;
}
for (const String &E : parser.get_dependencies()) {
p_dependencies->push_back(E);
r_dependencies->push_back(E);
}
}