diff options
author | Marius Hanl <mariushanl@web.de> | 2022-06-13 23:35:02 +0200 |
---|---|---|
committer | Marius Hanl <mariushanl@web.de> | 2022-12-21 19:49:57 +0100 |
commit | 5aa243f9da1c8ae425ae5b6706fe889f6e301959 (patch) | |
tree | c5294bbef0a1fe0897eddfbb41e7f5687a29466b /core/config/project_settings.cpp | |
parent | dcb3754db09b7b8c35aae1fedbc485b91e9f9508 (diff) |
Added the possibility to define a default value in ProjectSettings.get_setting(), which is used when no setting is set.
Also added tests for the project settings.
Co-authored-by: Yuri Sizov <11782833+YuriSizov@users.noreply.github.com>
Diffstat (limited to 'core/config/project_settings.cpp')
-rw-r--r-- | core/config/project_settings.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 310df46085..385cd2b2fd 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1124,8 +1124,12 @@ void ProjectSettings::set_setting(const String &p_setting, const Variant &p_valu set(p_setting, p_value); } -Variant ProjectSettings::get_setting(const String &p_setting) const { - return get(p_setting); +Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_default_value) const { + if (has_setting(p_setting)) { + return get(p_setting); + } else { + return p_default_value; + } } bool ProjectSettings::has_custom_feature(const String &p_feature) const { @@ -1158,7 +1162,7 @@ ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_ 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"), &ProjectSettings::get_setting); + ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant())); 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); |