project_settings.cpp 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  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. #include "project_settings.h"
  31. #include "core/core_bind.h" // For Compression enum.
  32. #include "core/input/input_map.h"
  33. #include "core/io/config_file.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_pack.h"
  37. #include "core/io/marshalls.h"
  38. #include "core/io/resource_uid.h"
  39. #include "core/object/script_language.h"
  40. #include "core/templates/rb_set.h"
  41. #include "core/variant/typed_array.h"
  42. #include "core/variant/variant_parser.h"
  43. #include "core/version.h"
  44. #ifdef TOOLS_ENABLED
  45. #include "modules/modules_enabled.gen.h" // For mono.
  46. #endif // TOOLS_ENABLED
  47. const String ProjectSettings::PROJECT_DATA_DIR_NAME_SUFFIX = "godot";
  48. ProjectSettings *ProjectSettings::singleton = nullptr;
  49. ProjectSettings *ProjectSettings::get_singleton() {
  50. return singleton;
  51. }
  52. String ProjectSettings::get_project_data_dir_name() const {
  53. return project_data_dir_name;
  54. }
  55. String ProjectSettings::get_project_data_path() const {
  56. return "res://" + get_project_data_dir_name();
  57. }
  58. String ProjectSettings::get_resource_path() const {
  59. return resource_path;
  60. }
  61. String ProjectSettings::get_imported_files_path() const {
  62. return get_project_data_path().path_join("imported");
  63. }
  64. #ifdef TOOLS_ENABLED
  65. // Returns the features that a project must have when opened with this build of Godot.
  66. // This is used by the project manager to provide the initial_settings for config/features.
  67. const PackedStringArray ProjectSettings::get_required_features() {
  68. PackedStringArray features;
  69. features.append(VERSION_BRANCH);
  70. #ifdef REAL_T_IS_DOUBLE
  71. features.append("Double Precision");
  72. #endif
  73. return features;
  74. }
  75. // Returns the features supported by this build of Godot. Includes all required features.
  76. const PackedStringArray ProjectSettings::_get_supported_features() {
  77. PackedStringArray features = get_required_features();
  78. #ifdef MODULE_MONO_ENABLED
  79. features.append("C#");
  80. #endif
  81. // Allow pinning to a specific patch number or build type by marking
  82. // them as supported. They're only used if the user adds them manually.
  83. features.append(VERSION_BRANCH "." _MKSTR(VERSION_PATCH));
  84. features.append(VERSION_FULL_CONFIG);
  85. features.append(VERSION_FULL_BUILD);
  86. #ifdef RD_ENABLED
  87. features.append("Forward Plus");
  88. features.append("Mobile");
  89. #endif
  90. #ifdef GLES3_ENABLED
  91. features.append("GL Compatibility");
  92. #endif
  93. return features;
  94. }
  95. // Returns the features that this project needs but this build of Godot lacks.
  96. const PackedStringArray ProjectSettings::get_unsupported_features(const PackedStringArray &p_project_features) {
  97. PackedStringArray unsupported_features;
  98. PackedStringArray supported_features = singleton->_get_supported_features();
  99. for (int i = 0; i < p_project_features.size(); i++) {
  100. if (!supported_features.has(p_project_features[i])) {
  101. // Temporary compatibility code to ease upgrade to 4.0 beta 2+.
  102. if (p_project_features[i].begins_with("Vulkan")) {
  103. continue;
  104. }
  105. unsupported_features.append(p_project_features[i]);
  106. }
  107. }
  108. unsupported_features.sort();
  109. return unsupported_features;
  110. }
  111. // Returns the features that both this project has and this build of Godot has, ensuring required features exist.
  112. const PackedStringArray ProjectSettings::_trim_to_supported_features(const PackedStringArray &p_project_features) {
  113. // Remove unsupported features if present.
  114. PackedStringArray features = PackedStringArray(p_project_features);
  115. PackedStringArray supported_features = _get_supported_features();
  116. for (int i = p_project_features.size() - 1; i > -1; i--) {
  117. if (!supported_features.has(p_project_features[i])) {
  118. features.remove_at(i);
  119. }
  120. }
  121. // Add required features if not present.
  122. PackedStringArray required_features = get_required_features();
  123. for (int i = 0; i < required_features.size(); i++) {
  124. if (!features.has(required_features[i])) {
  125. features.append(required_features[i]);
  126. }
  127. }
  128. features.sort();
  129. return features;
  130. }
  131. #endif // TOOLS_ENABLED
  132. String ProjectSettings::localize_path(const String &p_path) const {
  133. String path = p_path.simplify_path();
  134. if (resource_path.is_empty() || (path.is_absolute_path() && !path.begins_with(resource_path))) {
  135. return path;
  136. }
  137. // Check if we have a special path (like res://) or a protocol identifier.
  138. int p = path.find("://");
  139. bool found = false;
  140. if (p > 0) {
  141. found = true;
  142. for (int i = 0; i < p; i++) {
  143. if (!is_ascii_alphanumeric_char(path[i])) {
  144. found = false;
  145. break;
  146. }
  147. }
  148. }
  149. if (found) {
  150. return path;
  151. }
  152. Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  153. if (dir->change_dir(path) == OK) {
  154. String cwd = dir->get_current_dir();
  155. cwd = cwd.replace("\\", "/");
  156. // Ensure that we end with a '/'.
  157. // This is important to ensure that we do not wrongly localize the resource path
  158. // in an absolute path that just happens to contain this string but points to a
  159. // different folder (e.g. "/my/project" as resource_path would be contained in
  160. // "/my/project_data", even though the latter is not part of res://.
  161. // `path_join("")` is an easy way to ensure we have a trailing '/'.
  162. const String res_path = resource_path.path_join("");
  163. // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
  164. // so we must make sure we have it as well in order to compare with 'res_path'.
  165. cwd = cwd.path_join("");
  166. if (!cwd.begins_with(res_path)) {
  167. return path;
  168. }
  169. return cwd.replace_first(res_path, "res://");
  170. } else {
  171. int sep = path.rfind_char('/');
  172. if (sep == -1) {
  173. return "res://" + path;
  174. }
  175. String parent = path.substr(0, sep);
  176. String plocal = localize_path(parent);
  177. if (plocal.is_empty()) {
  178. return "";
  179. }
  180. // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
  181. if (plocal[plocal.length() - 1] == '/') {
  182. sep += 1;
  183. }
  184. return plocal + path.substr(sep, path.size() - sep);
  185. }
  186. }
  187. void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
  188. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  189. // Duplicate so that if value is array or dictionary, changing the setting will not change the stored initial value.
  190. props[p_name].initial = p_value.duplicate();
  191. }
  192. void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
  193. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  194. props[p_name].restart_if_changed = p_restart;
  195. }
  196. void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) {
  197. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  198. props[p_name].basic = p_basic;
  199. }
  200. void ProjectSettings::set_as_internal(const String &p_name, bool p_internal) {
  201. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  202. props[p_name].internal = p_internal;
  203. }
  204. void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) {
  205. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  206. #ifdef DEBUG_METHODS_ENABLED
  207. props[p_name].ignore_value_in_docs = p_ignore;
  208. #endif
  209. }
  210. bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
  211. ERR_FAIL_COND_V_MSG(!props.has(p_name), false, vformat("Request for nonexistent project setting: '%s'.", p_name));
  212. #ifdef DEBUG_METHODS_ENABLED
  213. return props[p_name].ignore_value_in_docs;
  214. #else
  215. return false;
  216. #endif
  217. }
  218. void ProjectSettings::add_hidden_prefix(const String &p_prefix) {
  219. ERR_FAIL_COND_MSG(hidden_prefixes.has(p_prefix), vformat("Hidden prefix '%s' already exists.", p_prefix));
  220. hidden_prefixes.push_back(p_prefix);
  221. }
  222. String ProjectSettings::globalize_path(const String &p_path) const {
  223. if (p_path.begins_with("res://")) {
  224. if (!resource_path.is_empty()) {
  225. return p_path.replace("res:/", resource_path);
  226. }
  227. return p_path.replace("res://", "");
  228. } else if (p_path.begins_with("uid://")) {
  229. const String path = ResourceUID::uid_to_path(p_path);
  230. if (!resource_path.is_empty()) {
  231. return path.replace("res:/", resource_path);
  232. }
  233. return path.replace("res://", "");
  234. } else if (p_path.begins_with("user://")) {
  235. String data_dir = OS::get_singleton()->get_user_data_dir();
  236. if (!data_dir.is_empty()) {
  237. return p_path.replace("user:/", data_dir);
  238. }
  239. return p_path.replace("user://", "");
  240. }
  241. return p_path;
  242. }
  243. bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
  244. _THREAD_SAFE_METHOD_
  245. if (p_value.get_type() == Variant::NIL) {
  246. props.erase(p_name);
  247. if (p_name.operator String().begins_with("autoload/")) {
  248. String node_name = p_name.operator String().split("/")[1];
  249. if (autoloads.has(node_name)) {
  250. remove_autoload(node_name);
  251. }
  252. } else if (p_name.operator String().begins_with("global_group/")) {
  253. String group_name = p_name.operator String().get_slice("/", 1);
  254. if (global_groups.has(group_name)) {
  255. remove_global_group(group_name);
  256. }
  257. }
  258. } else {
  259. if (p_name == CoreStringName(_custom_features)) {
  260. Vector<String> custom_feature_array = String(p_value).split(",");
  261. for (int i = 0; i < custom_feature_array.size(); i++) {
  262. custom_features.insert(custom_feature_array[i]);
  263. }
  264. _queue_changed();
  265. return true;
  266. }
  267. { // Feature overrides.
  268. int dot = p_name.operator String().find_char('.');
  269. if (dot != -1) {
  270. Vector<String> s = p_name.operator String().split(".");
  271. for (int i = 1; i < s.size(); i++) {
  272. String feature = s[i].strip_edges();
  273. Pair<StringName, StringName> feature_override(feature, p_name);
  274. if (!feature_overrides.has(s[0])) {
  275. feature_overrides[s[0]] = LocalVector<Pair<StringName, StringName>>();
  276. }
  277. feature_overrides[s[0]].push_back(feature_override);
  278. }
  279. }
  280. }
  281. if (props.has(p_name)) {
  282. props[p_name].variant = p_value;
  283. } else {
  284. props[p_name] = VariantContainer(p_value, last_order++);
  285. }
  286. if (p_name.operator String().begins_with("autoload/")) {
  287. String node_name = p_name.operator String().split("/")[1];
  288. AutoloadInfo autoload;
  289. autoload.name = node_name;
  290. String path = p_value;
  291. if (path.begins_with("*")) {
  292. autoload.is_singleton = true;
  293. autoload.path = path.substr(1).simplify_path();
  294. } else {
  295. autoload.path = path.simplify_path();
  296. }
  297. add_autoload(autoload);
  298. } else if (p_name.operator String().begins_with("global_group/")) {
  299. String group_name = p_name.operator String().get_slice("/", 1);
  300. add_global_group(group_name, p_value);
  301. }
  302. }
  303. _queue_changed();
  304. return true;
  305. }
  306. bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
  307. _THREAD_SAFE_METHOD_
  308. if (!props.has(p_name)) {
  309. return false;
  310. }
  311. r_ret = props[p_name].variant;
  312. return true;
  313. }
  314. Variant ProjectSettings::get_setting_with_override(const StringName &p_name) const {
  315. _THREAD_SAFE_METHOD_
  316. StringName name = p_name;
  317. if (feature_overrides.has(name)) {
  318. const LocalVector<Pair<StringName, StringName>> &overrides = feature_overrides[name];
  319. for (uint32_t i = 0; i < overrides.size(); i++) {
  320. if (OS::get_singleton()->has_feature(overrides[i].first)) { // Custom features are checked in OS.has_feature() already. No need to check twice.
  321. if (props.has(overrides[i].second)) {
  322. name = overrides[i].second;
  323. break;
  324. }
  325. }
  326. }
  327. }
  328. if (!props.has(name)) {
  329. WARN_PRINT(vformat("Property not found: '%s'.", String(name)));
  330. return Variant();
  331. }
  332. return props[name].variant;
  333. }
  334. struct _VCSort {
  335. String name;
  336. Variant::Type type = Variant::VARIANT_MAX;
  337. int order = 0;
  338. uint32_t flags = 0;
  339. bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
  340. };
  341. void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  342. _THREAD_SAFE_METHOD_
  343. RBSet<_VCSort> vclist;
  344. for (const KeyValue<StringName, VariantContainer> &E : props) {
  345. const VariantContainer *v = &E.value;
  346. if (v->hide_from_editor) {
  347. continue;
  348. }
  349. _VCSort vc;
  350. vc.name = E.key;
  351. vc.order = v->order;
  352. vc.type = v->variant.get_type();
  353. bool internal = v->internal;
  354. if (!internal) {
  355. for (const String &F : hidden_prefixes) {
  356. if (vc.name.begins_with(F)) {
  357. internal = true;
  358. break;
  359. }
  360. }
  361. }
  362. if (internal) {
  363. vc.flags = PROPERTY_USAGE_STORAGE;
  364. } else {
  365. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  366. }
  367. if (v->internal) {
  368. vc.flags |= PROPERTY_USAGE_INTERNAL;
  369. }
  370. if (v->basic) {
  371. vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  372. }
  373. if (v->restart_if_changed) {
  374. vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  375. }
  376. vclist.insert(vc);
  377. }
  378. for (const _VCSort &E : vclist) {
  379. String prop_info_name = E.name;
  380. int dot = prop_info_name.find_char('.');
  381. if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
  382. prop_info_name = prop_info_name.substr(0, dot);
  383. }
  384. if (custom_prop_info.has(prop_info_name)) {
  385. PropertyInfo pi = custom_prop_info[prop_info_name];
  386. pi.name = E.name;
  387. pi.usage = E.flags;
  388. p_list->push_back(pi);
  389. } else {
  390. p_list->push_back(PropertyInfo(E.type, E.name, PROPERTY_HINT_NONE, "", E.flags));
  391. }
  392. }
  393. }
  394. void ProjectSettings::_queue_changed() {
  395. if (is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) {
  396. return;
  397. }
  398. is_changed = true;
  399. callable_mp(this, &ProjectSettings::_emit_changed).call_deferred();
  400. }
  401. void ProjectSettings::_emit_changed() {
  402. if (!is_changed) {
  403. return;
  404. }
  405. is_changed = false;
  406. emit_signal("settings_changed");
  407. }
  408. bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
  409. if (PackedData::get_singleton()->is_disabled()) {
  410. return false;
  411. }
  412. bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK;
  413. if (!ok) {
  414. return false;
  415. }
  416. if (project_loaded) {
  417. // This pack may have declared new global classes (make sure they are picked up).
  418. refresh_global_class_list();
  419. // This pack may have defined new UIDs, make sure they are cached.
  420. ResourceUID::get_singleton()->load_from_cache(false);
  421. }
  422. //if data.pck is found, all directory access will be from here
  423. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  424. using_datapack = true;
  425. return true;
  426. }
  427. void ProjectSettings::_convert_to_last_version(int p_from_version) {
  428. #ifndef DISABLE_DEPRECATED
  429. if (p_from_version <= 3) {
  430. // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
  431. for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
  432. Variant value = E.value.variant;
  433. if (String(E.key).begins_with("input/") && value.get_type() == Variant::ARRAY) {
  434. Array array = value;
  435. Dictionary action;
  436. action["deadzone"] = Variant(0.5f);
  437. action["events"] = array;
  438. E.value.variant = action;
  439. }
  440. }
  441. }
  442. if (p_from_version == 5) {
  443. // Converts the device in events from -3 to -1.
  444. // -3 was introduced in GH-97707 as a way to prevent a clash in device IDs, but as reported in GH-99243, this leads to problems.
  445. // -3 was used during dev-releases, so this conversion helps to revert such affected projects.
  446. // This conversion doesn't affect any other projects, since -3 is not used otherwise.
  447. for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
  448. if (String(E.key).begins_with("input/")) {
  449. Dictionary action = E.value.variant;
  450. Array events = action["events"];
  451. for (int i = 0; i < events.size(); i++) {
  452. Ref<InputEvent> ev = events[i];
  453. if (ev.is_valid() && ev->get_device() == -3) {
  454. ev->set_device(-1);
  455. }
  456. }
  457. }
  458. }
  459. }
  460. #endif // DISABLE_DEPRECATED
  461. }
  462. /*
  463. * This method is responsible for loading a project.godot file and/or data file
  464. * using the following merit order:
  465. * - If using NetworkClient, try to lookup project file or fail.
  466. * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
  467. * - Search for project PCKs automatically. For each step we try loading a potential
  468. * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds,
  469. * we try loading the project settings, and abort if it fails. Steps:
  470. * o Bundled PCK in the executable.
  471. * o [macOS only] PCK with same basename as the binary in the .app resource dir.
  472. * o PCK with same basename as the binary in the binary's directory. We handle both
  473. * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and
  474. * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck').
  475. * o PCK with the same basename as the binary in the current working directory.
  476. * Same as above for the two possible PCK file names.
  477. * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
  478. * If found, load it or fail.
  479. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
  480. * are running from source code.
  481. * If not found and `p_upwards` is true (--upwards passed by the user), look for
  482. * project files in parent folders up to the system root (used to run a game
  483. * from command line while in a subfolder).
  484. * If a project file is found, load it or fail.
  485. * If nothing was found, error out.
  486. */
  487. Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  488. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  489. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  490. // If the OS would rather use a specific location, then it will not be empty.
  491. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  492. if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') {
  493. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  494. }
  495. }
  496. // Attempt with a user-defined main pack first
  497. if (!p_main_pack.is_empty()) {
  498. bool ok = _load_resource_pack(p_main_pack);
  499. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack));
  500. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  501. if (err == OK && !p_ignore_override) {
  502. // Load override from location of the main pack
  503. // Optional, we don't mind if it fails
  504. _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
  505. }
  506. return err;
  507. }
  508. String exec_path = OS::get_singleton()->get_executable_path();
  509. if (!exec_path.is_empty()) {
  510. // We do several tests sequentially until one succeeds to find a PCK,
  511. // and if so, we attempt loading it at the end.
  512. // Attempt with PCK bundled into executable.
  513. bool found = _load_resource_pack(exec_path);
  514. // Attempt with exec_name.pck.
  515. // (This is the usual case when distributing a Godot game.)
  516. String exec_dir = exec_path.get_base_dir();
  517. String exec_filename = exec_path.get_file();
  518. String exec_basename = exec_filename.get_basename();
  519. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  520. // or the exec path's basename + '.pck' (Windows).
  521. // We need to test both possibilities as extensions for Linux binaries are optional
  522. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  523. #ifdef MACOS_ENABLED
  524. if (!found) {
  525. // Attempt to load PCK from macOS .app bundle resources.
  526. found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"));
  527. }
  528. #endif
  529. if (!found) {
  530. // Try to load data pack at the location of the executable.
  531. // As mentioned above, we have two potential names to attempt.
  532. found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck")) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"));
  533. }
  534. if (!found) {
  535. // If we couldn't find them next to the executable, we attempt
  536. // the current working directory. Same story, two tests.
  537. found = _load_resource_pack(exec_basename + ".pck") || _load_resource_pack(exec_filename + ".pck");
  538. }
  539. // If we opened our package, try and load our project.
  540. if (found) {
  541. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  542. if (err == OK && !p_ignore_override) {
  543. // Load overrides from the PCK and the executable location.
  544. // Optional, we don't mind if either fails.
  545. _load_settings_text("res://override.cfg");
  546. _load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
  547. }
  548. return err;
  549. }
  550. }
  551. // Try to use the filesystem for files, according to OS.
  552. // (Only Android -when reading from pck- and iOS use this.)
  553. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  554. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  555. if (err == OK && !p_ignore_override) {
  556. // Optional, we don't mind if it fails.
  557. _load_settings_text("res://override.cfg");
  558. }
  559. return err;
  560. }
  561. #ifdef MACOS_ENABLED
  562. // Attempt to load project file from macOS .app bundle resources.
  563. resource_path = OS::get_singleton()->get_bundle_resource_dir();
  564. if (!resource_path.is_empty()) {
  565. if (resource_path[resource_path.length() - 1] == '/') {
  566. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  567. }
  568. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  569. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", resource_path));
  570. d->change_dir(resource_path);
  571. Error err;
  572. err = _load_settings_text_or_binary(resource_path.path_join("project.godot"), resource_path.path_join("project.binary"));
  573. if (err == OK && !p_ignore_override) {
  574. // Optional, we don't mind if it fails.
  575. _load_settings_text(resource_path.path_join("override.cfg"));
  576. return err;
  577. }
  578. }
  579. #endif
  580. // Nothing was found, try to find a project file in provided path (`p_path`)
  581. // or, if requested (`p_upwards`) in parent directories.
  582. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  583. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", p_path));
  584. d->change_dir(p_path);
  585. String current_dir = d->get_current_dir();
  586. bool found = false;
  587. Error err;
  588. while (true) {
  589. // Set the resource path early so things can be resolved when loading.
  590. resource_path = current_dir;
  591. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  592. err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary"));
  593. if (err == OK && !p_ignore_override) {
  594. // Optional, we don't mind if it fails.
  595. _load_settings_text(current_dir.path_join("override.cfg"));
  596. found = true;
  597. break;
  598. }
  599. if (p_upwards) {
  600. // Try to load settings ascending through parent directories
  601. d->change_dir("..");
  602. if (d->get_current_dir() == current_dir) {
  603. break; // not doing anything useful
  604. }
  605. current_dir = d->get_current_dir();
  606. } else {
  607. break;
  608. }
  609. }
  610. if (!found) {
  611. return err;
  612. }
  613. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  614. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  615. }
  616. return OK;
  617. }
  618. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  619. Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override);
  620. if (err == OK && !p_ignore_override) {
  621. String custom_settings = GLOBAL_GET("application/config/project_settings_override");
  622. if (!custom_settings.is_empty()) {
  623. _load_settings_text(custom_settings);
  624. }
  625. }
  626. // Updating the default value after the project settings have loaded.
  627. bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory");
  628. project_data_dir_name = (use_hidden_directory ? "." : "") + PROJECT_DATA_DIR_NAME_SUFFIX;
  629. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  630. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  631. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  632. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  633. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  634. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  635. load_scene_groups_cache();
  636. project_loaded = err == OK;
  637. return err;
  638. }
  639. bool ProjectSettings::has_setting(const String &p_var) const {
  640. _THREAD_SAFE_METHOD_
  641. return props.has(p_var);
  642. }
  643. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  644. Error err;
  645. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  646. if (err != OK) {
  647. return err;
  648. }
  649. uint8_t hdr[4];
  650. f->get_buffer(hdr, 4);
  651. 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).");
  652. uint32_t count = f->get_32();
  653. for (uint32_t i = 0; i < count; i++) {
  654. uint32_t slen = f->get_32();
  655. CharString cs;
  656. cs.resize(slen + 1);
  657. cs[slen] = 0;
  658. f->get_buffer((uint8_t *)cs.ptr(), slen);
  659. String key;
  660. key.parse_utf8(cs.ptr(), slen);
  661. uint32_t vlen = f->get_32();
  662. Vector<uint8_t> d;
  663. d.resize(vlen);
  664. f->get_buffer(d.ptrw(), vlen);
  665. Variant value;
  666. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  667. ERR_CONTINUE_MSG(err != OK, vformat("Error decoding property: '%s'.", key));
  668. set(key, value);
  669. }
  670. return OK;
  671. }
  672. Error ProjectSettings::_load_settings_text(const String &p_path) {
  673. Error err;
  674. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  675. if (f.is_null()) {
  676. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  677. // This needs to be streamlined if we want decent error reporting
  678. return ERR_FILE_NOT_FOUND;
  679. }
  680. VariantParser::StreamFile stream;
  681. stream.f = f;
  682. String assign;
  683. Variant value;
  684. VariantParser::Tag next_tag;
  685. int lines = 0;
  686. String error_text;
  687. String section;
  688. int config_version = 0;
  689. while (true) {
  690. assign = Variant();
  691. next_tag.fields.clear();
  692. next_tag.name = String();
  693. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  694. if (err == ERR_FILE_EOF) {
  695. // If we're loading a project.godot from source code, we can operate some
  696. // ProjectSettings conversions if need be.
  697. _convert_to_last_version(config_version);
  698. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  699. return OK;
  700. }
  701. 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));
  702. if (!assign.is_empty()) {
  703. if (section.is_empty() && assign == "config_version") {
  704. config_version = value;
  705. 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));
  706. } else {
  707. if (section.is_empty()) {
  708. set(assign, value);
  709. } else {
  710. set(section + "/" + assign, value);
  711. }
  712. }
  713. } else if (!next_tag.name.is_empty()) {
  714. section = next_tag.name;
  715. }
  716. }
  717. }
  718. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  719. // Attempt first to load the binary project.godot file.
  720. Error err = _load_settings_binary(p_bin_path);
  721. if (err == OK) {
  722. return OK;
  723. } else if (err != ERR_FILE_NOT_FOUND) {
  724. // If the file exists but can't be loaded, we want to know it.
  725. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_bin_path, err));
  726. }
  727. // Fallback to text-based project.godot file if binary was not found.
  728. err = _load_settings_text(p_text_path);
  729. if (err == OK) {
  730. return OK;
  731. } else if (err != ERR_FILE_NOT_FOUND) {
  732. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_text_path, err));
  733. }
  734. return err;
  735. }
  736. Error ProjectSettings::load_custom(const String &p_path) {
  737. if (p_path.ends_with(".binary")) {
  738. return _load_settings_binary(p_path);
  739. }
  740. return _load_settings_text(p_path);
  741. }
  742. int ProjectSettings::get_order(const String &p_name) const {
  743. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, vformat("Request for nonexistent project setting: '%s'.", p_name));
  744. return props[p_name].order;
  745. }
  746. void ProjectSettings::set_order(const String &p_name, int p_order) {
  747. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  748. props[p_name].order = p_order;
  749. }
  750. void ProjectSettings::set_builtin_order(const String &p_name) {
  751. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  752. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  753. props[p_name].order = last_builtin_order++;
  754. }
  755. }
  756. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  757. // Return true because a false negative is worse than a false positive.
  758. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, vformat("Request for nonexistent project setting: '%s'.", p_name));
  759. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  760. }
  761. void ProjectSettings::clear(const String &p_name) {
  762. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  763. props.erase(p_name);
  764. }
  765. Error ProjectSettings::save() {
  766. Error error = save_custom(get_resource_path().path_join("project.godot"));
  767. if (error == OK) {
  768. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  769. }
  770. return error;
  771. }
  772. 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) {
  773. Error err;
  774. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  775. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.binary at '%s'.", p_file));
  776. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  777. file->store_buffer(hdr, 4);
  778. int count = 0;
  779. for (const KeyValue<String, List<String>> &E : p_props) {
  780. count += E.value.size();
  781. }
  782. if (!p_custom_features.is_empty()) {
  783. // Store how many properties are saved, add one for custom features, which must always go first.
  784. file->store_32(uint32_t(count + 1));
  785. String key = CoreStringName(_custom_features);
  786. file->store_pascal_string(key);
  787. int len;
  788. err = encode_variant(p_custom_features, nullptr, len, false);
  789. ERR_FAIL_COND_V(err != OK, err);
  790. Vector<uint8_t> buff;
  791. buff.resize(len);
  792. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  793. ERR_FAIL_COND_V(err != OK, err);
  794. file->store_32(uint32_t(len));
  795. file->store_buffer(buff.ptr(), buff.size());
  796. } else {
  797. // Store how many properties are saved.
  798. file->store_32(uint32_t(count));
  799. }
  800. for (const KeyValue<String, List<String>> &E : p_props) {
  801. for (const String &key : E.value) {
  802. String k = key;
  803. if (!E.key.is_empty()) {
  804. k = E.key + "/" + k;
  805. }
  806. Variant value;
  807. if (p_custom.has(k)) {
  808. value = p_custom[k];
  809. } else {
  810. value = get(k);
  811. }
  812. file->store_pascal_string(k);
  813. int len;
  814. err = encode_variant(value, nullptr, len, true);
  815. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  816. Vector<uint8_t> buff;
  817. buff.resize(len);
  818. err = encode_variant(value, buff.ptrw(), len, true);
  819. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  820. file->store_32(uint32_t(len));
  821. file->store_buffer(buff.ptr(), buff.size());
  822. }
  823. }
  824. return OK;
  825. }
  826. 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) {
  827. Error err;
  828. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  829. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.godot - %s.", p_file));
  830. file->store_line("; Engine configuration file.");
  831. file->store_line("; It's best edited using the editor UI and not directly,");
  832. file->store_line("; since the parameters that go here are not all obvious.");
  833. file->store_line(";");
  834. file->store_line("; Format:");
  835. file->store_line("; [section] ; section goes between []");
  836. file->store_line("; param=value ; assign values to parameters");
  837. file->store_line("");
  838. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  839. if (!p_custom_features.is_empty()) {
  840. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  841. }
  842. file->store_string("\n");
  843. for (const KeyValue<String, List<String>> &E : p_props) {
  844. if (E.key != p_props.begin()->key) {
  845. file->store_string("\n");
  846. }
  847. if (!E.key.is_empty()) {
  848. file->store_string("[" + E.key + "]\n\n");
  849. }
  850. for (const String &F : E.value) {
  851. String key = F;
  852. if (!E.key.is_empty()) {
  853. key = E.key + "/" + key;
  854. }
  855. Variant value;
  856. if (p_custom.has(key)) {
  857. value = p_custom[key];
  858. } else {
  859. value = get(key);
  860. }
  861. String vstr;
  862. VariantWriter::write_to_string(value, vstr);
  863. file->store_string(F.property_name_encode() + "=" + vstr + "\n");
  864. }
  865. }
  866. return OK;
  867. }
  868. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  869. return save_custom(p_file);
  870. }
  871. #ifdef TOOLS_ENABLED
  872. bool _csproj_exists(const String &p_root_dir) {
  873. Ref<DirAccess> dir = DirAccess::open(p_root_dir);
  874. ERR_FAIL_COND_V(dir.is_null(), false);
  875. dir->list_dir_begin();
  876. String file_name = dir->_get_next();
  877. while (file_name != "") {
  878. if (!dir->current_is_dir() && file_name.get_extension() == "csproj") {
  879. return true;
  880. }
  881. file_name = dir->_get_next();
  882. }
  883. return false;
  884. }
  885. #endif // TOOLS_ENABLED
  886. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  887. ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  888. #ifdef TOOLS_ENABLED
  889. PackedStringArray project_features = get_setting("application/config/features");
  890. // If there is no feature list currently present, force one to generate.
  891. if (project_features.is_empty()) {
  892. project_features = ProjectSettings::get_required_features();
  893. }
  894. // Check the rendering API.
  895. const String rendering_api = has_setting("rendering/renderer/rendering_method") ? (String)get_setting("rendering/renderer/rendering_method") : String();
  896. if (!rendering_api.is_empty()) {
  897. // Add the rendering API as a project feature if it doesn't already exist.
  898. if (!project_features.has(rendering_api)) {
  899. project_features.append(rendering_api);
  900. }
  901. }
  902. // Check for the existence of a csproj file.
  903. if (_csproj_exists(get_resource_path())) {
  904. // If there is a csproj file, add the C# feature if it doesn't already exist.
  905. if (!project_features.has("C#")) {
  906. project_features.append("C#");
  907. }
  908. } else {
  909. // If there isn't a csproj file, remove the C# feature if it exists.
  910. if (project_features.has("C#")) {
  911. project_features.remove_at(project_features.find("C#"));
  912. }
  913. }
  914. project_features = _trim_to_supported_features(project_features);
  915. set_setting("application/config/features", project_features);
  916. #endif // TOOLS_ENABLED
  917. RBSet<_VCSort> vclist;
  918. if (p_merge_with_current) {
  919. for (const KeyValue<StringName, VariantContainer> &G : props) {
  920. const VariantContainer *v = &G.value;
  921. if (v->hide_from_editor) {
  922. continue;
  923. }
  924. if (p_custom.has(G.key)) {
  925. continue;
  926. }
  927. _VCSort vc;
  928. vc.name = G.key; //*k;
  929. vc.order = v->order;
  930. vc.type = v->variant.get_type();
  931. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  932. if (v->variant == v->initial) {
  933. continue;
  934. }
  935. vclist.insert(vc);
  936. }
  937. }
  938. for (const KeyValue<String, Variant> &E : p_custom) {
  939. // Lookup global prop to store in the same order
  940. RBMap<StringName, VariantContainer>::Iterator global_prop = props.find(E.key);
  941. _VCSort vc;
  942. vc.name = E.key;
  943. vc.order = global_prop ? global_prop->value.order : 0xFFFFFFF;
  944. vc.type = E.value.get_type();
  945. vc.flags = PROPERTY_USAGE_STORAGE;
  946. vclist.insert(vc);
  947. }
  948. RBMap<String, List<String>> save_props;
  949. for (const _VCSort &E : vclist) {
  950. String category = E.name;
  951. String name = E.name;
  952. int div = category.find_char('/');
  953. if (div < 0) {
  954. category = "";
  955. } else {
  956. category = category.substr(0, div);
  957. name = name.substr(div + 1, name.size());
  958. }
  959. save_props[category].push_back(name);
  960. }
  961. String save_features;
  962. for (int i = 0; i < p_custom_features.size(); i++) {
  963. if (i > 0) {
  964. save_features += ",";
  965. }
  966. String f = p_custom_features[i].strip_edges().replace("\"", "");
  967. save_features += f;
  968. }
  969. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  970. return _save_settings_text(p_path, save_props, p_custom, save_features);
  971. } else if (p_path.ends_with(".binary")) {
  972. return _save_settings_binary(p_path, save_props, p_custom, save_features);
  973. } else {
  974. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, vformat("Unknown config file format: '%s'.", p_path));
  975. }
  976. }
  977. 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) {
  978. Variant ret;
  979. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  980. ProjectSettings::get_singleton()->set(p_var, p_default);
  981. }
  982. ret = GLOBAL_GET(p_var);
  983. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  984. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  985. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  986. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  987. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  988. ProjectSettings::get_singleton()->set_as_internal(p_var, p_internal);
  989. return ret;
  990. }
  991. 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) {
  992. Variant ret = _GLOBAL_DEF(p_info.name, p_default, p_restart_if_changed, p_ignore_value_in_docs, p_basic, p_internal);
  993. ProjectSettings::get_singleton()->set_custom_property_info(p_info);
  994. return ret;
  995. }
  996. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  997. ERR_FAIL_COND(!p_info.has("name"));
  998. ERR_FAIL_COND(!p_info.has("type"));
  999. PropertyInfo pinfo;
  1000. pinfo.name = p_info["name"];
  1001. ERR_FAIL_COND(!props.has(pinfo.name));
  1002. pinfo.type = Variant::Type(p_info["type"].operator int());
  1003. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  1004. if (p_info.has("hint")) {
  1005. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  1006. }
  1007. if (p_info.has("hint_string")) {
  1008. pinfo.hint_string = p_info["hint_string"];
  1009. }
  1010. set_custom_property_info(pinfo);
  1011. }
  1012. void ProjectSettings::set_custom_property_info(const PropertyInfo &p_info) {
  1013. const String &prop_name = p_info.name;
  1014. ERR_FAIL_COND(!props.has(prop_name));
  1015. custom_prop_info[prop_name] = p_info;
  1016. }
  1017. const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  1018. return custom_prop_info;
  1019. }
  1020. bool ProjectSettings::is_using_datapack() const {
  1021. return using_datapack;
  1022. }
  1023. bool ProjectSettings::is_project_loaded() const {
  1024. return project_loaded;
  1025. }
  1026. bool ProjectSettings::_property_can_revert(const StringName &p_name) const {
  1027. return props.has(p_name);
  1028. }
  1029. bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  1030. const RBMap<StringName, ProjectSettings::VariantContainer>::Element *value = props.find(p_name);
  1031. if (value) {
  1032. r_property = value->value().initial.duplicate();
  1033. return true;
  1034. }
  1035. return false;
  1036. }
  1037. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  1038. set(p_setting, p_value);
  1039. }
  1040. Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_default_value) const {
  1041. if (has_setting(p_setting)) {
  1042. return get(p_setting);
  1043. } else {
  1044. return p_default_value;
  1045. }
  1046. }
  1047. void ProjectSettings::refresh_global_class_list() {
  1048. // This is called after mounting a new PCK file to pick up class changes.
  1049. is_global_class_list_loaded = false; // Make sure we read from the freshly mounted PCK.
  1050. Array script_classes = get_global_class_list();
  1051. for (int i = 0; i < script_classes.size(); i++) {
  1052. Dictionary c = script_classes[i];
  1053. if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
  1054. continue;
  1055. }
  1056. ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"]);
  1057. }
  1058. }
  1059. TypedArray<Dictionary> ProjectSettings::get_global_class_list() {
  1060. if (is_global_class_list_loaded) {
  1061. return global_class_list;
  1062. }
  1063. Ref<ConfigFile> cf;
  1064. cf.instantiate();
  1065. if (cf->load(get_global_class_list_path()) == OK) {
  1066. global_class_list = cf->get_value("", "list", Array());
  1067. } else {
  1068. #ifndef TOOLS_ENABLED
  1069. // Script classes can't be recreated in exported project, so print an error.
  1070. ERR_PRINT("Could not load global script cache.");
  1071. #endif
  1072. }
  1073. // File read succeeded or failed. If it failed, assume everything is still okay.
  1074. // We will later receive updated class data in store_global_class_list().
  1075. is_global_class_list_loaded = true;
  1076. return global_class_list;
  1077. }
  1078. String ProjectSettings::get_global_class_list_path() const {
  1079. return get_project_data_path().path_join("global_script_class_cache.cfg");
  1080. }
  1081. void ProjectSettings::store_global_class_list(const Array &p_classes) {
  1082. Ref<ConfigFile> cf;
  1083. cf.instantiate();
  1084. cf->set_value("", "list", p_classes);
  1085. cf->save(get_global_class_list_path());
  1086. global_class_list = p_classes;
  1087. }
  1088. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  1089. return custom_features.has(p_feature);
  1090. }
  1091. const HashMap<StringName, ProjectSettings::AutoloadInfo> &ProjectSettings::get_autoload_list() const {
  1092. return autoloads;
  1093. }
  1094. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  1095. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  1096. autoloads[p_autoload.name] = p_autoload;
  1097. }
  1098. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  1099. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  1100. autoloads.erase(p_autoload);
  1101. }
  1102. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  1103. return autoloads.has(p_autoload);
  1104. }
  1105. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  1106. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  1107. return autoloads[p_name];
  1108. }
  1109. const HashMap<StringName, String> &ProjectSettings::get_global_groups_list() const {
  1110. return global_groups;
  1111. }
  1112. void ProjectSettings::add_global_group(const StringName &p_name, const String &p_description) {
  1113. ERR_FAIL_COND_MSG(p_name == StringName(), "Trying to add global group with no name.");
  1114. global_groups[p_name] = p_description;
  1115. }
  1116. void ProjectSettings::remove_global_group(const StringName &p_name) {
  1117. ERR_FAIL_COND_MSG(!global_groups.has(p_name), "Trying to remove non-existent global group.");
  1118. global_groups.erase(p_name);
  1119. }
  1120. bool ProjectSettings::has_global_group(const StringName &p_name) const {
  1121. return global_groups.has(p_name);
  1122. }
  1123. void ProjectSettings::remove_scene_groups_cache(const StringName &p_path) {
  1124. scene_groups_cache.erase(p_path);
  1125. }
  1126. void ProjectSettings::add_scene_groups_cache(const StringName &p_path, const HashSet<StringName> &p_cache) {
  1127. scene_groups_cache[p_path] = p_cache;
  1128. }
  1129. void ProjectSettings::save_scene_groups_cache() {
  1130. Ref<ConfigFile> cf;
  1131. cf.instantiate();
  1132. for (const KeyValue<StringName, HashSet<StringName>> &E : scene_groups_cache) {
  1133. if (E.value.is_empty()) {
  1134. continue;
  1135. }
  1136. Array list;
  1137. for (const StringName &group : E.value) {
  1138. list.push_back(group);
  1139. }
  1140. cf->set_value(E.key, "groups", list);
  1141. }
  1142. cf->save(get_scene_groups_cache_path());
  1143. }
  1144. String ProjectSettings::get_scene_groups_cache_path() const {
  1145. return get_project_data_path().path_join("scene_groups_cache.cfg");
  1146. }
  1147. void ProjectSettings::load_scene_groups_cache() {
  1148. Ref<ConfigFile> cf;
  1149. cf.instantiate();
  1150. if (cf->load(get_scene_groups_cache_path()) == OK) {
  1151. List<String> scene_paths;
  1152. cf->get_sections(&scene_paths);
  1153. for (const String &E : scene_paths) {
  1154. Array scene_groups = cf->get_value(E, "groups", Array());
  1155. HashSet<StringName> cache;
  1156. for (const Variant &scene_group : scene_groups) {
  1157. cache.insert(scene_group);
  1158. }
  1159. add_scene_groups_cache(E, cache);
  1160. }
  1161. }
  1162. }
  1163. const HashMap<StringName, HashSet<StringName>> &ProjectSettings::get_scene_groups_cache() const {
  1164. return scene_groups_cache;
  1165. }
  1166. #ifdef TOOLS_ENABLED
  1167. void ProjectSettings::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1168. const String pf = p_function;
  1169. if (p_idx == 0) {
  1170. if (pf == "has_setting" || pf == "set_setting" || pf == "get_setting" || pf == "get_setting_with_override" ||
  1171. pf == "set_order" || pf == "get_order" || pf == "set_initial_value" || pf == "set_as_basic" ||
  1172. pf == "set_as_internal" || pf == "set_restart_if_changed" || pf == "clear") {
  1173. for (const KeyValue<StringName, VariantContainer> &E : props) {
  1174. if (E.value.hide_from_editor) {
  1175. continue;
  1176. }
  1177. r_options->push_back(String(E.key).quote());
  1178. }
  1179. }
  1180. }
  1181. Object::get_argument_options(p_function, p_idx, r_options);
  1182. }
  1183. #endif
  1184. void ProjectSettings::_bind_methods() {
  1185. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  1186. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  1187. ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant()));
  1188. ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override);
  1189. ClassDB::bind_method(D_METHOD("get_global_class_list"), &ProjectSettings::get_global_class_list);
  1190. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  1191. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  1192. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  1193. ClassDB::bind_method(D_METHOD("set_as_basic", "name", "basic"), &ProjectSettings::set_as_basic);
  1194. ClassDB::bind_method(D_METHOD("set_as_internal", "name", "internal"), &ProjectSettings::set_as_internal);
  1195. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  1196. ClassDB::bind_method(D_METHOD("set_restart_if_changed", "name", "restart"), &ProjectSettings::set_restart_if_changed);
  1197. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  1198. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  1199. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  1200. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  1201. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  1202. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  1203. ADD_SIGNAL(MethodInfo("settings_changed"));
  1204. }
  1205. void ProjectSettings::_add_builtin_input_map() {
  1206. if (InputMap::get_singleton()) {
  1207. HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  1208. for (KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
  1209. Array events;
  1210. // Convert list of input events into array
  1211. for (List<Ref<InputEvent>>::Element *I = E.value.front(); I; I = I->next()) {
  1212. events.push_back(I->get());
  1213. }
  1214. Dictionary action;
  1215. action["deadzone"] = Variant(InputMap::DEFAULT_DEADZONE);
  1216. action["events"] = events;
  1217. String action_name = "input/" + E.key;
  1218. GLOBAL_DEF(action_name, action);
  1219. input_presets.push_back(action_name);
  1220. }
  1221. }
  1222. }
  1223. ProjectSettings::ProjectSettings() {
  1224. // Initialization of engine variables should be done in the setup() method,
  1225. // so that the values can be overridden from project.godot or project.binary.
  1226. CRASH_COND_MSG(singleton != nullptr, "Instantiating a new ProjectSettings singleton is not supported.");
  1227. singleton = this;
  1228. #ifdef TOOLS_ENABLED
  1229. // Available only at runtime in editor builds. Needs to be processed before anything else to work properly.
  1230. if (!Engine::get_singleton()->is_editor_hint()) {
  1231. String editor_features = OS::get_singleton()->get_environment("GODOT_EDITOR_CUSTOM_FEATURES");
  1232. if (!editor_features.is_empty()) {
  1233. PackedStringArray feature_list = editor_features.split(",");
  1234. for (const String &s : feature_list) {
  1235. custom_features.insert(s);
  1236. }
  1237. }
  1238. }
  1239. #endif
  1240. GLOBAL_DEF_BASIC("application/config/name", "");
  1241. GLOBAL_DEF_BASIC(PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary());
  1242. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT), "");
  1243. GLOBAL_DEF_BASIC("application/config/version", "");
  1244. GLOBAL_DEF_INTERNAL(PropertyInfo(Variant::STRING, "application/config/tags"), PackedStringArray());
  1245. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), "");
  1246. GLOBAL_DEF("application/run/disable_stdout", false);
  1247. GLOBAL_DEF("application/run/disable_stderr", false);
  1248. GLOBAL_DEF("application/run/print_header", true);
  1249. GLOBAL_DEF("application/run/enable_alt_space_menu", false);
  1250. GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true);
  1251. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  1252. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  1253. GLOBAL_DEF("application/config/project_settings_override", "");
  1254. GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
  1255. GLOBAL_DEF("application/config/auto_accept_quit", true);
  1256. GLOBAL_DEF("application/config/quit_on_go_back", true);
  1257. // The default window size is tuned to:
  1258. // - Have a 16:9 aspect ratio,
  1259. // - Have both dimensions divisible by 8 to better play along with video recording,
  1260. // - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings).
  1261. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "1,7680,1,or_greater"), 1152); // 8K resolution
  1262. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "1,4320,1,or_greater"), 648); // 8K resolution
  1263. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), 0);
  1264. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  1265. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_position_type", PROPERTY_HINT_ENUM, "Absolute,Center of Primary Screen,Center of Other Screen,Center of Screen With Mouse Pointer,Center of Screen With Keyboard Focus"), 1);
  1266. GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR2I, "display/window/size/initial_position"), Vector2i());
  1267. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), 0);
  1268. GLOBAL_DEF_BASIC("display/window/size/resizable", true);
  1269. GLOBAL_DEF_BASIC("display/window/size/borderless", false);
  1270. GLOBAL_DEF("display/window/size/always_on_top", false);
  1271. GLOBAL_DEF("display/window/size/transparent", false);
  1272. GLOBAL_DEF("display/window/size/extend_to_title", false);
  1273. GLOBAL_DEF("display/window/size/no_focus", false);
  1274. GLOBAL_DEF("display/window/size/sharp_corners", false);
  1275. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
  1276. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution
  1277. GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
  1278. GLOBAL_DEF("animation/warnings/check_invalid_track_paths", true);
  1279. GLOBAL_DEF("animation/warnings/check_angle_interpolation_type_conflicting", true);
  1280. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"), "res://default_bus_layout.tres");
  1281. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type", PROPERTY_HINT_ENUM, "Stream,Sample"), 0);
  1282. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type.web", PROPERTY_HINT_ENUM, "Stream,Sample"), 1);
  1283. GLOBAL_DEF_RST("audio/general/text_to_speech", false);
  1284. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1285. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1286. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/ios/session_category", PROPERTY_HINT_ENUM, "Ambient,Multi Route,Play and Record,Playback,Record,Solo Ambient"), 0);
  1287. GLOBAL_DEF("audio/general/ios/mix_with_others", false);
  1288. _add_builtin_input_map();
  1289. // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
  1290. 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");
  1291. GLOBAL_DEF("display/window/subwindows/embed_subwindows", true);
  1292. // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
  1293. custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");
  1294. GLOBAL_DEF("display/window/frame_pacing/android/enable_frame_pacing", true);
  1295. 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);
  1296. #ifdef DISABLE_DEPRECATED
  1297. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Safe:1,Separate");
  1298. #else
  1299. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Unsafe (deprecated),Safe,Separate");
  1300. #endif
  1301. GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
  1302. GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
  1303. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport"), "disabled");
  1304. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand"), "keep");
  1305. GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "display/window/stretch/scale", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), 1.0);
  1306. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/scale_mode", PROPERTY_HINT_ENUM, "fractional,integer"), "fractional");
  1307. GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"), 16384);
  1308. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "debug/settings/profiler/max_timestamp_query_elements", PROPERTY_HINT_RANGE, "256,65535,1"), 256);
  1309. GLOBAL_DEF(PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"), Compression::zstd_long_distance_matching);
  1310. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"), Compression::zstd_level);
  1311. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"), Compression::zstd_window_log_size);
  1312. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::zlib_level);
  1313. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::gzip_level);
  1314. GLOBAL_DEF("debug/settings/crash_handler/message",
  1315. String("Please include this when reporting the bug to the project developer."));
  1316. GLOBAL_DEF("debug/settings/crash_handler/message.editor",
  1317. String("Please include this when reporting the bug on: https://github.com/godotengine/godot/issues"));
  1318. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/occlusion_culling/bvh_build_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), 2);
  1319. GLOBAL_DEF_RST("rendering/occlusion_culling/jitter_projection", true);
  1320. GLOBAL_DEF_RST("internationalization/rendering/force_right_to_left_layout_direction", false);
  1321. 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);
  1322. GLOBAL_DEF_BASIC("internationalization/rendering/root_node_auto_translate", true);
  1323. GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/timers/incremental_search_max_interval_msec", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"), 2000);
  1324. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);
  1325. #ifdef TOOLS_ENABLED
  1326. GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5);
  1327. #endif
  1328. GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
  1329. GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);
  1330. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/frame_queue_size", PROPERTY_HINT_RANGE, "2,3,1"), 2);
  1331. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/swapchain_image_count", PROPERTY_HINT_RANGE, "2,4,1"), 3);
  1332. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/block_size_kb", PROPERTY_HINT_RANGE, "4,2048,1,or_greater"), 256);
  1333. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/max_size_mb", PROPERTY_HINT_RANGE, "1,1024,1,or_greater"), 128);
  1334. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_upload_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1335. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_download_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1336. GLOBAL_DEF_RST(PropertyInfo(Variant::BOOL, "rendering/rendering_device/pipeline_cache/enable"), true);
  1337. 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);
  1338. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/vulkan/max_descriptors_per_pool", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1339. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", 16384);
  1340. custom_prop_info["rendering/rendering_device/d3d12/max_resource_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", PROPERTY_HINT_RANGE, "512,262144");
  1341. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", 1024);
  1342. custom_prop_info["rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", PROPERTY_HINT_RANGE, "256,2048");
  1343. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", 512);
  1344. custom_prop_info["rendering/rendering_device/d3d12/max_misc_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", PROPERTY_HINT_RANGE, "32,4096");
  1345. // The default value must match the minor part of the Agility SDK version
  1346. // installed by the scripts provided in the repository
  1347. // (check `misc/scripts/install_d3d12_sdk_windows.py`).
  1348. // For example, if the script installs 1.613.3, the default value must be 613.
  1349. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/agility_sdk_version", PROPERTY_HINT_RANGE, "0,10000,1,or_greater,hide_slider"), 613);
  1350. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), 1);
  1351. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror"), 0);
  1352. GLOBAL_DEF("collada/use_ambient", false);
  1353. // Input settings
  1354. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_long_press_as_right_click", false);
  1355. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_pan_and_scale_gestures", false);
  1356. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "input_devices/pointing/android/rotary_input_scroll_axis", PROPERTY_HINT_ENUM, "Horizontal,Vertical"), 1);
  1357. // These properties will not show up in the dialog. If you want to exclude whole groups, use add_hidden_prefix().
  1358. GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray());
  1359. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray());
  1360. GLOBAL_DEF_INTERNAL("internationalization/locale/translations", PackedStringArray());
  1361. GLOBAL_DEF_INTERNAL("internationalization/locale/translations_pot_files", PackedStringArray());
  1362. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_add_builtin_strings_to_pot", false);
  1363. ProjectSettings::get_singleton()->add_hidden_prefix("input/");
  1364. }
  1365. ProjectSettings::ProjectSettings(const String &p_path) {
  1366. if (load_custom(p_path) == OK) {
  1367. resource_path = p_path.get_base_dir();
  1368. project_loaded = true;
  1369. }
  1370. }
  1371. ProjectSettings::~ProjectSettings() {
  1372. if (singleton == this) {
  1373. singleton = nullptr;
  1374. }
  1375. }