Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
214b8a7
Initial fix by adding field to FileInfo
Atlinx Apr 28, 2022
2139a6c
Remove comments and update docs
Atlinx May 15, 2022
6555f22
Remove some comments & unecessary include
Atlinx May 15, 2022
96c5cd2
Update doc/classes/ResourceFormatLoader.xml
Atlinx May 21, 2022
ee7b967
Update doc/classes/EditorFileSystem.xml
Atlinx May 21, 2022
c86ccf8
Update editor/editor_file_system.cpp
Atlinx May 21, 2022
2bc6890
Update editor/editor_file_system.cpp
Atlinx May 21, 2022
4290b18
Exclude packed scenes from parsing
Atlinx May 22, 2022
4655e8a
Fix missing not operator
Atlinx May 22, 2022
5cec031
Update core/io/resource_loader.cpp
Atlinx May 22, 2022
79acac9
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
32efac4
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
3d6c92d
Update editor/filesystem_dock.cpp
Atlinx May 22, 2022
01b4e58
Update scene/resources/resource_format_text.cpp
Atlinx May 22, 2022
9fa356c
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
083bc04
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
00bdb8c
Add rest of KoBeWi's suggestions
Atlinx May 22, 2022
39f38f4
Add more of KoBeWi's suggestions
Atlinx May 22, 2022
959a643
Relocated helper method + add file list icon
Atlinx May 23, 2022
376edd4
WIP binary format
Atlinx May 23, 2022
8918126
Add binary format
Atlinx May 23, 2022
12a5c66
Change resource parsing to explicitly look for script property
Atlinx Jul 15, 2022
feb86c9
Merge branch 'godotengine:master' into feat/32706_custom_resource_icons
Atlinx Jul 15, 2022
878d4c0
Initial fix by adding field to FileInfo
Atlinx Apr 28, 2022
b2b1e73
Remove comments and update docs
Atlinx May 15, 2022
12436b0
Remove some comments & unecessary include
Atlinx May 15, 2022
74da04c
Update doc/classes/ResourceFormatLoader.xml
Atlinx May 21, 2022
af03d99
Update doc/classes/EditorFileSystem.xml
Atlinx May 21, 2022
1f677ff
Update editor/editor_file_system.cpp
Atlinx May 21, 2022
112dbb8
Update editor/editor_file_system.cpp
Atlinx May 21, 2022
1adf59e
Exclude packed scenes from parsing
Atlinx May 22, 2022
bfb067a
Fix missing not operator
Atlinx May 22, 2022
1cbc633
Update core/io/resource_loader.cpp
Atlinx May 22, 2022
e1b6bfa
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
d973eff
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
f7d1054
Update editor/filesystem_dock.cpp
Atlinx May 22, 2022
e05eef6
Update scene/resources/resource_format_text.cpp
Atlinx May 22, 2022
2f36132
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
c54616e
Update editor/editor_file_system.cpp
Atlinx May 22, 2022
6f727f7
Add rest of KoBeWi's suggestions
Atlinx May 22, 2022
2c33802
Add more of KoBeWi's suggestions
Atlinx May 22, 2022
1c4ae52
Relocated helper method + add file list icon
Atlinx May 23, 2022
f12f5fa
WIP binary format
Atlinx May 23, 2022
6d4afb2
Add binary format
Atlinx May 23, 2022
23e8af4
Change resource parsing to explicitly look for script property
Atlinx Jul 15, 2022
4151bd8
Change Map to HashMap
Atlinx Jul 15, 2022
aee71b9
Remove old code
Atlinx Jul 15, 2022
dcee398
Merge branch 'feat/32706_custom_resource_icons' of https://github.com…
Atlinx Jul 15, 2022
20b421a
Remove dependency on scene and remove unecessary resource.h changes
Atlinx Jul 16, 2022
a8da40f
Add skip until tag parsing
Atlinx Jul 25, 2022
3b4734d
Merge branch 'master' into feat/32706_custom_resource_icons
Atlinx Jul 25, 2022
dc65e34
Fix missing description tag in doc
Atlinx Jul 25, 2022
8c35031
Fix indentation to tabs in docs
Atlinx Aug 11, 2022
9abeb02
Merge branch 'godotengine:master' into feat/32706_custom_resource_icons
Atlinx Aug 22, 2022
f0aba98
Fix docs
Atlinx Aug 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment bloat

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 {
Expand Down
1 change: 1 addition & 0 deletions core/io/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Resource : public RefCounted {

Node *get_local_scene() const;

static bool is_script_extendable_resource(const StringName &p_class);
#ifdef TOOLS_ENABLED

uint32_t hash_edited_version() const;
Expand Down
56 changes: 56 additions & 0 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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) {
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 + "'.");
Expand Down
2 changes: 2 additions & 0 deletions core/io/resource_format_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);

Expand All @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
};
Expand Down
23 changes: 23 additions & 0 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)) {
Expand Down Expand Up @@ -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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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");
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;

Expand Down
3 changes: 3 additions & 0 deletions core/io/resource_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)
Expand All @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
1 change: 1 addition & 0 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
25 changes: 22 additions & 3 deletions core/variant/variant_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core bloat?**

r_assign = "";
String what;

Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core bloat?**

return err;
}
} else if (c == '\n') {
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
4 changes: 4 additions & 0 deletions core/variant/variant_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
5 changes: 5 additions & 0 deletions doc/classes/EditorFileSystem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
Emitted if at least one resource is reloaded when the filesystem is scanned.
</description>
</signal>
<signal name="script_classes_loaded">
<description>
Emitted once all scripts have been loaded. This happens after [signal filesystem_changed] is emitted.
</description>
</signal>
<signal name="sources_changed">
<param index="0" name="exist" type="bool" />
<description>
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/ResourceFormatLoader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
<description>
</description>
</method>
<method name="_get_attached_script_path" qualifiers="virtual const">
<return type="String" />
<param index="0" name="path" type="String" />
<description>
If implemented, gets the path of a script attached to a resource. The script is usually attached when creating a new instance of a [Resource]-based custom class.
</description>
</method>
<method name="_get_classes_used" qualifiers="virtual const">
<return type="PackedStringArray" />
<param index="0" name="path" type="String" />
Expand Down
Loading