From 752c1451dbc32ea6ea22231f419190e2f43f5b20 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 29 Jun 2021 01:13:05 -0400 Subject: [PATCH] [3.x] Allow reading shaders from .gdshader files (cherry picked from commit 7dc2edc430a5cfcfe89d0e40900303098c3b9504) --- core/project_settings.cpp | 1 + doc/classes/ProjectSettings.xml | 2 +- editor/editor_asset_installer.cpp | 1 + editor/plugins/script_editor_plugin.cpp | 2 +- misc/dist/linux/org.godotengine.Godot.xml | 6 ++++++ scene/resources/shader.cpp | 7 +++++-- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/project_settings.cpp b/core/project_settings.cpp index 3efe25fc8b8..0e1e0f74446 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -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); diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index e582b7b95b8..c5fc34aad71 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -520,7 +520,7 @@ 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. - + 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. diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index 29190bf9398..134a6f04e4b 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -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"); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index ca3f76b882b..4baf4642122 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -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(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); shader_editor->edit(res.ptr()); shader_editor->make_visible(true); diff --git a/misc/dist/linux/org.godotengine.Godot.xml b/misc/dist/linux/org.godotengine.Godot.xml index 2f647f71a64..e51179cd617 100644 --- a/misc/dist/linux/org.godotengine.Godot.xml +++ b/misc/dist/linux/org.godotengine.Godot.xml @@ -21,6 +21,12 @@ + + Godot Engine shader + + + + GDScript script diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 3883ac0d180..2dd2e013ead 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -216,7 +216,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderShader::get_recognized_extensions(List *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(*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