2
0

project_settings.cpp 68 KB

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