diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-09-02 16:05:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-02 16:05:05 +0200 |
commit | 877912b23ccfbbb349b495bdf52b694535cc896a (patch) | |
tree | 3470198563c586aae38378d8a1cc788b11ea681a | |
parent | d767edb9b3439a200caf07d7ec6dd3e2b9495ac1 (diff) | |
parent | c719cbee6996dcad9068fb5abcc107d5b9037d40 (diff) |
Merge pull request #24925 from Mr-Slurpy/typed-autoload
Added autoloads as a potential type.
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 9 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 69 |
2 files changed, 76 insertions, 2 deletions
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 7c01e85ff7..9d8089f00e 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -2826,6 +2826,15 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path ScriptCodeCompletionOption option(Variant::get_type_name((Variant::Type)i), ScriptCodeCompletionOption::KIND_CLASS); options.insert(option.display, option); } + List<PropertyInfo> props; + ProjectSettings::get_singleton()->get_property_list(&props); + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + String s = E->get().name; + if (!s.begins_with("autoload/")) { + continue; + } + options.insert(s.get_slice("/", 1)); + } } List<StringName> native_classes; diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 99bfdae7ec..14d8a3f4a2 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -5245,6 +5245,31 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive return; } p = NULL; + } else { + List<PropertyInfo> props; + ProjectSettings::get_singleton()->get_property_list(&props); + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + String s = E->get().name; + if (!s.begins_with("autoload/")) { + continue; + } + String name = s.get_slice("/", 1); + if (name == base) { + String singleton_path = ProjectSettings::get_singleton()->get(s); + if (singleton_path.begins_with("*")) { + singleton_path = singleton_path.right(1); + } + if (!singleton_path.begins_with("res://")) { + singleton_path = "res://" + singleton_path; + } + base_script = ResourceLoader::load(singleton_path); + if (!base_script.is_valid()) { + _set_error("Class '" + base + "' could not be fully loaded (script error or cyclic inheritance).", p_class->line); + return; + } + p = NULL; + } + } } while (p) { @@ -5589,9 +5614,49 @@ GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source, } name_part++; continue; - } else { - p = current_class; } + List<PropertyInfo> props; + ProjectSettings::get_singleton()->get_property_list(&props); + String singleton_path; + for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + String s = E->get().name; + if (!s.begins_with("autoload/")) { + continue; + } + String name = s.get_slice("/", 1); + if (name == id) { + singleton_path = ProjectSettings::get_singleton()->get(s); + if (singleton_path.begins_with("*")) { + singleton_path = singleton_path.right(1); + } + if (!singleton_path.begins_with("res://")) { + singleton_path = "res://" + singleton_path; + } + break; + } + } + if (!singleton_path.empty()) { + Ref<Script> script = ResourceLoader::load(singleton_path); + Ref<GDScript> gds = script; + if (gds.is_valid()) { + if (!gds->is_valid()) { + _set_error("Class '" + id + "' could not be fully loaded (script error or cyclic inheritance).", p_line); + return DataType(); + } + result.kind = DataType::GDSCRIPT; + result.script_type = gds; + } else if (script.is_valid()) { + result.kind = DataType::SCRIPT; + result.script_type = script; + } else { + _set_error("Couldn't fully load singleton script '" + id + "' (possible cyclic reference or parse error).", p_line); + return DataType(); + } + name_part++; + continue; + } + + p = current_class; } else if (base_type.kind == DataType::CLASS) { p = base_type.class_type; } |