-
-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Fix custom resource icons not appearing in file system #60606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
214b8a7
2139a6c
6555f22
96c5cd2
ee7b967
c86ccf8
2bc6890
4290b18
4655e8a
5cec031
79acac9
32efac4
3d6c92d
01b4e58
9fa356c
083bc04
00bdb8c
39f38f4
959a643
376edd4
8918126
12a5c66
feb86c9
878d4c0
b2b1e73
12436b0
74da04c
af03d99
1f677ff
112dbb8
1adf59e
bfb067a
1cbc633
e1b6bfa
d973eff
f7d1054
e05eef6
2f36132
c54616e
6f727f7
2c33802
1c4ae52
f12f5fa
6d4afb2
23e8af4
4151bd8
aee71b9
dcee398
20b421a
a8da40f
3b4734d
dc65e34
8c35031
9abeb02
f0aba98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,6 +320,11 @@ void Resource::notify_change_to_owners() { | |
| } | ||
| } | ||
|
|
||
| // We assume that only Resources can have attached scripts (excluding Scripts and PackedScenes, which still extend Resource). | ||
| bool Resource::is_script_extendable_resource(const StringName &p_class) { | ||
| return ClassDB::is_parent_class(p_class, Resource::get_class_static()) && !ClassDB::is_parent_class(p_class, Script::get_class_static()) && !ClassDB::is_parent_class(p_class, "PackedScene"); | ||
| } | ||
|
|
||
|
Comment on lines
+324
to
+327
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly considered core bloat, but also, this seems like it could actually be reasonable since it's short and centralizes logic that would be used not just in core, but also in scene and extensions/modules. |
||
| #ifdef TOOLS_ENABLED | ||
|
|
||
| uint32_t Resource::hash_edited_version() const { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -904,6 +904,47 @@ String ResourceLoaderBinary::get_unicode_string() { | |
| return s; | ||
| } | ||
|
|
||
| String ResourceLoaderBinary::get_attached_script_path(Ref<FileAccess> p_f) { | ||
| open(p_f, false, true); | ||
| if (error) { | ||
| return ""; | ||
| } | ||
| int main_resource_idx = internal_resources.size() - 1; | ||
|
|
||
| uint64_t offset = internal_resources[main_resource_idx].offset; | ||
|
|
||
| f->seek(offset); | ||
|
|
||
| String t = get_unicode_string(); | ||
|
|
||
| int pc = f->get_32(); | ||
| for (int j = 0; j < pc; j++) { | ||
| StringName name = _get_string(); | ||
|
|
||
| if (name == StringName()) { | ||
| error = ERR_FILE_CORRUPT; | ||
| ERR_FAIL_V(""); | ||
| } | ||
|
|
||
| Variant value; | ||
| uint32_t type = f->get_32(); | ||
| // Note that OBJECT_EXTERNAL_RESOURCE is old resource file format | ||
| if (name != StringName("script") || type != VARIANT_OBJECT) { | ||
| return ""; | ||
| } | ||
|
|
||
| uint32_t objtype = f->get_32(); | ||
| if (objtype != OBJECT_EXTERNAL_RESOURCE_INDEX) { | ||
| return ""; | ||
| } | ||
|
|
||
| int erindex = f->get_32(); | ||
| return external_resources[erindex].path; | ||
| } | ||
|
|
||
| return ""; | ||
| } | ||
|
|
||
|
Comment on lines
+907
to
+947
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| void ResourceLoaderBinary::get_classes_used(Ref<FileAccess> p_f, HashSet<StringName> *p_classes) { | ||
| open(p_f, false, true); | ||
| if (error) { | ||
|
|
@@ -1175,6 +1216,21 @@ bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const { | |
| return true; //handles all | ||
| } | ||
|
|
||
| String ResourceFormatLoaderBinary::get_attached_script_path(const String &p_path) const { | ||
| String type = get_resource_type(p_path); | ||
| if (!Resource::is_script_extendable_resource(type)) { | ||
| return ""; | ||
| } | ||
|
|
||
| Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); | ||
| ERR_FAIL_COND_V_MSG(f.is_null(), "", "Cannot open file '" + p_path + "'."); | ||
|
|
||
| ResourceLoaderBinary loader; | ||
| loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path); | ||
| loader.res_path = loader.local_path; | ||
| return loader.get_attached_script_path(f); | ||
| } | ||
|
|
||
|
Comment on lines
+1219
to
+1233
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { | ||
| Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); | ||
| ERR_FAIL_COND_MSG(f.is_null(), "Cannot open file '" + p_path + "'."); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,7 @@ class ResourceLoaderBinary { | |
| void set_remaps(const HashMap<String, String> &p_remaps) { remaps = p_remaps; } | ||
| void open(Ref<FileAccess> p_f, bool p_no_resources = false, bool p_keep_uuid_paths = false); | ||
| String recognize(Ref<FileAccess> p_f); | ||
| String get_attached_script_path(Ref<FileAccess> p_f); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| void get_dependencies(Ref<FileAccess> p_f, List<String> *p_dependencies, bool p_add_types); | ||
| void get_classes_used(Ref<FileAccess> p_f, HashSet<StringName> *p_classes); | ||
|
|
||
|
|
@@ -115,6 +116,7 @@ class ResourceFormatLoaderBinary : public ResourceFormatLoader { | |
| virtual String get_resource_type(const String &p_path) const; | ||
| virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes); | ||
| virtual ResourceUID::ID get_resource_uid(const String &p_path) const; | ||
| virtual String get_attached_script_path(const String &p_path) const; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false); | ||
| virtual Error rename_dependencies(const String &p_path, const HashMap<String, String> &p_map); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,15 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const { | |
| return ""; | ||
| } | ||
|
|
||
| String ResourceFormatLoader::get_attached_script_path(const String &p_path) const { | ||
| String script_path; | ||
| if (GDVIRTUAL_CALL(_get_attached_script_path, p_path, script_path)) { | ||
| return script_path; | ||
| } | ||
|
|
||
| return ""; | ||
| } | ||
|
|
||
|
Comment on lines
+104
to
+112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const { | ||
| int64_t uid; | ||
| if (GDVIRTUAL_CALL(_get_resource_uid, p_path, uid)) { | ||
|
|
@@ -191,6 +200,7 @@ void ResourceFormatLoader::_bind_methods() { | |
| GDVIRTUAL_BIND(_get_recognized_extensions); | ||
| GDVIRTUAL_BIND(_handles_type, "type"); | ||
| GDVIRTUAL_BIND(_get_resource_type, "path"); | ||
| GDVIRTUAL_BIND(_get_attached_script_path, "path"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| GDVIRTUAL_BIND(_get_resource_uid, "path"); | ||
| GDVIRTUAL_BIND(_get_dependencies, "path", "add_types"); | ||
| GDVIRTUAL_BIND(_rename_dependencies, "path", "renames"); | ||
|
|
@@ -784,6 +794,19 @@ ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) { | |
| return ResourceUID::INVALID_ID; | ||
| } | ||
|
|
||
| String ResourceLoader::get_attached_script_path(const String &p_path) { | ||
| String local_path = _validate_local_path(p_path); | ||
|
|
||
| for (int i = 0; i < loader_count; i++) { | ||
| String path = loader[i]->get_attached_script_path(local_path); | ||
| if (!path.is_empty()) { | ||
| return path; | ||
| } | ||
| } | ||
|
|
||
| return ""; | ||
| } | ||
|
|
||
|
Comment on lines
+797
to
+809
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) { | ||
| String new_path = p_path; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ class ResourceFormatLoader : public RefCounted { | |
| GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions) | ||
| GDVIRTUAL1RC(bool, _handles_type, StringName) | ||
| GDVIRTUAL1RC(String, _get_resource_type, String) | ||
| GDVIRTUAL1RC(String, _get_attached_script_path, String) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| GDVIRTUAL1RC(ResourceUID::ID, _get_resource_uid, String) | ||
| GDVIRTUAL2RC(Vector<String>, _get_dependencies, String, bool) | ||
| GDVIRTUAL1RC(Vector<String>, _get_classes_used, String) | ||
|
|
@@ -70,6 +71,7 @@ class ResourceFormatLoader : public RefCounted { | |
| virtual bool handles_type(const String &p_type) const; | ||
| virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes); | ||
| virtual String get_resource_type(const String &p_path) const; | ||
| virtual String get_attached_script_path(const String &p_path) const; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| virtual ResourceUID::ID get_resource_uid(const String &p_path) const; | ||
| virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false); | ||
| virtual Error rename_dependencies(const String &p_path, const HashMap<String, String> &p_map); | ||
|
|
@@ -175,6 +177,7 @@ class ResourceLoader { | |
| static void get_classes_used(const String &p_path, HashSet<StringName> *r_classes); | ||
| static String get_resource_type(const String &p_path); | ||
| static ResourceUID::ID get_resource_uid(const String &p_path); | ||
| static String get_attached_script_path(const String &p_path); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?* |
||
| static void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false); | ||
| static Error rename_dependencies(const String &p_path, const HashMap<String, String> &p_map); | ||
| static bool is_import_valid(const String &p_path); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,6 +232,7 @@ class ClassDB { | |
| static StringName get_compatibility_remapped_class(const StringName &p_class); | ||
| static bool class_exists(const StringName &p_class); | ||
| static bool is_parent_class(const StringName &p_class, const StringName &p_inherits); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary |
||
| static bool can_instantiate(const StringName &p_class); | ||
| static bool is_virtual(const StringName &p_class); | ||
| static Object *instantiate(const StringName &p_class); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1399,6 +1399,21 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin | |
| return OK; | ||
| } | ||
|
|
||
| Error VariantParser::skip_until_tag(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser, bool p_simple_tag) { | ||
| Token token; | ||
| get_token(p_stream, token, line, r_err_str); | ||
|
|
||
| if (token.type == TK_EOF) { | ||
| return ERR_FILE_EOF; | ||
| } | ||
|
|
||
| while (token.type != TK_BRACKET_OPEN) { | ||
| get_token(p_stream, token, line, r_err_str); | ||
| } | ||
|
|
||
| return _parse_tag(token, p_stream, line, r_err_str, r_tag, p_res_parser, p_simple_tag); | ||
| } | ||
|
|
||
|
Comment on lines
+1402
to
+1416
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?** |
||
| Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser, bool p_simple_tag) { | ||
| Token token; | ||
| get_token(p_stream, token, line, r_err_str); | ||
|
|
@@ -1415,8 +1430,8 @@ Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, T | |
| return _parse_tag(token, p_stream, line, r_err_str, r_tag, p_res_parser, p_simple_tag); | ||
| } | ||
|
|
||
| Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag) { | ||
| //assign.. | ||
| // Parses tags or assigns and takes in a custom function for handling value parsing | ||
| Error VariantParser::parse_tag_assign_with_value_func_eof(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag, ParseValueFunc p_parse_value_func) { | ||
|
Comment on lines
+1433
to
+1434
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?** |
||
| r_assign = ""; | ||
| String what; | ||
|
|
||
|
|
@@ -1478,7 +1493,7 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r | |
| r_assign = what; | ||
| Token token; | ||
| get_token(p_stream, token, line, r_err_str); | ||
| Error err = parse_value(token, r_value, p_stream, line, r_err_str, p_res_parser); | ||
| Error err = p_parse_value_func(token, r_value, p_stream, line, r_err_str, p_res_parser); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?** |
||
| return err; | ||
| } | ||
| } else if (c == '\n') { | ||
|
|
@@ -1487,6 +1502,10 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r | |
| } | ||
| } | ||
|
|
||
| Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag) { | ||
| return parse_tag_assign_with_value_func_eof(p_stream, line, r_err_str, r_tag, r_assign, r_value, p_res_parser, p_simple_tag, parse_value); | ||
| } | ||
|
|
||
|
Comment on lines
+1505
to
+1508
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?** |
||
| Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, int &r_err_line, ResourceParser *p_res_parser) { | ||
| Token token; | ||
| Error err = get_token(p_stream, token, r_err_line, r_err_str); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,7 +127,11 @@ class VariantParser { | |
| static Error _parse_tag(Token &token, Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser = nullptr, bool p_simple_tag = false); | ||
|
|
||
| public: | ||
| typedef Error (*ParseValueFunc)(Token &token, Variant &value, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser); | ||
|
|
||
| static Error skip_until_tag(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser = nullptr, bool p_simple_tag = false); | ||
| static Error parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, ResourceParser *p_res_parser = nullptr, bool p_simple_tag = false); | ||
| static Error parse_tag_assign_with_value_func_eof(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag, ParseValueFunc p_value_func); | ||
|
Comment on lines
+130
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Core bloat?** |
||
| static Error parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag &r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser = nullptr, bool p_simple_tag = false); | ||
|
|
||
| static Error parse_value(Token &token, Variant &value, Stream *p_stream, int &line, String &r_err_str, ResourceParser *p_res_parser = nullptr); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment bloat