diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gdscript_editor.cpp | 10 | ||||
-rw-r--r-- | modules/gdscript/gdscript_functions.cpp | 36 | ||||
-rw-r--r-- | modules/gdscript/gdscript_functions.h | 1 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 81 |
4 files changed, 125 insertions, 3 deletions
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 7c01e85ff7..925dbda620 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -2826,6 +2826,16 @@ 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; + } + ScriptCodeCompletionOption option(s.get_slice("/", 1), ScriptCodeCompletionOption::KIND_CLASS); + options.insert(option.display, option); + } } List<StringName> native_classes; diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index ad8bf5b2c0..97790e00bb 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -106,6 +106,7 @@ const char *GDScriptFunctions::get_func_name(Function p_func) { "typeof", "type_exists", "char", + "ord", "str", "print", "printt", @@ -665,6 +666,33 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ CharType result[2] = { *p_args[0], 0 }; r_ret = String(result); } break; + case TEXT_ORD: { + + VALIDATE_ARG_COUNT(1); + + if (p_args[0]->get_type() != Variant::STRING) { + + r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::STRING; + r_ret = Variant(); + return; + } + + String str = p_args[0]->operator String(); + + if (str.length() != 1) { + + r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::STRING; + r_ret = RTR("Expected a string of length 1 (a character)."); + return; + } + + r_ret = str.get(0); + + } break; case TEXT_STR: { if (p_arg_count < 1) { r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; @@ -1507,6 +1535,7 @@ bool GDScriptFunctions::is_deterministic(Function p_func) { case TYPE_OF: case TYPE_EXISTS: case TEXT_CHAR: + case TEXT_ORD: case TEXT_STR: case COLOR8: case LEN: @@ -1849,6 +1878,13 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { return mi; } break; + case TEXT_ORD: { + + MethodInfo mi("ord", PropertyInfo(Variant::STRING, "char")); + mi.return_val.type = Variant::INT; + return mi; + + } break; case TEXT_STR: { MethodInfo mi("str"); diff --git a/modules/gdscript/gdscript_functions.h b/modules/gdscript/gdscript_functions.h index 8f7ba76d2c..9ea5dd46cf 100644 --- a/modules/gdscript/gdscript_functions.h +++ b/modules/gdscript/gdscript_functions.h @@ -97,6 +97,7 @@ public: TYPE_OF, TYPE_EXISTS, TEXT_CHAR, + TEXT_ORD, TEXT_STR, TEXT_PRINT, TEXT_PRINT_TABBED, diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 99bfdae7ec..9c5b78c8f3 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -252,6 +252,16 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } } + // Check that the next token is not TK_CURSOR and if it is, the offset should be incremented. + int next_valid_offset = 1; + if (tokenizer->get_token(next_valid_offset) == GDScriptTokenizer::TK_CURSOR) { + next_valid_offset++; + // There is a chunk of the identifier that also needs to be ignored (not always there!) + if (tokenizer->get_token(next_valid_offset) == GDScriptTokenizer::TK_IDENTIFIER) { + next_valid_offset++; + } + } + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { //subexpression () tokenizer->advance(); @@ -668,7 +678,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s expr = cn; } - } else if (tokenizer->get_token(1) == GDScriptTokenizer::TK_PARENTHESIS_OPEN && tokenizer->is_token_literal()) { + } else if (tokenizer->get_token(next_valid_offset) == GDScriptTokenizer::TK_PARENTHESIS_OPEN && tokenizer->is_token_literal()) { // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //function or constructor @@ -5245,6 +5255,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 +5624,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; } |