| 1 | /**************************************************************************/ |
| 2 | /* project_settings.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "project_settings.h" |
| 32 | |
| 33 | #include "core/core_bind.h" // For Compression enum. |
| 34 | #include "core/input/input_map.h" |
| 35 | #include "core/io/config_file.h" |
| 36 | #include "core/io/dir_access.h" |
| 37 | #include "core/io/file_access.h" |
| 38 | #include "core/io/file_access_pack.h" |
| 39 | #include "core/io/marshalls.h" |
| 40 | #include "core/io/resource_uid.h" |
| 41 | #include "core/object/script_language.h" |
| 42 | #include "core/templates/rb_set.h" |
| 43 | #include "core/variant/typed_array.h" |
| 44 | #include "core/variant/variant_parser.h" |
| 45 | #include "core/version.h" |
| 46 | #include "servers/rendering/rendering_server.h" |
| 47 | |
| 48 | #ifdef TOOLS_ENABLED |
| 49 | #include "modules/modules_enabled.gen.h" // For mono. |
| 50 | #endif // TOOLS_ENABLED |
| 51 | |
| 52 | ProjectSettings *ProjectSettings::get_singleton() { |
| 53 | return singleton; |
| 54 | } |
| 55 | |
| 56 | String ProjectSettings::get_project_data_dir_name() const { |
| 57 | return project_data_dir_name; |
| 58 | } |
| 59 | |
| 60 | String ProjectSettings::get_project_data_path() const { |
| 61 | return "res://" + get_project_data_dir_name(); |
| 62 | } |
| 63 | |
| 64 | String ProjectSettings::get_resource_path() const { |
| 65 | return resource_path; |
| 66 | } |
| 67 | |
| 68 | // This returns paths like "res://.godot/imported". |
| 69 | String ProjectSettings::get_imported_files_path() const { |
| 70 | return get_project_data_path().path_join("imported"); |
| 71 | } |
| 72 | |
| 73 | #ifdef TOOLS_ENABLED |
| 74 | // Returns the features that a project must have when opened with this build of Godot. |
| 75 | // This is used by the project manager to provide the initial_settings for config/features. |
| 76 | const PackedStringArray ProjectSettings::get_required_features() { |
| 77 | PackedStringArray features; |
| 78 | features.append(GODOT_VERSION_BRANCH); |
| 79 | #ifdef REAL_T_IS_DOUBLE |
| 80 | features.append("Double Precision"); |
| 81 | #endif |
| 82 | return features; |
| 83 | } |
| 84 | |
| 85 | // Returns the features supported by this build of Godot. Includes all required features. |
| 86 | const PackedStringArray ProjectSettings::_get_supported_features() { |
| 87 | PackedStringArray features = get_required_features(); |
| 88 | |
| 89 | #ifdef LIBGODOT_ENABLED |
| 90 | features.append("LibGodot"); |
| 91 | #endif |
| 92 | |
| 93 | #ifdef MODULE_MONO_ENABLED |
| 94 | features.append("C#"); |
| 95 | #endif |
| 96 | // Allow pinning to a specific patch number or build type by marking |
| 97 | // them as supported. They're only used if the user adds them manually. |
| 98 | features.append(GODOT_VERSION_BRANCH "." _MKSTR(GODOT_VERSION_PATCH)); |
| 99 | features.append(GODOT_VERSION_FULL_CONFIG); |
| 100 | features.append(GODOT_VERSION_FULL_BUILD); |
| 101 | |
| 102 | #ifdef RD_ENABLED |
| 103 | features.append("Forward Plus"); |
| 104 | features.append("Mobile"); |
| 105 | #endif |
| 106 | |
| 107 | #ifdef GLES3_ENABLED |
| 108 | features.append("GL Compatibility"); |
| 109 | #endif |
| 110 | return features; |
| 111 | } |
| 112 | |
| 113 | // Returns the features that this project needs but this build of Godot lacks. |
| 114 | const PackedStringArray ProjectSettings::get_unsupported_features(const PackedStringArray &p_project_features) { |
| 115 | PackedStringArray unsupported_features; |
| 116 | PackedStringArray supported_features = singleton->_get_supported_features(); |
| 117 | for (int i = 0; i < p_project_features.size(); i++) { |
| 118 | if (!supported_features.has(p_project_features[i])) { |
| 119 | // Temporary compatibility code to ease upgrade to 4.0 beta 2+. |
| 120 | if (p_project_features[i].begins_with("Vulkan")) { |
| 121 | continue; |
| 122 | } |
| 123 | unsupported_features.append(p_project_features[i]); |
| 124 | } |
| 125 | } |
| 126 | unsupported_features.sort(); |
| 127 | return unsupported_features; |
| 128 | } |
| 129 | |
| 130 | // Returns the features that both this project has and this build of Godot has, ensuring required features exist. |
| 131 | const PackedStringArray ProjectSettings::_trim_to_supported_features(const PackedStringArray &p_project_features) { |
| 132 | // Remove unsupported features if present. |
| 133 | PackedStringArray features = PackedStringArray(p_project_features); |
| 134 | PackedStringArray supported_features = _get_supported_features(); |
| 135 | for (int i = p_project_features.size() - 1; i > -1; i--) { |
| 136 | if (!supported_features.has(p_project_features[i])) { |
| 137 | features.remove_at(i); |
| 138 | } |
| 139 | } |
| 140 | // Add required features if not present. |
| 141 | PackedStringArray required_features = get_required_features(); |
| 142 | for (int i = 0; i < required_features.size(); i++) { |
| 143 | if (!features.has(required_features[i])) { |
| 144 | features.append(required_features[i]); |
| 145 | } |
| 146 | } |
| 147 | features.sort(); |
| 148 | return features; |
| 149 | } |
| 150 | #endif // TOOLS_ENABLED |
| 151 | |
| 152 | String ProjectSettings::localize_path(const String &p_path) const { |
| 153 | String path = p_path.simplify_path(); |
| 154 | |
| 155 | if (resource_path.is_empty() || (path.is_absolute_path() && !path.begins_with(resource_path))) { |
| 156 | return path; |
| 157 | } |
| 158 | |
| 159 | // Check if we have a special path (like res://) or a protocol identifier. |
| 160 | int p = path.find("://"); |
| 161 | bool found = false; |
| 162 | if (p > 0) { |
| 163 | found = true; |
| 164 | for (int i = 0; i < p; i++) { |
| 165 | if (!is_ascii_alphanumeric_char(path[i])) { |
| 166 | found = false; |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | if (found) { |
| 172 | return path; |
| 173 | } |
| 174 | |
| 175 | Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 176 | |
| 177 | if (dir->change_dir(path) == OK) { |
| 178 | String cwd = dir->get_current_dir(); |
| 179 | cwd = cwd.replace_char('\\', '/'); |
| 180 | |
| 181 | // Ensure that we end with a '/'. |
| 182 | // This is important to ensure that we do not wrongly localize the resource path |
| 183 | // in an absolute path that just happens to contain this string but points to a |
| 184 | // different folder (e.g. "/my/project" as resource_path would be contained in |
| 185 | // "/my/project_data", even though the latter is not part of res://. |
| 186 | // `path_join("")` is an easy way to ensure we have a trailing '/'. |
| 187 | const String res_path = resource_path.path_join(""); |
| 188 | |
| 189 | // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/', |
| 190 | // so we must make sure we have it as well in order to compare with 'res_path'. |
| 191 | cwd = cwd.path_join(""); |
| 192 | |
| 193 | if (!cwd.begins_with(res_path)) { |
| 194 | return path; |
| 195 | } |
| 196 | |
| 197 | return cwd.replace_first(res_path, "res://"); |
| 198 | } else { |
| 199 | int sep = path.rfind_char('/'); |
| 200 | if (sep == -1) { |
| 201 | return "res://" + path; |
| 202 | } |
| 203 | |
| 204 | String parent = path.substr(0, sep); |
| 205 | |
| 206 | String plocal = localize_path(parent); |
| 207 | if (plocal.is_empty()) { |
| 208 | return ""; |
| 209 | } |
| 210 | // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/' |
| 211 | if (plocal[plocal.length() - 1] == '/') { |
| 212 | sep += 1; |
| 213 | } |
| 214 | return plocal + path.substr(sep); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) { |
| 219 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 220 | |
| 221 | // Duplicate so that if value is array or dictionary, changing the setting will not change the stored initial value. |
| 222 | props[p_name].initial = p_value.duplicate(); |
| 223 | } |
| 224 | |
| 225 | void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) { |
| 226 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 227 | props[p_name].restart_if_changed = p_restart; |
| 228 | } |
| 229 | |
| 230 | void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) { |
| 231 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 232 | props[p_name].basic = p_basic; |
| 233 | } |
| 234 | |
| 235 | void ProjectSettings::set_as_internal(const String &p_name, bool p_internal) { |
| 236 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 237 | props[p_name].internal = p_internal; |
| 238 | } |
| 239 | |
| 240 | void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) { |
| 241 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 242 | #ifdef DEBUG_ENABLED |
| 243 | props[p_name].ignore_value_in_docs = p_ignore; |
| 244 | #endif // DEBUG_ENABLED |
| 245 | } |
| 246 | |
| 247 | bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const { |
| 248 | ERR_FAIL_COND_V_MSG(!props.has(p_name), false, vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 249 | #ifdef DEBUG_ENABLED |
| 250 | return props[p_name].ignore_value_in_docs; |
| 251 | #else |
| 252 | return false; |
| 253 | #endif // DEBUG_ENABLED |
| 254 | } |
| 255 | |
| 256 | void ProjectSettings::add_hidden_prefix(const String &p_prefix) { |
| 257 | ERR_FAIL_COND_MSG(hidden_prefixes.has(p_prefix), vformat("Hidden prefix '%s' already exists.", p_prefix)); |
| 258 | hidden_prefixes.push_back(p_prefix); |
| 259 | } |
| 260 | |
| 261 | String ProjectSettings::globalize_path(const String &p_path) const { |
| 262 | if (p_path.begins_with("res://")) { |
| 263 | if (!resource_path.is_empty()) { |
| 264 | return p_path.replace("res:/", resource_path); |
| 265 | } |
| 266 | return p_path.replace("res://", ""); |
| 267 | } else if (p_path.begins_with("uid://")) { |
| 268 | const String path = ResourceUID::uid_to_path(p_path); |
| 269 | if (!resource_path.is_empty()) { |
| 270 | return path.replace("res:/", resource_path); |
| 271 | } |
| 272 | return path.replace("res://", ""); |
| 273 | } else if (p_path.begins_with("user://")) { |
| 274 | String data_dir = OS::get_singleton()->get_user_data_dir(); |
| 275 | if (!data_dir.is_empty()) { |
| 276 | return p_path.replace("user:/", data_dir); |
| 277 | } |
| 278 | return p_path.replace("user://", ""); |
| 279 | } |
| 280 | |
| 281 | return p_path; |
| 282 | } |
| 283 | |
| 284 | bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) { |
| 285 | _THREAD_SAFE_METHOD_ |
| 286 | |
| 287 | // Early return if value hasn't changed (unless it's being deleted) |
| 288 | if (p_value.get_type() != Variant::NIL) { |
| 289 | if (props.has(p_name) && props[p_name].variant == p_value) { |
| 290 | return true; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if (p_value.get_type() == Variant::NIL) { |
| 295 | props.erase(p_name); |
| 296 | if (p_name.operator String().begins_with("autoload/")) { |
| 297 | String node_name = p_name.operator String().get_slicec('/', 1); |
| 298 | if (autoloads.has(node_name)) { |
| 299 | remove_autoload(node_name); |
| 300 | } |
| 301 | } else if (p_name.operator String().begins_with("global_group/")) { |
| 302 | String group_name = p_name.operator String().get_slicec('/', 1); |
| 303 | if (global_groups.has(group_name)) { |
| 304 | remove_global_group(group_name); |
| 305 | } |
| 306 | } |
| 307 | } else { |
| 308 | if (p_name == CoreStringName(_custom_features)) { |
| 309 | Vector<String> custom_feature_array = String(p_value).split(","); |
| 310 | for (int i = 0; i < custom_feature_array.size(); i++) { |
| 311 | custom_features.insert(custom_feature_array[i]); |
| 312 | } |
| 313 | |
| 314 | _version++; |
| 315 | _queue_changed(p_name); |
| 316 | return true; |
| 317 | } |
| 318 | |
| 319 | { // Feature overrides. |
| 320 | int dot = p_name.operator String().find_char('.'); |
| 321 | if (dot != -1) { |
| 322 | Vector<String> s = p_name.operator String().split("."); |
| 323 | |
| 324 | for (int i = 1; i < s.size(); i++) { |
| 325 | String feature = s[i].strip_edges(); |
| 326 | Pair<StringName, StringName> feature_override(feature, p_name); |
| 327 | |
| 328 | if (!feature_overrides.has(s[0])) { |
| 329 | feature_overrides[s[0]] = LocalVector<Pair<StringName, StringName>>(); |
| 330 | } |
| 331 | |
| 332 | feature_overrides[s[0]].push_back(feature_override); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if (props.has(p_name)) { |
| 338 | props[p_name].variant = p_value; |
| 339 | } else { |
| 340 | props[p_name] = VariantContainer(p_value, last_order++); |
| 341 | } |
| 342 | if (p_name.operator String().begins_with("autoload_prepend/")) { |
| 343 | String node_name = p_name.operator String().get_slicec('/', 1); |
| 344 | AutoloadInfo autoload; |
| 345 | autoload.name = node_name; |
| 346 | String path = p_value; |
| 347 | if (path.begins_with("*")) { |
| 348 | autoload.is_singleton = true; |
| 349 | autoload.path = path.substr(1).simplify_path(); |
| 350 | } else { |
| 351 | autoload.path = path.simplify_path(); |
| 352 | } |
| 353 | add_autoload(autoload, true); |
| 354 | } else if (p_name.operator String().begins_with("autoload/")) { |
| 355 | String node_name = p_name.operator String().get_slicec('/', 1); |
| 356 | AutoloadInfo autoload; |
| 357 | autoload.name = node_name; |
| 358 | String path = p_value; |
| 359 | if (path.begins_with("*")) { |
| 360 | autoload.is_singleton = true; |
| 361 | autoload.path = path.substr(1).simplify_path(); |
| 362 | } else { |
| 363 | autoload.path = path.simplify_path(); |
| 364 | } |
| 365 | add_autoload(autoload); |
| 366 | } else if (p_name.operator String().begins_with("global_group/")) { |
| 367 | String group_name = p_name.operator String().get_slicec('/', 1); |
| 368 | add_global_group(group_name, p_value); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | _version++; |
| 373 | _queue_changed(p_name); |
| 374 | return true; |
| 375 | } |
| 376 | |
| 377 | bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const { |
| 378 | _THREAD_SAFE_METHOD_ |
| 379 | |
| 380 | if (!props.has(p_name)) { |
| 381 | return false; |
| 382 | } |
| 383 | r_ret = props[p_name].variant; |
| 384 | return true; |
| 385 | } |
| 386 | |
| 387 | Variant ProjectSettings::get_setting_with_override_and_custom_features(const StringName &p_name, const Vector<String> &p_features) const { |
| 388 | _THREAD_SAFE_METHOD_ |
| 389 | |
| 390 | StringName name = p_name; |
| 391 | if (feature_overrides.has(name)) { |
| 392 | const LocalVector<Pair<StringName, StringName>> &overrides = feature_overrides[name]; |
| 393 | for (uint32_t i = 0; i < overrides.size(); i++) { |
| 394 | if (p_features.has(String(overrides[i].first).to_lower())) { |
| 395 | if (props.has(overrides[i].second)) { |
| 396 | name = overrides[i].second; |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (!props.has(name)) { |
| 404 | WARN_PRINT("Property not found: " + String(name)); |
| 405 | return Variant(); |
| 406 | } |
| 407 | return props[name].variant; |
| 408 | } |
| 409 | |
| 410 | Variant ProjectSettings::get_setting_with_override(const StringName &p_name) const { |
| 411 | _THREAD_SAFE_METHOD_ |
| 412 | |
| 413 | const LocalVector<Pair<StringName, StringName>> *overrides = feature_overrides.getptr(p_name); |
| 414 | if (overrides) { |
| 415 | for (uint32_t i = 0; i < overrides->size(); i++) { |
| 416 | if (!OS::get_singleton()->has_feature((*overrides)[i].first)) { |
| 417 | continue; |
| 418 | } |
| 419 | |
| 420 | // Custom features are checked in OS.has_feature() already. No need to check twice. |
| 421 | const RBMap<StringName, VariantContainer>::Element *override_prop = props.find((*overrides)[i].second); |
| 422 | if (override_prop) { |
| 423 | return override_prop->get().variant; |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | const RBMap<StringName, VariantContainer>::Element *prop = props.find(p_name); |
| 429 | if (!prop) { |
| 430 | WARN_PRINT(vformat("Property not found: '%s'.", p_name)); |
| 431 | return Variant(); |
| 432 | } |
| 433 | |
| 434 | return prop->get().variant; |
| 435 | } |
| 436 | |
| 437 | struct _VCSort { |
| 438 | String name; |
| 439 | Variant::Type type = Variant::VARIANT_MAX; |
| 440 | int order = 0; |
| 441 | uint32_t flags = 0; |
| 442 | |
| 443 | bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; } |
| 444 | }; |
| 445 | |
| 446 | void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const { |
| 447 | _THREAD_SAFE_METHOD_ |
| 448 | |
| 449 | RBSet<_VCSort> vclist; |
| 450 | HashMap<String, LocalVector<_VCSort>> setting_overrides; |
| 451 | |
| 452 | for (const KeyValue<StringName, VariantContainer> &E : props) { |
| 453 | const VariantContainer *v = &E.value; |
| 454 | |
| 455 | if (v->hide_from_editor) { |
| 456 | continue; |
| 457 | } |
| 458 | |
| 459 | _VCSort vc; |
| 460 | vc.name = E.key; |
| 461 | vc.order = v->order; |
| 462 | vc.type = v->variant.get_type(); |
| 463 | |
| 464 | bool internal = v->internal; |
| 465 | if (!internal) { |
| 466 | for (const String &F : hidden_prefixes) { |
| 467 | if (vc.name.begins_with(F)) { |
| 468 | internal = true; |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (internal) { |
| 475 | vc.flags = PROPERTY_USAGE_STORAGE; |
| 476 | } else { |
| 477 | vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; |
| 478 | } |
| 479 | |
| 480 | if (v->internal) { |
| 481 | vc.flags |= PROPERTY_USAGE_INTERNAL; |
| 482 | } |
| 483 | |
| 484 | if (v->basic) { |
| 485 | vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING; |
| 486 | } |
| 487 | |
| 488 | if (v->restart_if_changed) { |
| 489 | vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED; |
| 490 | } |
| 491 | |
| 492 | int dot = vc.name.rfind_char('.'); |
| 493 | if (dot != -1) { |
| 494 | StringName n = vc.name.substr(0, dot); |
| 495 | if (props.has(n)) { |
| 496 | // Property is an override. |
| 497 | setting_overrides[n].push_back(vc); |
| 498 | } else { |
| 499 | vclist.insert(vc); |
| 500 | } |
| 501 | } else { |
| 502 | vclist.insert(vc); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | for (const _VCSort &base : vclist) { |
| 507 | if (custom_prop_info.has(base.name)) { |
| 508 | PropertyInfo pi = custom_prop_info[base.name]; |
| 509 | pi.name = base.name; |
| 510 | pi.usage = base.flags; |
| 511 | p_list->push_back(pi); |
| 512 | #ifdef TOOLS_ENABLED |
| 513 | } else if (base.name.begins_with(EDITOR_SETTING_OVERRIDE_PREFIX)) { |
| 514 | PropertyInfo info(base.type, base.name, PROPERTY_HINT_NONE, "", base.flags); |
| 515 | |
| 516 | const PropertyInfo *pi = editor_settings_info.getptr(base.name.trim_prefix(EDITOR_SETTING_OVERRIDE_PREFIX)); |
| 517 | if (pi) { |
| 518 | info.usage = pi->usage; |
| 519 | info.hint = pi->hint; |
| 520 | info.hint_string = pi->hint_string; |
| 521 | } |
| 522 | p_list->push_back(info); |
| 523 | #endif |
| 524 | } else { |
| 525 | p_list->push_back(PropertyInfo(base.type, base.name, PROPERTY_HINT_NONE, "", base.flags)); |
| 526 | } |
| 527 | |
| 528 | if (setting_overrides.has(base.name)) { |
| 529 | for (const _VCSort &over : setting_overrides.get(base.name)) { |
| 530 | if (custom_prop_info.has(over.name)) { |
| 531 | PropertyInfo pi = custom_prop_info[over.name]; |
| 532 | pi.name = over.name; |
| 533 | pi.usage = over.flags; |
| 534 | p_list->push_back(pi); |
| 535 | } else if (custom_prop_info.has(base.name)) { |
| 536 | // Fallback to base property info. |
| 537 | PropertyInfo pi = custom_prop_info[base.name]; |
| 538 | pi.name = over.name; |
| 539 | pi.usage = over.flags; |
| 540 | p_list->push_back(pi); |
| 541 | } else { |
| 542 | p_list->push_back(PropertyInfo(over.type, over.name, PROPERTY_HINT_NONE, "", over.flags)); |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | void ProjectSettings::_queue_changed(const StringName &p_name) { |
| 550 | changed_settings.insert(p_name); |
| 551 | |
| 552 | if (!MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) { |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | // Only queue the deferred call once per frame. |
| 557 | if (!is_changed) { |
| 558 | is_changed = true; |
| 559 | callable_mp(this, &ProjectSettings::_emit_changed).call_deferred(); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | void ProjectSettings::_emit_changed() { |
| 564 | if (!is_changed) { |
| 565 | return; |
| 566 | } |
| 567 | is_changed = false; |
| 568 | |
| 569 | // Emit the general settings_changed signal to indicate changes are complete. |
| 570 | emit_signal("settings_changed"); |
| 571 | |
| 572 | // Clear the changed settings after emitting the signal |
| 573 | changed_settings.clear(); |
| 574 | } |
| 575 | |
| 576 | bool ProjectSettings::load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) { |
| 577 | return ProjectSettings::_load_resource_pack(p_pack, p_replace_files, p_offset, false); |
| 578 | } |
| 579 | |
| 580 | bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset, bool p_main_pack) { |
| 581 | if (PackedData::get_singleton()->is_disabled()) { |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | if (p_pack == "res://") { |
| 586 | // Loading the resource directory as a pack source is reserved for internal use only. |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | if (!p_main_pack && !using_datapack && !OS::get_singleton()->get_resource_dir().is_empty()) { |
| 591 | // Add the project's resource file system to PackedData so directory access keeps working when |
| 592 | // the game is running without a main pack, like in the editor or on Android. |
| 593 | PackedData::get_singleton()->add_pack_source(memnew(PackedSourceDirectory)); |
| 594 | PackedData::get_singleton()->add_pack("res://", false, 0); |
| 595 | DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES); |
| 596 | using_datapack = true; |
| 597 | } |
| 598 | |
| 599 | bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK; |
| 600 | if (!ok) { |
| 601 | return false; |
| 602 | } |
| 603 | |
| 604 | if (project_loaded) { |
| 605 | // This pack may have declared new global classes (make sure they are picked up). |
| 606 | refresh_global_class_list(); |
| 607 | |
| 608 | // This pack may have defined new UIDs, make sure they are cached. |
| 609 | ResourceUID::get_singleton()->load_from_cache(false); |
| 610 | } |
| 611 | |
| 612 | // If the data pack was found, all directory access will be from here. |
| 613 | if (!using_datapack) { |
| 614 | DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES); |
| 615 | using_datapack = true; |
| 616 | } |
| 617 | |
| 618 | return true; |
| 619 | } |
| 620 | |
| 621 | void ProjectSettings::_convert_to_last_version(int p_from_version) { |
| 622 | #ifndef DISABLE_DEPRECATED |
| 623 | if (p_from_version <= 3) { |
| 624 | // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events) |
| 625 | for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) { |
| 626 | Variant value = E.value.variant; |
| 627 | if (String(E.key).begins_with("input/") && value.get_type() == Variant::ARRAY) { |
| 628 | Array array = value; |
| 629 | Dictionary action; |
| 630 | action["deadzone"] = Variant(0.5f); |
| 631 | action["events"] = array; |
| 632 | E.value.variant = action; |
| 633 | } |
| 634 | } |
| 635 | } else if (p_from_version <= 6) { |
| 636 | // Check if we still have legacy boot splash (removed in 4.6), map it to new project setting, then remove legacy setting. |
| 637 | if (has_setting("application/boot_splash/fullsize")) { |
| 638 | set_setting("application/boot_splash/stretch_mode", RenderingServer::map_scaling_option_to_stretch_mode(get_setting("application/boot_splash/fullsize"))); |
| 639 | set_setting("application/boot_splash/fullsize", Variant()); |
| 640 | } |
| 641 | } |
| 642 | #endif // DISABLE_DEPRECATED |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * This method is responsible for loading a project.godot file and/or data file |
| 647 | * using the following merit order: |
| 648 | * - If using NetworkClient, try to lookup project file or fail. |
| 649 | * - If --main-pack was passed by the user (`p_main_pack`), load it or fail. |
| 650 | * - Search for project PCKs automatically. For each step we try loading a potential |
| 651 | * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds, |
| 652 | * we try loading the project settings, and abort if it fails. Steps: |
| 653 | * o Bundled PCK in the executable. |
| 654 | * o [macOS only] PCK with same basename as the binary in the .app resource dir. |
| 655 | * o PCK with same basename as the binary in the binary's directory. We handle both |
| 656 | * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and |
| 657 | * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck'). |
| 658 | * o PCK with the same basename as the binary in the current working directory. |
| 659 | * Same as above for the two possible PCK file names. |
| 660 | * - On Android, look for 'assets.sparsepck' and try loading it, if it doesn't work, |
| 661 | * proceed to the next step. |
| 662 | * - On relevant platforms (Android/iOS), lookup project file in OS resource path. |
| 663 | * If found, load it or fail. |
| 664 | * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we |
| 665 | * are running from source code. |
| 666 | * If not found and `p_upwards` is true, look for project files in parent folders |
| 667 | * up to the system root (used to run a game from command line while in a subfolder). |
| 668 | * If a project file is found, load it or fail. |
| 669 | * If nothing was found, error out. |
| 670 | */ |
| 671 | Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) { |
| 672 | if (!OS::get_singleton()->get_resource_dir().is_empty()) { |
| 673 | // OS will call ProjectSettings->get_resource_path which will be empty if not overridden! |
| 674 | // If the OS would rather use a specific location, then it will not be empty. |
| 675 | resource_path = OS::get_singleton()->get_resource_dir().replace_char('\\', '/'); |
| 676 | if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') { |
| 677 | resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end. |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | // Attempt with a user-defined main pack first |
| 682 | |
| 683 | if (!p_main_pack.is_empty()) { |
| 684 | bool ok = _load_resource_pack(p_main_pack, false, 0, true); |
| 685 | ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack)); |
| 686 | |
| 687 | Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary"); |
| 688 | #ifdef OVERRIDE_ENABLED |
| 689 | if (err == OK && !p_ignore_override) { |
| 690 | // Load override from location of the main pack |
| 691 | // Optional, we don't mind if it fails |
| 692 | bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override"); |
| 693 | if (!disable_override) { |
| 694 | _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg")); |
| 695 | } |
| 696 | } |
| 697 | #endif // OVERRIDE_ENABLED |
| 698 | return err; |
| 699 | } |
| 700 | |
| 701 | String exec_path = OS::get_singleton()->get_executable_path(); |
| 702 | |
| 703 | if (!exec_path.is_empty()) { |
| 704 | // We do several tests sequentially until one succeeds to find a PCK, |
| 705 | // and if so, we attempt loading it at the end. |
| 706 | |
| 707 | // Attempt with PCK bundled into executable. |
| 708 | bool found = _load_resource_pack(exec_path, false, 0, true); |
| 709 | |
| 710 | // Attempt with exec_name.pck. |
| 711 | // (This is the usual case when distributing a Godot game.) |
| 712 | String exec_dir = exec_path.get_base_dir(); |
| 713 | String exec_filename = exec_path.get_file(); |
| 714 | String exec_basename = exec_filename.get_basename(); |
| 715 | |
| 716 | // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle) |
| 717 | // or the exec path's basename + '.pck' (Windows). |
| 718 | // We need to test both possibilities as extensions for Linux binaries are optional |
| 719 | // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck'). |
| 720 | |
| 721 | #if defined(MACOS_ENABLED) || defined(APPLE_EMBEDDED_ENABLED) |
| 722 | if (!found) { |
| 723 | // Attempt to load PCK from macOS .app bundle resources. |
| 724 | found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"), false, 0, true); |
| 725 | } |
| 726 | #endif |
| 727 | |
| 728 | if (!found) { |
| 729 | // Try to load data pack at the location of the executable. |
| 730 | // As mentioned above, we have two potential names to attempt. |
| 731 | found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"), false, 0, true); |
| 732 | } |
| 733 | |
| 734 | if (!found) { |
| 735 | // If we couldn't find them next to the executable, we attempt |
| 736 | // the current working directory. Same story, two tests. |
| 737 | found = _load_resource_pack(exec_basename + ".pck", false, 0, true) || _load_resource_pack(exec_filename + ".pck", false, 0, true); |
| 738 | } |
| 739 | |
| 740 | // If we opened our package, try and load our project. |
| 741 | if (found) { |
| 742 | Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary"); |
| 743 | #ifdef OVERRIDE_ENABLED |
| 744 | if (err == OK && !p_ignore_override) { |
| 745 | // Load overrides from the PCK and the executable location. |
| 746 | // Optional, we don't mind if either fails. |
| 747 | bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override"); |
| 748 | if (!disable_override) { |
| 749 | _load_settings_text("res://override.cfg"); |
| 750 | _load_settings_text(exec_path.get_base_dir().path_join("override.cfg")); |
| 751 | } |
| 752 | } |
| 753 | #endif // OVERRIDE_ENABLED |
| 754 | return err; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | #ifdef ANDROID_ENABLED |
| 759 | // Attempt to load sparse PCK assets. |
| 760 | _load_resource_pack("res://assets.sparsepck", false, 0, true); |
| 761 | #endif |
| 762 | |
| 763 | // Try to use the filesystem for files, according to OS. |
| 764 | // (Only Android -when reading from PCK-.) |
| 765 | |
| 766 | if (!OS::get_singleton()->get_resource_dir().is_empty()) { |
| 767 | Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary"); |
| 768 | #ifdef OVERRIDE_ENABLED |
| 769 | if (err == OK && !p_ignore_override) { |
| 770 | // Optional, we don't mind if it fails. |
| 771 | bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override"); |
| 772 | if (!disable_override) { |
| 773 | _load_settings_text("res://override.cfg"); |
| 774 | } |
| 775 | } |
| 776 | #endif // OVERRIDE_ENABLED |
| 777 | return err; |
| 778 | } |
| 779 | |
| 780 | #if defined(MACOS_ENABLED) || defined(APPLE_EMBEDDED_ENABLED) |
| 781 | // Attempt to load project file from macOS .app bundle resources. |
| 782 | resource_path = OS::get_singleton()->get_bundle_resource_dir(); |
| 783 | if (!resource_path.is_empty()) { |
| 784 | if (resource_path[resource_path.length() - 1] == '/') { |
| 785 | resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end. |
| 786 | } |
| 787 | Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 788 | ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", resource_path)); |
| 789 | d->change_dir(resource_path); |
| 790 | |
| 791 | Error err; |
| 792 | |
| 793 | err = _load_settings_text_or_binary(resource_path.path_join("project.godot"), resource_path.path_join("project.binary")); |
| 794 | if (err == OK && !p_ignore_override) { |
| 795 | // Optional, we don't mind if it fails. |
| 796 | #ifdef OVERRIDE_ENABLED |
| 797 | bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override"); |
| 798 | if (!disable_override) { |
| 799 | _load_settings_text(resource_path.path_join("override.cfg")); |
| 800 | } |
| 801 | #endif // OVERRIDE_ENABLED |
| 802 | return err; |
| 803 | } |
| 804 | } |
| 805 | #endif // MACOS_ENABLED |
| 806 | |
| 807 | // Nothing was found, try to find a project file in provided path (`p_path`) |
| 808 | // or, if requested (`p_upwards`) in parent directories. |
| 809 | |
| 810 | Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 811 | ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", p_path)); |
| 812 | d->change_dir(p_path); |
| 813 | |
| 814 | String current_dir = d->get_current_dir(); |
| 815 | bool found = false; |
| 816 | Error err; |
| 817 | |
| 818 | while (true) { |
| 819 | // Set the resource path early so things can be resolved when loading. |
| 820 | resource_path = current_dir; |
| 821 | resource_path = resource_path.replace_char('\\', '/'); // Windows path to Unix path just in case. |
| 822 | err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary")); |
| 823 | if (err == OK) { |
| 824 | #ifdef OVERRIDE_ENABLED |
| 825 | if (!p_ignore_override) { |
| 826 | // Optional, we don't mind if it fails. |
| 827 | bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override"); |
| 828 | if (!disable_override) { |
| 829 | _load_settings_text(current_dir.path_join("override.cfg")); |
| 830 | } |
| 831 | } |
| 832 | #endif // OVERRIDE_ENABLED |
| 833 | found = true; |
| 834 | break; |
| 835 | } |
| 836 | |
| 837 | #if defined(OVERRIDE_PATH_ENABLED) |
| 838 | if (p_upwards) { |
| 839 | // Try to load settings ascending through parent directories |
| 840 | d->change_dir(".."); |
| 841 | if (d->get_current_dir() == current_dir) { |
| 842 | break; // not doing anything useful |
| 843 | } |
| 844 | current_dir = d->get_current_dir(); |
| 845 | } else { |
| 846 | #else |
| 847 | { |
| 848 | #endif |
| 849 | break; |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if (!found) { |
| 854 | return err; |
| 855 | } |
| 856 | |
| 857 | if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') { |
| 858 | resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end. |
| 859 | } |
| 860 | |
| 861 | return OK; |
| 862 | } |
| 863 | |
| 864 | Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) { |
| 865 | Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override); |
| 866 | #ifdef OVERRIDE_ENABLED |
| 867 | if (err == OK && !p_ignore_override) { |
| 868 | bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override"); |
| 869 | if (!disable_override) { |
| 870 | String custom_settings = GLOBAL_GET("application/config/project_settings_override"); |
| 871 | if (!custom_settings.is_empty()) { |
| 872 | _load_settings_text(custom_settings); |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | #endif |
| 877 | |
| 878 | // Updating the default value after the project settings have loaded. |
| 879 | bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory"); |
| 880 | project_data_dir_name = (use_hidden_directory ? "." : "") + PROJECT_DATA_DIR_NAME_SUFFIX; |
| 881 | |
| 882 | // Using GLOBAL_GET on every block for compressing can be slow, so assigning here. |
| 883 | Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching"); |
| 884 | Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level"); |
| 885 | Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size"); |
| 886 | |
| 887 | Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level"); |
| 888 | |
| 889 | Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level"); |
| 890 | |
| 891 | load_scene_groups_cache(); |
| 892 | |
| 893 | project_loaded = err == OK; |
| 894 | return err; |
| 895 | } |
| 896 | |
| 897 | bool ProjectSettings::has_setting(const String &p_var) const { |
| 898 | _THREAD_SAFE_METHOD_ |
| 899 | |
| 900 | return props.has(p_var); |
| 901 | } |
| 902 | |
| 903 | Error ProjectSettings::_load_settings_binary(const String &p_path) { |
| 904 | Error err; |
| 905 | Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err); |
| 906 | if (err != OK) { |
| 907 | return err; |
| 908 | } |
| 909 | |
| 910 | uint8_t hdr[4]; |
| 911 | f->get_buffer(hdr, 4); |
| 912 | ERR_FAIL_COND_V_MSG((hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G'), ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG)."); |
| 913 | |
| 914 | uint32_t count = f->get_32(); |
| 915 | |
| 916 | for (uint32_t i = 0; i < count; i++) { |
| 917 | uint32_t slen = f->get_32(); |
| 918 | CharString cs; |
| 919 | cs.resize_uninitialized(slen + 1); |
| 920 | cs[slen] = 0; |
| 921 | f->get_buffer((uint8_t *)cs.ptr(), slen); |
| 922 | String key = String::utf8(cs.ptr(), slen); |
| 923 | |
| 924 | uint32_t vlen = f->get_32(); |
| 925 | Vector<uint8_t> d; |
| 926 | d.resize(vlen); |
| 927 | f->get_buffer(d.ptrw(), vlen); |
| 928 | Variant value; |
| 929 | err = decode_variant(value, d.ptr(), d.size(), nullptr, true); |
| 930 | ERR_CONTINUE_MSG(err != OK, vformat("Error decoding property: '%s'.", key)); |
| 931 | set(key, value); |
| 932 | } |
| 933 | |
| 934 | return OK; |
| 935 | } |
| 936 | |
| 937 | Error ProjectSettings::_load_settings_text(const String &p_path) { |
| 938 | Error err; |
| 939 | Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err); |
| 940 | |
| 941 | if (f.is_null()) { |
| 942 | // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing |
| 943 | // This needs to be streamlined if we want decent error reporting |
| 944 | return ERR_FILE_NOT_FOUND; |
| 945 | } |
| 946 | |
| 947 | VariantParser::StreamFile stream; |
| 948 | stream.f = f; |
| 949 | |
| 950 | String assign; |
| 951 | Variant value; |
| 952 | VariantParser::Tag next_tag; |
| 953 | |
| 954 | int lines = 0; |
| 955 | String error_text; |
| 956 | String section; |
| 957 | int config_version = 0; |
| 958 | |
| 959 | while (true) { |
| 960 | assign = Variant(); |
| 961 | next_tag.fields.clear(); |
| 962 | next_tag.name = String(); |
| 963 | |
| 964 | err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true); |
| 965 | if (err == ERR_FILE_EOF) { |
| 966 | // If we're loading a project.godot from source code, we can operate some |
| 967 | // ProjectSettings conversions if need be. |
| 968 | _convert_to_last_version(config_version); |
| 969 | last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot")); |
| 970 | return OK; |
| 971 | } |
| 972 | ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Error parsing '%s' at line %d: %s File might be corrupted.", p_path, lines, error_text)); |
| 973 | |
| 974 | if (!assign.is_empty()) { |
| 975 | if (section.is_empty() && assign == "config_version") { |
| 976 | config_version = value; |
| 977 | ERR_FAIL_COND_V_MSG(config_version > CONFIG_VERSION, ERR_FILE_CANT_OPEN, vformat("Can't open project at '%s', its `config_version` (%d) is from a more recent and incompatible version of the engine. Expected config version: %d.", p_path, config_version, CONFIG_VERSION)); |
| 978 | } else { |
| 979 | if (section.is_empty()) { |
| 980 | set(assign, value); |
| 981 | } else { |
| 982 | set(section + "/" + assign, value); |
| 983 | } |
| 984 | } |
| 985 | } else if (!next_tag.name.is_empty()) { |
| 986 | section = next_tag.name; |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) { |
| 992 | // Attempt first to load the binary project.godot file. |
| 993 | Error err = _load_settings_binary(p_bin_path); |
| 994 | if (err == OK) { |
| 995 | return OK; |
| 996 | } else if (err != ERR_FILE_NOT_FOUND) { |
| 997 | // If the file exists but can't be loaded, we want to know it. |
| 998 | ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_bin_path, err)); |
| 999 | } |
| 1000 | |
| 1001 | // Fallback to text-based project.godot file if binary was not found. |
| 1002 | err = _load_settings_text(p_text_path); |
| 1003 | if (err == OK) { |
| 1004 | #ifndef DISABLE_DEPRECATED |
| 1005 | const PackedStringArray features = get_setting("application/config/features"); |
| 1006 | for (const String &feat : features) { |
| 1007 | if (feat.contains_char('.') && feat.get_slice_count(".") == 2) { |
| 1008 | int major_version = feat.get_slicec('.', 0).to_int(); |
| 1009 | int minor_version = feat.get_slicec('.', 1).to_int(); |
| 1010 | // Major version is irrelevant, but the extra check ensures that the feature is in fact a version string. |
| 1011 | if (major_version == 4 && minor_version < 6) { |
| 1012 | // Enable MeshInstance3D compat for projects created before 4.6. |
| 1013 | set_setting("animation/compatibility/default_parent_skeleton_in_mesh_instance_3d", true); |
| 1014 | } |
| 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | #endif |
| 1019 | return OK; |
| 1020 | } else if (err != ERR_FILE_NOT_FOUND) { |
| 1021 | ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_text_path, err)); |
| 1022 | } |
| 1023 | |
| 1024 | return err; |
| 1025 | } |
| 1026 | |
| 1027 | Error ProjectSettings::load_custom(const String &p_path) { |
| 1028 | if (p_path.ends_with(".binary")) { |
| 1029 | return _load_settings_binary(p_path); |
| 1030 | } |
| 1031 | return _load_settings_text(p_path); |
| 1032 | } |
| 1033 | |
| 1034 | int ProjectSettings::get_order(const String &p_name) const { |
| 1035 | ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 1036 | return props[p_name].order; |
| 1037 | } |
| 1038 | |
| 1039 | void ProjectSettings::set_order(const String &p_name, int p_order) { |
| 1040 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 1041 | props[p_name].order = p_order; |
| 1042 | } |
| 1043 | |
| 1044 | void ProjectSettings::set_builtin_order(const String &p_name) { |
| 1045 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 1046 | if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) { |
| 1047 | props[p_name].order = last_builtin_order++; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | bool ProjectSettings::is_builtin_setting(const String &p_name) const { |
| 1052 | // Return true because a false negative is worse than a false positive. |
| 1053 | ERR_FAIL_COND_V_MSG(!props.has(p_name), true, vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 1054 | return props[p_name].order < NO_BUILTIN_ORDER_BASE; |
| 1055 | } |
| 1056 | |
| 1057 | void ProjectSettings::clear(const String &p_name) { |
| 1058 | ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name)); |
| 1059 | props.erase(p_name); |
| 1060 | } |
| 1061 | |
| 1062 | Error ProjectSettings::save() { |
| 1063 | Error error = save_custom(get_resource_path().path_join("project.godot")); |
| 1064 | if (error == OK) { |
| 1065 | last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot")); |
| 1066 | } |
| 1067 | return error; |
| 1068 | } |
| 1069 | |
| 1070 | Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) { |
| 1071 | Error err; |
| 1072 | Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err); |
| 1073 | ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.binary at '%s'.", p_file)); |
| 1074 | |
| 1075 | uint8_t hdr[4] = { 'E', 'C', 'F', 'G' }; |
| 1076 | file->store_buffer(hdr, 4); |
| 1077 | |
| 1078 | int count = 0; |
| 1079 | |
| 1080 | for (const KeyValue<String, List<String>> &E : p_props) { |
| 1081 | count += E.value.size(); |
| 1082 | } |
| 1083 | |
| 1084 | if (!p_custom_features.is_empty()) { |
| 1085 | // Store how many properties are saved, add one for custom features, which must always go first. |
| 1086 | file->store_32(uint32_t(count + 1)); |
| 1087 | String key = CoreStringName(_custom_features); |
| 1088 | file->store_pascal_string(key); |
| 1089 | |
| 1090 | int len; |
| 1091 | err = encode_variant(p_custom_features, nullptr, len, false); |
| 1092 | ERR_FAIL_COND_V(err != OK, err); |
| 1093 | |
| 1094 | Vector<uint8_t> buff; |
| 1095 | buff.resize(len); |
| 1096 | |
| 1097 | err = encode_variant(p_custom_features, buff.ptrw(), len, false); |
| 1098 | ERR_FAIL_COND_V(err != OK, err); |
| 1099 | file->store_32(uint32_t(len)); |
| 1100 | file->store_buffer(buff.ptr(), buff.size()); |
| 1101 | |
| 1102 | } else { |
| 1103 | // Store how many properties are saved. |
| 1104 | file->store_32(uint32_t(count)); |
| 1105 | } |
| 1106 | |
| 1107 | for (const KeyValue<String, List<String>> &E : p_props) { |
| 1108 | for (const String &key : E.value) { |
| 1109 | String k = key; |
| 1110 | if (!E.key.is_empty()) { |
| 1111 | k = E.key + "/" + k; |
| 1112 | } |
| 1113 | Variant value; |
| 1114 | if (p_custom.has(k)) { |
| 1115 | value = p_custom[k]; |
| 1116 | } else { |
| 1117 | value = get(k); |
| 1118 | } |
| 1119 | |
| 1120 | file->store_pascal_string(k); |
| 1121 | |
| 1122 | int len; |
| 1123 | err = encode_variant(value, nullptr, len, true); |
| 1124 | ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant."); |
| 1125 | |
| 1126 | Vector<uint8_t> buff; |
| 1127 | buff.resize(len); |
| 1128 | |
| 1129 | err = encode_variant(value, buff.ptrw(), len, true); |
| 1130 | ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant."); |
| 1131 | file->store_32(uint32_t(len)); |
| 1132 | file->store_buffer(buff.ptr(), buff.size()); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | return OK; |
| 1137 | } |
| 1138 | |
| 1139 | Error ProjectSettings::_save_settings_text(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) { |
| 1140 | Error err; |
| 1141 | Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err); |
| 1142 | |
| 1143 | ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.godot - %s.", p_file)); |
| 1144 | |
| 1145 | file->store_line("; Engine configuration file."); |
| 1146 | file->store_line("; It's best edited using the editor UI and not directly,"); |
| 1147 | file->store_line("; since the parameters that go here are not all obvious."); |
| 1148 | file->store_line(";"); |
| 1149 | file->store_line("; Format:"); |
| 1150 | file->store_line("; [section] ; section goes between []"); |
| 1151 | file->store_line("; param=value ; assign values to parameters"); |
| 1152 | file->store_line(""); |
| 1153 | |
| 1154 | file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n"); |
| 1155 | if (!p_custom_features.is_empty()) { |
| 1156 | file->store_string("custom_features=\"" + p_custom_features + "\"\n"); |
| 1157 | } |
| 1158 | file->store_string("\n"); |
| 1159 | |
| 1160 | for (const KeyValue<String, List<String>> &E : p_props) { |
| 1161 | if (E.key != p_props.begin()->key) { |
| 1162 | file->store_string("\n"); |
| 1163 | } |
| 1164 | |
| 1165 | if (!E.key.is_empty()) { |
| 1166 | file->store_string("[" + E.key + "]\n\n"); |
| 1167 | } |
| 1168 | for (const String &F : E.value) { |
| 1169 | String key = F; |
| 1170 | if (!E.key.is_empty()) { |
| 1171 | key = E.key + "/" + key; |
| 1172 | } |
| 1173 | Variant value; |
| 1174 | if (p_custom.has(key)) { |
| 1175 | value = p_custom[key]; |
| 1176 | } else { |
| 1177 | value = get(key); |
| 1178 | } |
| 1179 | |
| 1180 | String vstr; |
| 1181 | VariantWriter::write_to_string(value, vstr); |
| 1182 | file->store_string(F.property_name_encode() + "=" + vstr + "\n"); |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | return OK; |
| 1187 | } |
| 1188 | |
| 1189 | Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array? |
| 1190 | return save_custom(p_file); |
| 1191 | } |
| 1192 | |
| 1193 | #ifdef TOOLS_ENABLED |
| 1194 | bool _csproj_exists(const String &p_root_dir) { |
| 1195 | Ref<DirAccess> dir = DirAccess::open(p_root_dir); |
| 1196 | ERR_FAIL_COND_V(dir.is_null(), false); |
| 1197 | |
| 1198 | dir->list_dir_begin(); |
| 1199 | String file_name = dir->_get_next(); |
| 1200 | while (file_name != "") { |
| 1201 | if (!dir->current_is_dir() && file_name.get_extension() == "csproj") { |
| 1202 | return true; |
| 1203 | } |
| 1204 | file_name = dir->_get_next(); |
| 1205 | } |
| 1206 | |
| 1207 | return false; |
| 1208 | } |
| 1209 | #endif // TOOLS_ENABLED |
| 1210 | |
| 1211 | Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) { |
| 1212 | ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Project settings save path cannot be empty."); |
| 1213 | |
| 1214 | #ifdef TOOLS_ENABLED |
| 1215 | PackedStringArray project_features = get_setting("application/config/features"); |
| 1216 | // If there is no feature list currently present, force one to generate. |
| 1217 | if (project_features.is_empty()) { |
| 1218 | project_features = ProjectSettings::get_required_features(); |
| 1219 | } |
| 1220 | // Check the rendering API. |
| 1221 | const String rendering_api = has_setting("rendering/renderer/rendering_method") ? (String)get_setting("rendering/renderer/rendering_method") : String(); |
| 1222 | if (!rendering_api.is_empty()) { |
| 1223 | // Add the rendering API as a project feature if it doesn't already exist. |
| 1224 | if (!project_features.has(rendering_api)) { |
| 1225 | project_features.append(rendering_api); |
| 1226 | } |
| 1227 | } |
| 1228 | // Check for the existence of a csproj file. |
| 1229 | if (_csproj_exists(get_resource_path())) { |
| 1230 | // If there is a csproj file, add the C# feature if it doesn't already exist. |
| 1231 | if (!project_features.has("C#")) { |
| 1232 | project_features.append("C#"); |
| 1233 | } |
| 1234 | } else { |
| 1235 | // If there isn't a csproj file, remove the C# feature if it exists. |
| 1236 | if (project_features.has("C#")) { |
| 1237 | project_features.remove_at(project_features.find("C#")); |
| 1238 | } |
| 1239 | } |
| 1240 | project_features = _trim_to_supported_features(project_features); |
| 1241 | set_setting("application/config/features", project_features); |
| 1242 | #endif // TOOLS_ENABLED |
| 1243 | |
| 1244 | RBSet<_VCSort> vclist; |
| 1245 | |
| 1246 | if (p_merge_with_current) { |
| 1247 | for (const KeyValue<StringName, VariantContainer> &G : props) { |
| 1248 | const VariantContainer *v = &G.value; |
| 1249 | |
| 1250 | if (v->hide_from_editor) { |
| 1251 | continue; |
| 1252 | } |
| 1253 | |
| 1254 | if (p_custom.has(G.key)) { |
| 1255 | continue; |
| 1256 | } |
| 1257 | |
| 1258 | _VCSort vc; |
| 1259 | vc.name = G.key; //*k; |
| 1260 | vc.order = v->order; |
| 1261 | vc.type = v->variant.get_type(); |
| 1262 | vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE; |
| 1263 | if (v->variant == v->initial) { |
| 1264 | continue; |
| 1265 | } |
| 1266 | |
| 1267 | vclist.insert(vc); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | for (const KeyValue<String, Variant> &E : p_custom) { |
| 1272 | // Lookup global prop to store in the same order |
| 1273 | RBMap<StringName, VariantContainer>::Iterator global_prop = props.find(E.key); |
| 1274 | |
| 1275 | _VCSort vc; |
| 1276 | vc.name = E.key; |
| 1277 | vc.order = global_prop ? global_prop->value.order : 0xFFFFFFF; |
| 1278 | vc.type = E.value.get_type(); |
| 1279 | vc.flags = PROPERTY_USAGE_STORAGE; |
| 1280 | vclist.insert(vc); |
| 1281 | } |
| 1282 | |
| 1283 | RBMap<String, List<String>> save_props; |
| 1284 | |
| 1285 | for (const _VCSort &E : vclist) { |
| 1286 | String category = E.name; |
| 1287 | String name = E.name; |
| 1288 | |
| 1289 | int div = category.find_char('/'); |
| 1290 | |
| 1291 | if (div < 0) { |
| 1292 | category = ""; |
| 1293 | } else { |
| 1294 | category = category.substr(0, div); |
| 1295 | name = name.substr(div + 1); |
| 1296 | } |
| 1297 | save_props[category].push_back(name); |
| 1298 | } |
| 1299 | |
| 1300 | String save_features; |
| 1301 | |
| 1302 | for (int i = 0; i < p_custom_features.size(); i++) { |
| 1303 | if (i > 0) { |
| 1304 | save_features += ","; |
| 1305 | } |
| 1306 | |
| 1307 | String f = p_custom_features[i].strip_edges().remove_char('\"'); |
| 1308 | save_features += f; |
| 1309 | } |
| 1310 | |
| 1311 | if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) { |
| 1312 | return _save_settings_text(p_path, save_props, p_custom, save_features); |
| 1313 | } else if (p_path.ends_with(".binary")) { |
| 1314 | return _save_settings_binary(p_path, save_props, p_custom, save_features); |
| 1315 | } else { |
| 1316 | ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, vformat("Unknown config file format: '%s'.", p_path)); |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) { |
| 1321 | Variant ret; |
| 1322 | if (!ProjectSettings::get_singleton()->has_setting(p_var)) { |
| 1323 | ProjectSettings::get_singleton()->set(p_var, p_default); |
| 1324 | } |
| 1325 | ret = GLOBAL_GET(p_var); |
| 1326 | |
| 1327 | ProjectSettings::get_singleton()->set_initial_value(p_var, p_default); |
| 1328 | ProjectSettings::get_singleton()->set_builtin_order(p_var); |
| 1329 | ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic); |
| 1330 | ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed); |
| 1331 | ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs); |
| 1332 | ProjectSettings::get_singleton()->set_as_internal(p_var, p_internal); |
| 1333 | return ret; |
| 1334 | } |
| 1335 | |
| 1336 | Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) { |
| 1337 | Variant ret = _GLOBAL_DEF(p_info.name, p_default, p_restart_if_changed, p_ignore_value_in_docs, p_basic, p_internal); |
| 1338 | ProjectSettings::get_singleton()->set_custom_property_info(p_info); |
| 1339 | return ret; |
| 1340 | } |
| 1341 | |
| 1342 | void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) { |
| 1343 | ERR_FAIL_COND_MSG(!p_info.has("name"), "Property info is missing \"name\" field."); |
| 1344 | ERR_FAIL_COND_MSG(!p_info.has("type"), "Property info is missing \"type\" field."); |
| 1345 | |
| 1346 | if (p_info.has("usage")) { |
| 1347 | WARN_PRINT("\"usage\" is not supported in add_property_info()."); |
| 1348 | } |
| 1349 | |
| 1350 | PropertyInfo pinfo; |
| 1351 | pinfo.name = p_info["name"]; |
| 1352 | ERR_FAIL_COND(!props.has(pinfo.name)); |
| 1353 | pinfo.type = Variant::Type(p_info["type"].operator int()); |
| 1354 | ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX); |
| 1355 | |
| 1356 | if (p_info.has("hint")) { |
| 1357 | pinfo.hint = PropertyHint(p_info["hint"].operator int()); |
| 1358 | } |
| 1359 | if (p_info.has("hint_string")) { |
| 1360 | pinfo.hint_string = p_info["hint_string"]; |
| 1361 | } |
| 1362 | |
| 1363 | set_custom_property_info(pinfo); |
| 1364 | } |
| 1365 | |
| 1366 | void ProjectSettings::set_custom_property_info(const PropertyInfo &p_info) { |
| 1367 | const String &prop_name = p_info.name; |
| 1368 | ERR_FAIL_COND(!props.has(prop_name)); |
| 1369 | custom_prop_info[prop_name] = p_info; |
| 1370 | } |
| 1371 | |
| 1372 | const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const { |
| 1373 | return custom_prop_info; |
| 1374 | } |
| 1375 | |
| 1376 | bool ProjectSettings::is_using_datapack() const { |
| 1377 | return using_datapack; |
| 1378 | } |
| 1379 | |
| 1380 | bool ProjectSettings::is_project_loaded() const { |
| 1381 | return project_loaded; |
| 1382 | } |
| 1383 | |
| 1384 | bool ProjectSettings::_property_can_revert(const StringName &p_name) const { |
| 1385 | return props.has(p_name) && !String(p_name).begins_with(EDITOR_SETTING_OVERRIDE_PREFIX); |
| 1386 | } |
| 1387 | |
| 1388 | bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const { |
| 1389 | const RBMap<StringName, ProjectSettings::VariantContainer>::Element *value = props.find(p_name); |
| 1390 | if (value) { |
| 1391 | r_property = value->value().initial.duplicate(); |
| 1392 | return true; |
| 1393 | } |
| 1394 | return false; |
| 1395 | } |
| 1396 | |
| 1397 | void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) { |
| 1398 | set(p_setting, p_value); |
| 1399 | } |
| 1400 | |
| 1401 | Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_default_value) const { |
| 1402 | if (has_setting(p_setting)) { |
| 1403 | return get(p_setting); |
| 1404 | } else { |
| 1405 | return p_default_value; |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | PackedStringArray ProjectSettings::get_changed_settings() const { |
| 1410 | PackedStringArray arr; |
| 1411 | for (const StringName &setting : changed_settings) { |
| 1412 | arr.push_back(setting); |
| 1413 | } |
| 1414 | return arr; |
| 1415 | } |
| 1416 | |
| 1417 | bool ProjectSettings::check_changed_settings_in_group(const String &p_setting_prefix) const { |
| 1418 | for (const StringName &setting : changed_settings) { |
| 1419 | if (String(setting).begins_with(p_setting_prefix)) { |
| 1420 | return true; |
| 1421 | } |
| 1422 | } |
| 1423 | return false; |
| 1424 | } |
| 1425 | |
| 1426 | void ProjectSettings::refresh_global_class_list() { |
| 1427 | // This is called after mounting a new PCK file to pick up class changes. |
| 1428 | is_global_class_list_loaded = false; // Make sure we read from the freshly mounted PCK. |
| 1429 | Array script_classes = get_global_class_list(); |
| 1430 | for (int i = 0; i < script_classes.size(); i++) { |
| 1431 | Dictionary c = script_classes[i]; |
| 1432 | if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base") || !c.has("is_abstract") || !c.has("is_tool")) { |
| 1433 | continue; |
| 1434 | } |
| 1435 | ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"], c["is_abstract"], c["is_tool"]); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | TypedArray<Dictionary> ProjectSettings::get_global_class_list() { |
| 1440 | if (is_global_class_list_loaded) { |
| 1441 | return global_class_list; |
| 1442 | } |
| 1443 | |
| 1444 | Ref<ConfigFile> cf; |
| 1445 | cf.instantiate(); |
| 1446 | if (cf->load(get_global_class_list_path()) == OK) { |
| 1447 | global_class_list = cf->get_value("", "list", Array()); |
| 1448 | } else { |
| 1449 | #ifndef TOOLS_ENABLED |
| 1450 | // Script classes can't be recreated in exported project, so print an error. |
| 1451 | ERR_PRINT("Could not load global script cache."); |
| 1452 | #endif |
| 1453 | } |
| 1454 | |
| 1455 | // File read succeeded or failed. If it failed, assume everything is still okay. |
| 1456 | // We will later receive updated class data in store_global_class_list(). |
| 1457 | is_global_class_list_loaded = true; |
| 1458 | |
| 1459 | return global_class_list; |
| 1460 | } |
| 1461 | |
| 1462 | String ProjectSettings::get_global_class_list_path() const { |
| 1463 | return get_project_data_path().path_join("global_script_class_cache.cfg"); |
| 1464 | } |
| 1465 | |
| 1466 | void ProjectSettings::store_global_class_list(const Array &p_classes) { |
| 1467 | Ref<ConfigFile> cf; |
| 1468 | cf.instantiate(); |
| 1469 | cf->set_value("", "list", p_classes); |
| 1470 | cf->save(get_global_class_list_path()); |
| 1471 | |
| 1472 | global_class_list = p_classes; |
| 1473 | } |
| 1474 | |
| 1475 | bool ProjectSettings::has_custom_feature(const String &p_feature) const { |
| 1476 | return custom_features.has(p_feature); |
| 1477 | } |
| 1478 | |
| 1479 | const HashMap<StringName, ProjectSettings::AutoloadInfo> &ProjectSettings::get_autoload_list() const { |
| 1480 | return autoloads; |
| 1481 | } |
| 1482 | |
| 1483 | void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload, bool p_front_insert) { |
| 1484 | ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name."); |
| 1485 | if (p_front_insert) { |
| 1486 | if (autoloads.has(p_autoload.name)) { |
| 1487 | autoloads.erase(p_autoload.name); |
| 1488 | } |
| 1489 | autoloads.insert(p_autoload.name, p_autoload, true); |
| 1490 | } else { |
| 1491 | autoloads[p_autoload.name] = p_autoload; |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | void ProjectSettings::remove_autoload(const StringName &p_autoload) { |
| 1496 | ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload."); |
| 1497 | autoloads.erase(p_autoload); |
| 1498 | } |
| 1499 | |
| 1500 | bool ProjectSettings::has_autoload(const StringName &p_autoload) const { |
| 1501 | return autoloads.has(p_autoload); |
| 1502 | } |
| 1503 | |
| 1504 | ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const { |
| 1505 | ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload."); |
| 1506 | return autoloads[p_name]; |
| 1507 | } |
| 1508 | |
| 1509 | void ProjectSettings::fix_autoload_paths() { |
| 1510 | for (KeyValue<StringName, AutoloadInfo> &kv : autoloads) { |
| 1511 | kv.value.path = ResourceUID::ensure_path(kv.value.path); |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | const HashMap<StringName, String> &ProjectSettings::get_global_groups_list() const { |
| 1516 | return global_groups; |
| 1517 | } |
| 1518 | |
| 1519 | void ProjectSettings::add_global_group(const StringName &p_name, const String &p_description) { |
| 1520 | ERR_FAIL_COND_MSG(p_name == StringName(), "Trying to add global group with no name."); |
| 1521 | global_groups[p_name] = p_description; |
| 1522 | } |
| 1523 | |
| 1524 | void ProjectSettings::remove_global_group(const StringName &p_name) { |
| 1525 | ERR_FAIL_COND_MSG(!global_groups.has(p_name), "Trying to remove non-existent global group."); |
| 1526 | global_groups.erase(p_name); |
| 1527 | } |
| 1528 | |
| 1529 | bool ProjectSettings::has_global_group(const StringName &p_name) const { |
| 1530 | return global_groups.has(p_name); |
| 1531 | } |
| 1532 | |
| 1533 | void ProjectSettings::remove_scene_groups_cache(const StringName &p_path) { |
| 1534 | scene_groups_cache.erase(p_path); |
| 1535 | } |
| 1536 | |
| 1537 | void ProjectSettings::add_scene_groups_cache(const StringName &p_path, const HashSet<StringName> &p_cache) { |
| 1538 | scene_groups_cache[p_path] = p_cache; |
| 1539 | } |
| 1540 | |
| 1541 | void ProjectSettings::save_scene_groups_cache() { |
| 1542 | Ref<ConfigFile> cf; |
| 1543 | cf.instantiate(); |
| 1544 | for (const KeyValue<StringName, HashSet<StringName>> &E : scene_groups_cache) { |
| 1545 | if (E.value.is_empty()) { |
| 1546 | continue; |
| 1547 | } |
| 1548 | Array list; |
| 1549 | for (const StringName &group : E.value) { |
| 1550 | list.push_back(group); |
| 1551 | } |
| 1552 | cf->set_value(E.key, "groups", list); |
| 1553 | } |
| 1554 | cf->save(get_scene_groups_cache_path()); |
| 1555 | } |
| 1556 | |
| 1557 | String ProjectSettings::get_scene_groups_cache_path() const { |
| 1558 | return get_project_data_path().path_join("scene_groups_cache.cfg"); |
| 1559 | } |
| 1560 | |
| 1561 | void ProjectSettings::load_scene_groups_cache() { |
| 1562 | Ref<ConfigFile> cf; |
| 1563 | cf.instantiate(); |
| 1564 | if (cf->load(get_scene_groups_cache_path()) == OK) { |
| 1565 | Vector<String> scene_paths = cf->get_sections(); |
| 1566 | for (const String &E : scene_paths) { |
| 1567 | Array scene_groups = cf->get_value(E, "groups", Array()); |
| 1568 | HashSet<StringName> cache; |
| 1569 | for (const Variant &scene_group : scene_groups) { |
| 1570 | cache.insert(scene_group); |
| 1571 | } |
| 1572 | add_scene_groups_cache(E, cache); |
| 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | const HashMap<StringName, HashSet<StringName>> &ProjectSettings::get_scene_groups_cache() const { |
| 1578 | return scene_groups_cache; |
| 1579 | } |
| 1580 | |
| 1581 | #ifdef TOOLS_ENABLED |
| 1582 | void ProjectSettings::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { |
| 1583 | const String pf = p_function; |
| 1584 | if (p_idx == 0) { |
| 1585 | if (pf == "has_setting" || pf == "set_setting" || pf == "get_setting" || pf == "get_setting_with_override" || |
| 1586 | pf == "set_order" || pf == "get_order" || pf == "set_initial_value" || pf == "set_as_basic" || |
| 1587 | pf == "set_as_internal" || pf == "set_restart_if_changed" || pf == "clear") { |
| 1588 | for (const KeyValue<StringName, VariantContainer> &E : props) { |
| 1589 | if (E.value.hide_from_editor) { |
| 1590 | continue; |
| 1591 | } |
| 1592 | |
| 1593 | r_options->push_back(String(E.key).quote()); |
| 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | Object::get_argument_options(p_function, p_idx, r_options); |
| 1598 | } |
| 1599 | #endif |
| 1600 | |
| 1601 | void ProjectSettings::set_editor_setting_override(const String &p_setting, const Variant &p_value) { |
| 1602 | set_setting(EDITOR_SETTING_OVERRIDE_PREFIX + p_setting, p_value); |
| 1603 | } |
| 1604 | |
| 1605 | bool ProjectSettings::has_editor_setting_override(const String &p_setting) const { |
| 1606 | return has_setting(EDITOR_SETTING_OVERRIDE_PREFIX + p_setting); |
| 1607 | } |
| 1608 | |
| 1609 | Variant ProjectSettings::get_editor_setting_override(const String &p_setting) const { |
| 1610 | return get_setting(EDITOR_SETTING_OVERRIDE_PREFIX + p_setting); |
| 1611 | } |
| 1612 | |
| 1613 | void ProjectSettings::_bind_methods() { |
| 1614 | ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting); |
| 1615 | ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting); |
| 1616 | ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant())); |
| 1617 | ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override); |
| 1618 | ClassDB::bind_method(D_METHOD("get_global_class_list"), &ProjectSettings::get_global_class_list); |
| 1619 | ClassDB::bind_method(D_METHOD("get_setting_with_override_and_custom_features", "name", "features"), &ProjectSettings::get_setting_with_override_and_custom_features); |
| 1620 | ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order); |
| 1621 | ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order); |
| 1622 | ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value); |
| 1623 | ClassDB::bind_method(D_METHOD("set_as_basic", "name", "basic"), &ProjectSettings::set_as_basic); |
| 1624 | ClassDB::bind_method(D_METHOD("set_as_internal", "name", "internal"), &ProjectSettings::set_as_internal); |
| 1625 | ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind); |
| 1626 | ClassDB::bind_method(D_METHOD("set_restart_if_changed", "name", "restart"), &ProjectSettings::set_restart_if_changed); |
| 1627 | ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear); |
| 1628 | ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path); |
| 1629 | ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path); |
| 1630 | ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save); |
| 1631 | ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::load_resource_pack, DEFVAL(true), DEFVAL(0)); |
| 1632 | |
| 1633 | ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd); |
| 1634 | |
| 1635 | // Change tracking methods |
| 1636 | ClassDB::bind_method(D_METHOD("get_changed_settings"), &ProjectSettings::get_changed_settings); |
| 1637 | ClassDB::bind_method(D_METHOD("check_changed_settings_in_group", "setting_prefix"), &ProjectSettings::check_changed_settings_in_group); |
| 1638 | ADD_SIGNAL(MethodInfo("settings_changed")); |
| 1639 | } |
| 1640 | |
| 1641 | void ProjectSettings::_add_builtin_input_map() { |
| 1642 | if (InputMap::get_singleton()) { |
| 1643 | HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins(); |
| 1644 | |
| 1645 | for (KeyValue<String, List<Ref<InputEvent>>> &E : builtins) { |
| 1646 | Array events; |
| 1647 | |
| 1648 | // Convert list of input events into array |
| 1649 | for (const Ref<InputEvent> &event : E.value) { |
| 1650 | events.push_back(event); |
| 1651 | } |
| 1652 | |
| 1653 | Dictionary action; |
| 1654 | action["deadzone"] = Variant(InputMap::DEFAULT_TOGGLE_DEADZONE); |
| 1655 | action["events"] = events; |
| 1656 | |
| 1657 | String action_name = "input/" + E.key; |
| 1658 | GLOBAL_DEF(action_name, action); |
| 1659 | input_presets.push_back(action_name); |
| 1660 | } |
| 1661 | } |
| 1662 | } |
| 1663 | |
| 1664 | ProjectSettings::ProjectSettings() { |
| 1665 | // Initialization of engine variables should be done in the setup() method, |
| 1666 | // so that the values can be overridden from project.godot or project.binary. |
| 1667 | |
| 1668 | CRASH_COND_MSG(singleton != nullptr, "Instantiating a new ProjectSettings singleton is not supported."); |
| 1669 | singleton = this; |
| 1670 | |
| 1671 | #ifdef TOOLS_ENABLED |
| 1672 | // Available only at runtime in editor builds. Needs to be processed before anything else to work properly. |
| 1673 | if (!Engine::get_singleton()->is_editor_hint()) { |
| 1674 | String editor_features = OS::get_singleton()->get_environment("GODOT_EDITOR_CUSTOM_FEATURES"); |
| 1675 | if (!editor_features.is_empty()) { |
| 1676 | PackedStringArray feature_list = editor_features.split(","); |
| 1677 | for (const String &s : feature_list) { |
| 1678 | custom_features.insert(s); |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | #endif |
| 1683 | |
| 1684 | GLOBAL_DEF_BASIC("application/config/name", ""); |
| 1685 | GLOBAL_DEF(PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()); |
| 1686 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT), ""); |
| 1687 | GLOBAL_DEF_BASIC("application/config/version", ""); |
| 1688 | GLOBAL_DEF_INTERNAL(PropertyInfo(Variant::STRING, "application/config/tags"), PackedStringArray()); |
| 1689 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), ""); |
| 1690 | GLOBAL_DEF("application/run/disable_stdout", false); |
| 1691 | GLOBAL_DEF("application/run/disable_stderr", false); |
| 1692 | GLOBAL_DEF("application/run/print_header", true); |
| 1693 | GLOBAL_DEF("application/run/enable_alt_space_menu", false); |
| 1694 | GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true); |
| 1695 | GLOBAL_DEF("application/config/use_custom_user_dir", false); |
| 1696 | GLOBAL_DEF("application/config/custom_user_dir_name", ""); |
| 1697 | GLOBAL_DEF("application/config/project_settings_override", ""); |
| 1698 | GLOBAL_DEF("application/config/disable_project_settings_override", false); |
| 1699 | |
| 1700 | GLOBAL_DEF("application/run/main_loop_type", "SceneTree"); |
| 1701 | GLOBAL_DEF("application/config/auto_accept_quit", true); |
| 1702 | GLOBAL_DEF("application/config/quit_on_go_back", true); |
| 1703 | |
| 1704 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "accessibility/general/accessibility_support", PROPERTY_HINT_ENUM, "Auto (When Screen Reader is Running),Always Active,Disabled"), 0); |
| 1705 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "accessibility/general/updates_per_second", PROPERTY_HINT_RANGE, "1,100,1"), 60); |
| 1706 | |
| 1707 | // The default window size is tuned to: |
| 1708 | // - Have a 16:9 aspect ratio, |
| 1709 | // - Have both dimensions divisible by 8 to better play along with video recording, |
| 1710 | // - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings). |
| 1711 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "1,7680,1,or_greater"), 1152); // 8K resolution |
| 1712 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "1,4320,1,or_greater"), 648); // 8K resolution |
| 1713 | |
| 1714 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), 0); |
| 1715 | |
| 1716 | // Keep the enum values in sync with the `Window::WINDOW_INITIAL_POSITION_` enum. |
| 1717 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_position_type", PROPERTY_HINT_ENUM, "Absolute:0,Center of Primary Screen:1,Center of Other Screen:3,Center of Screen With Mouse Pointer:4,Center of Screen With Keyboard Focus:5"), 1); |
| 1718 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR2I, "display/window/size/initial_position"), Vector2i()); |
| 1719 | // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum. |
| 1720 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), 0); |
| 1721 | |
| 1722 | GLOBAL_DEF_BASIC("display/window/size/resizable", true); |
| 1723 | GLOBAL_DEF_BASIC("display/window/size/borderless", false); |
| 1724 | GLOBAL_DEF("display/window/size/always_on_top", false); |
| 1725 | GLOBAL_DEF("display/window/size/transparent", false); |
| 1726 | GLOBAL_DEF("display/window/size/extend_to_title", false); |
| 1727 | GLOBAL_DEF("display/window/size/no_focus", false); |
| 1728 | GLOBAL_DEF("display/window/size/sharp_corners", false); |
| 1729 | GLOBAL_DEF("display/window/size/minimize_disabled", false); |
| 1730 | GLOBAL_DEF("display/window/size/maximize_disabled", false); |
| 1731 | |
| 1732 | GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution |
| 1733 | GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution |
| 1734 | |
| 1735 | GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true); |
| 1736 | GLOBAL_DEF("animation/warnings/check_invalid_track_paths", true); |
| 1737 | GLOBAL_DEF("animation/warnings/check_angle_interpolation_type_conflicting", true); |
| 1738 | #ifndef DISABLE_DEPRECATED |
| 1739 | GLOBAL_DEF_RST("animation/compatibility/default_parent_skeleton_in_mesh_instance_3d", false); |
| 1740 | #endif |
| 1741 | |
| 1742 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"), "res://default_bus_layout.tres"); |
| 1743 | GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type", PROPERTY_HINT_ENUM, "Stream,Sample"), 0); |
| 1744 | GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type.web", PROPERTY_HINT_ENUM, "Stream,Sample"), 1); |
| 1745 | GLOBAL_DEF_RST("audio/general/text_to_speech", false); |
| 1746 | GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f); |
| 1747 | GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f); |
| 1748 | |
| 1749 | GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/ios/session_category", PROPERTY_HINT_ENUM, "Ambient,Multi Route,Play and Record,Playback,Record,Solo Ambient"), 0); |
| 1750 | GLOBAL_DEF("audio/general/ios/mix_with_others", false); |
| 1751 | |
| 1752 | _add_builtin_input_map(); |
| 1753 | |
| 1754 | // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum. |
| 1755 | custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"); |
| 1756 | GLOBAL_DEF("display/window/subwindows/embed_subwindows", true); |
| 1757 | // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum. |
| 1758 | custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox"); |
| 1759 | |
| 1760 | GLOBAL_DEF("display/window/frame_pacing/android/enable_frame_pacing", true); |
| 1761 | GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/frame_pacing/android/swappy_mode", PROPERTY_HINT_ENUM, "pipeline_forced_on,auto_fps_pipeline_forced_on,auto_fps_auto_pipeline"), 2); |
| 1762 | |
| 1763 | #ifdef DISABLE_DEPRECATED |
| 1764 | custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Safe:1,Separate"); |
| 1765 | #else |
| 1766 | custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Unsafe (deprecated),Safe,Separate"); |
| 1767 | #endif |
| 1768 | |
| 1769 | #ifndef PHYSICS_2D_DISABLED |
| 1770 | GLOBAL_DEF("physics/2d/run_on_separate_thread", false); |
| 1771 | #endif // PHYSICS_2D_DISABLED |
| 1772 | #ifndef PHYSICS_3D_DISABLED |
| 1773 | GLOBAL_DEF("physics/3d/run_on_separate_thread", false); |
| 1774 | #endif // PHYSICS_3D_DISABLED |
| 1775 | |
| 1776 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport"), "disabled"); |
| 1777 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand"), "keep"); |
| 1778 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "display/window/stretch/scale", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), 1.0); |
| 1779 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/scale_mode", PROPERTY_HINT_ENUM, "fractional,integer"), "fractional"); |
| 1780 | |
| 1781 | GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"), 16384); |
| 1782 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "debug/settings/profiler/max_timestamp_query_elements", PROPERTY_HINT_RANGE, "256,65535,1"), 256); |
| 1783 | |
| 1784 | GLOBAL_DEF(PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"), Compression::zstd_long_distance_matching); |
| 1785 | GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"), Compression::zstd_level); |
| 1786 | GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"), Compression::zstd_window_log_size); |
| 1787 | GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::zlib_level); |
| 1788 | GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::gzip_level); |
| 1789 | |
| 1790 | GLOBAL_DEF("debug/settings/crash_handler/message", |
| 1791 | String("Please include this when reporting the bug to the project developer.")); |
| 1792 | GLOBAL_DEF("debug/settings/crash_handler/message.editor", |
| 1793 | String("Please include this when reporting the bug on: https://github.com/godotengine/godot/issues")); |
| 1794 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/occlusion_culling/bvh_build_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), 2); |
| 1795 | GLOBAL_DEF_RST("rendering/occlusion_culling/jitter_projection", true); |
| 1796 | |
| 1797 | GLOBAL_DEF_RST("internationalization/rendering/force_right_to_left_layout_direction", false); |
| 1798 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "internationalization/rendering/root_node_layout_direction", PROPERTY_HINT_ENUM, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale"), 0); |
| 1799 | GLOBAL_DEF_BASIC("internationalization/rendering/root_node_auto_translate", true); |
| 1800 | |
| 1801 | GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/timers/incremental_search_max_interval_msec", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"), 2000); |
| 1802 | GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5); |
| 1803 | #ifdef TOOLS_ENABLED |
| 1804 | GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5); |
| 1805 | #endif |
| 1806 | |
| 1807 | GLOBAL_DEF("gui/common/drag_threshold", 10); |
| 1808 | GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true); |
| 1809 | GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/common/show_focus_state_on_pointer_event", PROPERTY_HINT_ENUM, "Never,Control Supports Keyboard Input,Always"), 1); |
| 1810 | GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true); |
| 1811 | |
| 1812 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/frame_queue_size", PROPERTY_HINT_RANGE, "2,3,1"), 2); |
| 1813 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/swapchain_image_count", PROPERTY_HINT_RANGE, "2,4,1"), 3); |
| 1814 | GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/block_size_kb", PROPERTY_HINT_RANGE, "4,2048,1,or_greater"), 256); |
| 1815 | GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/max_size_mb", PROPERTY_HINT_RANGE, "1,1024,1,or_greater"), 128); |
| 1816 | GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_upload_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64); |
| 1817 | GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_download_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64); |
| 1818 | GLOBAL_DEF_RST(PropertyInfo(Variant::BOOL, "rendering/rendering_device/pipeline_cache/enable"), true); |
| 1819 | GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/rendering_device/pipeline_cache/save_chunk_size_mb", PROPERTY_HINT_RANGE, "0.000001,64.0,0.001,or_greater"), 3.0); |
| 1820 | GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/vulkan/max_descriptors_per_pool", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64); |
| 1821 | |
| 1822 | GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_resource_descriptors", 65536); |
| 1823 | custom_prop_info["rendering/rendering_device/d3d12/max_resource_descriptors"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_resource_descriptors", PROPERTY_HINT_RANGE, "512,1000000"); |
| 1824 | GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_sampler_descriptors", 1024); |
| 1825 | custom_prop_info["rendering/rendering_device/d3d12/max_sampler_descriptors"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_sampler_descriptors", PROPERTY_HINT_RANGE, "256,2048"); |
| 1826 | |
| 1827 | // The default value must match the minor part of the Agility SDK version |
| 1828 | // installed by the scripts provided in the repository |
| 1829 | // (check `misc/scripts/install_d3d12_sdk_windows.py`). |
| 1830 | // For example, if the script installs 1.618.5, the default value must be 618. |
| 1831 | GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/agility_sdk_version", PROPERTY_HINT_RANGE, "0,10000,1,or_greater,hide_control"), 618); |
| 1832 | |
| 1833 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), 1); |
| 1834 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror"), 0); |
| 1835 | |
| 1836 | GLOBAL_DEF("collada/use_ambient", false); |
| 1837 | |
| 1838 | // Input settings |
| 1839 | GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_long_press_as_right_click", false); |
| 1840 | GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_pan_and_scale_gestures", false); |
| 1841 | GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "input_devices/pointing/android/rotary_input_scroll_axis", PROPERTY_HINT_ENUM, "Horizontal,Vertical"), 1); |
| 1842 | GLOBAL_DEF("input_devices/pointing/android/override_volume_buttons", false); |
| 1843 | GLOBAL_DEF_BASIC("input_devices/pointing/android/disable_scroll_deadzone", false); |
| 1844 | |
| 1845 | // These properties will not show up in the dialog. If you want to exclude whole groups, use add_hidden_prefix(). |
| 1846 | GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray()); |
| 1847 | GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray()); |
| 1848 | GLOBAL_DEF_INTERNAL("internationalization/locale/translations", PackedStringArray()); |
| 1849 | GLOBAL_DEF_INTERNAL("internationalization/locale/translations_pot_files", PackedStringArray()); |
| 1850 | GLOBAL_DEF_INTERNAL("internationalization/locale/translation_add_builtin_strings_to_pot", false); |
| 1851 | |
| 1852 | #if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) |
| 1853 | GLOBAL_DEF("navigation/world/map_use_async_iterations", true); |
| 1854 | GLOBAL_DEF("navigation/world/region_use_async_iterations", true); |
| 1855 | |
| 1856 | GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_multiple_threads", true); |
| 1857 | GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_high_priority_threads", true); |
| 1858 | |
| 1859 | GLOBAL_DEF("navigation/pathfinding/max_threads", 4); |
| 1860 | |
| 1861 | GLOBAL_DEF("navigation/baking/use_crash_prevention_checks", true); |
| 1862 | GLOBAL_DEF("navigation/baking/thread_model/baking_use_multiple_threads", true); |
| 1863 | GLOBAL_DEF("navigation/baking/thread_model/baking_use_high_priority_threads", true); |
| 1864 | #endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) |
| 1865 | #ifndef NAVIGATION_2D_DISABLED |
| 1866 | GLOBAL_DEF("navigation/2d/warnings/navmesh_edge_merge_errors", true); |
| 1867 | GLOBAL_DEF("navigation/2d/warnings/navmesh_cell_size_mismatch", true); |
| 1868 | #endif // NAVIGATION_2D_DISABLED |
| 1869 | #ifndef NAVIGATION_3D_DISABLED |
| 1870 | GLOBAL_DEF("navigation/3d/warnings/navmesh_edge_merge_errors", true); |
| 1871 | GLOBAL_DEF("navigation/3d/warnings/navmesh_cell_size_mismatch", true); |
| 1872 | #endif // NAVIGATION_3D_DISABLED |
| 1873 | |
| 1874 | ProjectSettings::get_singleton()->add_hidden_prefix("input/"); |
| 1875 | } |
| 1876 | |
| 1877 | ProjectSettings::ProjectSettings(const String &p_path) { |
| 1878 | if (load_custom(p_path) == OK) { |
| 1879 | resource_path = p_path.get_base_dir(); |
| 1880 | project_loaded = true; |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | ProjectSettings::~ProjectSettings() { |
| 1885 | if (singleton == this) { |
| 1886 | singleton = nullptr; |
| 1887 | } |
| 1888 | } |