[3.x] Allow reading shaders from .gdshader files

(cherry picked from commit 7dc2edc430)
This commit is contained in:
Aaron Franke 2021-06-29 01:13:05 -04:00 committed by Rémi Verschelde
parent 1856be7a0e
commit 752c1451db
No known key found for this signature in database
GPG Key ID: C3336907360768E1
6 changed files with 15 additions and 4 deletions

View File

@ -1057,6 +1057,7 @@ ProjectSettings::ProjectSettings() {
extensions.push_back("gd");
if (Engine::get_singleton()->has_singleton("GodotSharp"))
extensions.push_back("cs");
extensions.push_back("gdshader");
extensions.push_back("shader");
GLOBAL_DEF("editor/search_in_file_extensions", extensions);

View File

@ -520,7 +520,7 @@
<member name="editor/script_templates_search_path" type="String" setter="" getter="" default="&quot;res://script_templates&quot;">
Search path for project-specific script templates. Godot will search for script templates both in the editor-specific path and in this project-specific path.
</member>
<member name="editor/search_in_file_extensions" type="PoolStringArray" setter="" getter="" default="PoolStringArray( &quot;gd&quot;, &quot;shader&quot; )">
<member name="editor/search_in_file_extensions" type="PoolStringArray" setter="" getter="" default="PoolStringArray( &quot;gd&quot;, &quot;gdshader&quot;, &quot;shader&quot; )">
Text-based file extensions to include in the script editor's "Find in Files" feature. You can add e.g. [code]tscn[/code] if you wish to also parse your scene files, especially if you use built-in scripts which are serialized in the scene files.
</member>
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">

View File

@ -140,6 +140,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) {
extension_guess["atlastex"] = get_icon("AtlasTexture", "EditorIcons");
extension_guess["scn"] = get_icon("PackedScene", "EditorIcons");
extension_guess["tscn"] = get_icon("PackedScene", "EditorIcons");
extension_guess["gdshader"] = get_icon("Shader", "EditorIcons");
extension_guess["shader"] = get_icon("Shader", "EditorIcons");
extension_guess["gd"] = get_icon("GDScript", "EditorIcons");
extension_guess["vs"] = get_icon("VisualScript", "EditorIcons");

View File

@ -3095,7 +3095,7 @@ void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_numb
if (ResourceLoader::exists(fpath)) {
RES res = ResourceLoader::load(fpath);
if (fpath.get_extension() == "shader") {
if (fpath.get_extension() == "gdshader" || fpath.get_extension() == "shader") {
ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader"));
shader_editor->edit(res.ptr());
shader_editor->make_visible(true);

View File

@ -21,6 +21,12 @@
<glob pattern="*.escn"/>
</mime-type>
<mime-type type="application/x-godot-shader">
<comment>Godot Engine shader</comment>
<icon name="x-godot-shader" />
<glob pattern="*.gdshader"/>
</mime-type>
<mime-type type="application/x-gdscript">
<comment>GDScript script</comment>
<icon name="x-gdscript" />

View File

@ -216,7 +216,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi
}
void ResourceFormatLoaderShader::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("gdshader");
p_extensions->push_back("shader");
}
@ -228,8 +228,9 @@ bool ResourceFormatLoaderShader::handles_type(const String &p_type) const {
String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "shader")
if (el == "gdshader" || el == "shader") {
return "Shader";
}
return "";
}
@ -260,10 +261,12 @@ void ResourceFormatSaverShader::get_recognized_extensions(const RES &p_resource,
if (const Shader *shader = Object::cast_to<Shader>(*p_resource)) {
if (shader->is_text_shader()) {
p_extensions->push_back("gdshader");
p_extensions->push_back("shader");
}
}
}
bool ResourceFormatSaverShader::recognize(const RES &p_resource) const {
return p_resource->get_class_name() == "Shader"; //only shader, not inherited