GDScript: Fix extension comparison for exported scripts
This commit is contained in:
parent
907db8eebc
commit
a2e3e31e80
|
@ -1405,6 +1405,18 @@ String GDScript::debug_get_script_name(const Ref<Script> &p_script) {
|
|||
}
|
||||
#endif
|
||||
|
||||
bool GDScript::is_equal_gdscript_paths(const String &p_path_a, const String &p_path_b) {
|
||||
String path_a = p_path_a;
|
||||
if (path_a.get_extension() == "gdc") {
|
||||
path_a = path_a.get_basename() + ".gd";
|
||||
}
|
||||
String path_b = p_path_b;
|
||||
if (path_b.get_extension() == "gdc") {
|
||||
path_b = path_b.get_basename() + ".gd";
|
||||
}
|
||||
return path_a == path_b;
|
||||
}
|
||||
|
||||
GDScript::UpdatableFuncPtr::UpdatableFuncPtr(GDScriptFunction *p_function) {
|
||||
if (p_function == nullptr) {
|
||||
return;
|
||||
|
|
|
@ -230,6 +230,8 @@ public:
|
|||
static String debug_get_script_name(const Ref<Script> &p_script);
|
||||
#endif
|
||||
|
||||
static bool is_equal_gdscript_paths(const String &p_path_a, const String &p_path_b);
|
||||
|
||||
_FORCE_INLINE_ StringName get_local_name() const { return local_name; }
|
||||
|
||||
void clear(GDScript::ClearData *p_clear_data = nullptr);
|
||||
|
|
|
@ -361,7 +361,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
|
|||
push_error(vformat(R"(Class "%s" hides a built-in type.)", class_name), p_class->identifier);
|
||||
} else if (class_exists(class_name)) {
|
||||
push_error(vformat(R"(Class "%s" hides a native class.)", class_name), p_class->identifier);
|
||||
} else if (ScriptServer::is_global_class(class_name) && (ScriptServer::get_global_class_path(class_name) != parser->script_path || p_class != parser->head)) {
|
||||
} else if (ScriptServer::is_global_class(class_name) && (!GDScript::is_equal_gdscript_paths(ScriptServer::get_global_class_path(class_name), parser->script_path) || p_class != parser->head)) {
|
||||
push_error(vformat(R"(Class "%s" hides a global script class.)", class_name), p_class->identifier);
|
||||
} else if (ProjectSettings::get_singleton()->has_autoload(class_name) && ProjectSettings::get_singleton()->get_autoload(class_name).is_singleton) {
|
||||
push_error(vformat(R"(Class "%s" hides an autoload singleton.)", class_name), p_class->identifier);
|
||||
|
@ -425,7 +425,7 @@ Error GDScriptAnalyzer::resolve_class_inheritance(GDScriptParser::ClassNode *p_c
|
|||
if (ScriptServer::is_global_class(name)) {
|
||||
String base_path = ScriptServer::get_global_class_path(name);
|
||||
|
||||
if (base_path == parser->script_path) {
|
||||
if (GDScript::is_equal_gdscript_paths(base_path, parser->script_path)) {
|
||||
base = parser->head->get_datatype();
|
||||
} else {
|
||||
Ref<GDScriptParserRef> base_parser = get_parser_for(base_path);
|
||||
|
@ -698,7 +698,7 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type
|
|||
result.builtin_type = Variant::OBJECT;
|
||||
result.native_type = first;
|
||||
} else if (ScriptServer::is_global_class(first)) {
|
||||
if (parser->script_path == ScriptServer::get_global_class_path(first)) {
|
||||
if (GDScript::is_equal_gdscript_paths(parser->script_path, ScriptServer::get_global_class_path(first))) {
|
||||
result = parser->head->get_datatype();
|
||||
} else {
|
||||
String path = ScriptServer::get_global_class_path(first);
|
||||
|
|
|
@ -641,7 +641,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
|
|||
while (!stack.is_empty()) {
|
||||
current = Object::cast_to<Node>(stack.pop_back());
|
||||
Ref<GDScript> scr = current->get_script();
|
||||
if (scr.is_valid() && scr->get_path() == path) {
|
||||
if (scr.is_valid() && GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < current->get_child_count(); ++i) {
|
||||
|
@ -650,7 +650,7 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
|
|||
}
|
||||
|
||||
Ref<GDScript> scr = current->get_script();
|
||||
if (!scr.is_valid() || scr->get_path() != path) {
|
||||
if (!scr.is_valid() || !GDScript::is_equal_gdscript_paths(scr->get_path(), path)) {
|
||||
current = owner_scene_node;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,17 +82,21 @@ Ref<GDScriptEditorTranslationParserPlugin> gdscript_translation_parser_plugin;
|
|||
class EditorExportGDScript : public EditorExportPlugin {
|
||||
GDCLASS(EditorExportGDScript, EditorExportPlugin);
|
||||
|
||||
public:
|
||||
virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override {
|
||||
int script_mode = EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED;
|
||||
static constexpr int DEFAULT_SCRIPT_MODE = EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED;
|
||||
int script_mode = DEFAULT_SCRIPT_MODE;
|
||||
|
||||
protected:
|
||||
virtual void _export_begin(const HashSet<String> &p_features, bool p_debug, const String &p_path, int p_flags) override {
|
||||
script_mode = DEFAULT_SCRIPT_MODE;
|
||||
|
||||
const Ref<EditorExportPreset> &preset = get_export_preset();
|
||||
|
||||
if (preset.is_valid()) {
|
||||
script_mode = preset->get_script_export_mode();
|
||||
}
|
||||
}
|
||||
|
||||
if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
|
||||
virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override {
|
||||
if (p_path.get_extension() != "gd" || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -110,10 +114,9 @@ public:
|
|||
}
|
||||
|
||||
add_file(p_path.get_basename() + ".gdc", file, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual String get_name() const override { return "GDScript"; }
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue