diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/config/project_settings.cpp | 53 | ||||
-rw-r--r-- | core/config/project_settings.h | 9 | ||||
-rw-r--r-- | core/core_bind.cpp | 6 | ||||
-rw-r--r-- | core/core_bind.h | 2 | ||||
-rw-r--r-- | core/io/config_file.cpp | 4 | ||||
-rw-r--r-- | core/os/os.h | 2 | ||||
-rw-r--r-- | core/variant/variant_parser.cpp | 21 |
7 files changed, 62 insertions, 35 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 0bf7430d84..73d7d7420f 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -291,31 +291,26 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { return true; } - if (!disable_feature_overrides) { + { // Feature overrides. int dot = p_name.operator String().find("."); if (dot != -1) { Vector<String> s = p_name.operator String().split("."); - bool override_valid = false; for (int i = 1; i < s.size(); i++) { String feature = s[i].strip_edges(); - if (OS::get_singleton()->has_feature(feature) || custom_features.has(feature)) { - override_valid = true; - break; + Pair<StringName, StringName> fo(feature, p_name); + + if (!feature_overrides.has(s[0])) { + feature_overrides[s[0]] = LocalVector<Pair<StringName, StringName>>(); } - } - if (override_valid) { - feature_overrides[s[0]] = p_name; + feature_overrides[s[0]].push_back(fo); } } } if (props.has(p_name)) { - if (!props[p_name].overridden) { - props[p_name].variant = p_value; - } - + props[p_name].variant = p_value; } else { props[p_name] = VariantContainer(p_value, last_order++); } @@ -340,16 +335,35 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const { _THREAD_SAFE_METHOD_ + if (!props.has(p_name)) { + WARN_PRINT("Property not found: " + String(p_name)); + return false; + } + r_ret = props[p_name].variant; + return true; +} + +Variant ProjectSettings::get_setting_with_override(const StringName &p_name) const { + _THREAD_SAFE_METHOD_ + StringName name = p_name; - if (!disable_feature_overrides && feature_overrides.has(name)) { - name = feature_overrides[name]; + if (feature_overrides.has(name)) { + const LocalVector<Pair<StringName, StringName>> &overrides = feature_overrides[name]; + for (uint32_t i = 0; i < overrides.size(); i++) { + if (OS::get_singleton()->has_feature(overrides[i].first)) { // Custom features are checked in OS.has_feature() already. No need to check twice. + if (props.has(overrides[i].second)) { + name = overrides[i].second; + break; + } + } + } } + if (!props.has(name)) { WARN_PRINT("Property not found: " + String(name)); - return false; + return Variant(); } - r_ret = props[name].variant; - return true; + return props[name].variant; } struct _VCSort { @@ -1101,10 +1115,6 @@ const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_in return custom_prop_info; } -void ProjectSettings::set_disable_feature_overrides(bool p_disable) { - disable_feature_overrides = p_disable; -} - bool ProjectSettings::is_using_datapack() const { return using_datapack; } @@ -1169,6 +1179,7 @@ void ProjectSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting); ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting); ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override); ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order); ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order); ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value); diff --git a/core/config/project_settings.h b/core/config/project_settings.h index 2aca1e7691..353e298919 100644 --- a/core/config/project_settings.h +++ b/core/config/project_settings.h @@ -34,6 +34,7 @@ #include "core/object/class_db.h" #include "core/os/thread_safe.h" #include "core/templates/hash_map.h" +#include "core/templates/local_vector.h" #include "core/templates/rb_set.h" class ProjectSettings : public Object { @@ -69,7 +70,6 @@ protected: Variant variant; Variant initial; bool hide_from_editor = false; - bool overridden = false; bool restart_if_changed = false; #ifdef DEBUG_METHODS_ENABLED bool ignore_value_in_docs = false; @@ -91,12 +91,11 @@ protected: RBMap<StringName, VariantContainer> props; // NOTE: Key order is used e.g. in the save_custom method. String resource_path; HashMap<StringName, PropertyInfo> custom_prop_info; - bool disable_feature_overrides = false; bool using_datapack = false; List<String> input_presets; HashSet<String> custom_features; - HashMap<StringName, StringName> feature_overrides; + HashMap<StringName, LocalVector<Pair<StringName, StringName>>> feature_overrides; HashMap<StringName, AutoloadInfo> autoloads; @@ -181,7 +180,7 @@ public: List<String> get_input_presets() const { return input_presets; } - void set_disable_feature_overrides(bool p_disable); + Variant get_setting_with_override(const StringName &p_name) const; bool is_using_datapack() const; @@ -205,7 +204,7 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p #define GLOBAL_DEF_RST(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true) #define GLOBAL_DEF_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, true) #define GLOBAL_DEF_RST_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, true) -#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get(m_var) +#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get_setting_with_override(m_var) #define GLOBAL_DEF_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, false, true) #define GLOBAL_DEF_RST_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, false, true) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 0ed05a20a2..ab433bd8f1 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -257,8 +257,8 @@ Error OS::shell_open(String p_uri) { return ::OS::get_singleton()->shell_open(p_uri); } -String OS::read_string_from_stdin(bool p_block) { - return ::OS::get_singleton()->get_stdin_string(true); +String OS::read_string_from_stdin() { + return ::OS::get_singleton()->get_stdin_string(); } int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr, bool p_open_console) { @@ -539,7 +539,7 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_system_font_path", "font_name", "weight", "stretch", "italic"), &OS::get_system_font_path, DEFVAL(400), DEFVAL(100), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_system_font_path_for_text", "font_name", "text", "locale", "script", "weight", "stretch", "italic"), &OS::get_system_font_path_for_text, DEFVAL(String()), DEFVAL(String()), DEFVAL(400), DEFVAL(100), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path); - ClassDB::bind_method(D_METHOD("read_string_from_stdin", "block"), &OS::read_string_from_stdin, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("read_string_from_stdin"), &OS::read_string_from_stdin); ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL(Array()), DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false)); ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance); diff --git a/core/core_bind.h b/core/core_bind.h index e8c59866e3..7ef346d1c4 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -146,7 +146,7 @@ public: String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const; Vector<String> get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const; String get_executable_path() const; - String read_string_from_stdin(bool p_block = true); + String read_string_from_stdin(); int execute(const String &p_path, const Vector<String> &p_arguments, Array r_output = Array(), bool p_read_stderr = false, bool p_open_console = false); int create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console = false); int create_instance(const Vector<String> &p_arguments); diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index f2cd3ba4d9..98f8c3de41 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -208,7 +208,7 @@ Error ConfigFile::_internal_save(Ref<FileAccess> file) { file->store_string("\n"); } if (!E.key.is_empty()) { - file->store_string("[" + E.key + "]\n\n"); + file->store_string("[" + E.key.replace("]", "\\]") + "]\n\n"); } for (const KeyValue<String, Variant> &F : E.value) { @@ -308,7 +308,7 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) if (!assign.is_empty()) { set_value(section, assign, value); } else if (!next_tag.name.is_empty()) { - section = next_tag.name; + section = next_tag.name.replace("\\]", "]"); } } diff --git a/core/os/os.h b/core/os/os.h index 3c0c05f575..b80efa47b7 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -131,7 +131,7 @@ public: void print_rich(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; - virtual String get_stdin_string(bool p_block = true) = 0; + virtual String get_stdin_string() = 0; virtual Error get_entropy(uint8_t *r_buffer, int p_bytes) = 0; // Should return cryptographically-safe random bytes. diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 39a039ffe8..87874deb8d 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1358,6 +1358,7 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin if (p_simple_tag) { r_tag.name = ""; r_tag.fields.clear(); + bool escaping = false; if (p_stream->is_utf8()) { CharString cs; @@ -1368,7 +1369,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin return ERR_PARSE_ERROR; } if (c == ']') { - break; + if (escaping) { + escaping = false; + } else { + break; + } + } else if (c == '\\') { + escaping = true; + } else { + escaping = false; } cs += c; } @@ -1381,7 +1390,15 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin return ERR_PARSE_ERROR; } if (c == ']') { - break; + if (escaping) { + escaping = false; + } else { + break; + } + } else if (c == '\\') { + escaping = true; + } else { + escaping = false; } r_tag.name += String::chr(c); } |