project_settings.cpp 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. /*************************************************************************/
  2. /* project_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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/core_string_names.h"
  33. #include "core/input/input_map.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_network.h"
  37. #include "core/io/file_access_pack.h"
  38. #include "core/io/marshalls.h"
  39. #include "core/os/keyboard.h"
  40. #include "core/variant/variant_parser.h"
  41. #include "core/version.h"
  42. #include "modules/modules_enabled.gen.h" // For mono.
  43. const String ProjectSettings::PROJECT_DATA_DIR_NAME_SUFFIX = "godot";
  44. ProjectSettings *ProjectSettings::singleton = nullptr;
  45. ProjectSettings *ProjectSettings::get_singleton() {
  46. return singleton;
  47. }
  48. String ProjectSettings::get_project_data_dir_name() const {
  49. return project_data_dir_name;
  50. }
  51. String ProjectSettings::get_project_data_path() const {
  52. return "res://" + get_project_data_dir_name();
  53. }
  54. String ProjectSettings::get_resource_path() const {
  55. return resource_path;
  56. }
  57. String ProjectSettings::get_safe_project_name() const {
  58. String safe_name = OS::get_singleton()->get_safe_dir_name(get("application/config/name"));
  59. if (safe_name.is_empty()) {
  60. safe_name = "UnnamedProject";
  61. }
  62. return safe_name;
  63. }
  64. String ProjectSettings::get_imported_files_path() const {
  65. return get_project_data_path().plus_file("imported");
  66. }
  67. // Returns the features that a project must have when opened with this build of Godot.
  68. // This is used by the project manager to provide the initial_settings for config/features.
  69. const PackedStringArray ProjectSettings::get_required_features() {
  70. PackedStringArray features = PackedStringArray();
  71. features.append(VERSION_BRANCH);
  72. #ifdef REAL_T_IS_DOUBLE
  73. features.append("Double Precision");
  74. #endif
  75. return features;
  76. }
  77. // Returns the features supported by this build of Godot. Includes all required features.
  78. const PackedStringArray ProjectSettings::_get_supported_features() {
  79. PackedStringArray features = get_required_features();
  80. #ifdef MODULE_MONO_ENABLED
  81. features.append("C#");
  82. #endif
  83. // Allow pinning to a specific patch number or build type by marking
  84. // them as supported. They're only used if the user adds them manually.
  85. features.append(VERSION_BRANCH "." _MKSTR(VERSION_PATCH));
  86. features.append(VERSION_FULL_CONFIG);
  87. features.append(VERSION_FULL_BUILD);
  88. // For now, assume Vulkan is always supported.
  89. // This should be removed if it's possible to build the editor without Vulkan.
  90. features.append("Vulkan Clustered");
  91. features.append("Vulkan Mobile");
  92. return features;
  93. }
  94. // Returns the features that this project needs but this build of Godot lacks.
  95. const PackedStringArray ProjectSettings::get_unsupported_features(const PackedStringArray &p_project_features) {
  96. PackedStringArray unsupported_features = PackedStringArray();
  97. PackedStringArray supported_features = singleton->_get_supported_features();
  98. for (int i = 0; i < p_project_features.size(); i++) {
  99. if (!supported_features.has(p_project_features[i])) {
  100. unsupported_features.append(p_project_features[i]);
  101. }
  102. }
  103. unsupported_features.sort();
  104. return unsupported_features;
  105. }
  106. // Returns the features that both this project has and this build of Godot has, ensuring required features exist.
  107. const PackedStringArray ProjectSettings::_trim_to_supported_features(const PackedStringArray &p_project_features) {
  108. // Remove unsupported features if present.
  109. PackedStringArray features = PackedStringArray(p_project_features);
  110. PackedStringArray supported_features = _get_supported_features();
  111. for (int i = p_project_features.size() - 1; i > -1; i--) {
  112. if (!supported_features.has(p_project_features[i])) {
  113. features.remove_at(i);
  114. }
  115. }
  116. // Add required features if not present.
  117. PackedStringArray required_features = get_required_features();
  118. for (int i = 0; i < required_features.size(); i++) {
  119. if (!features.has(required_features[i])) {
  120. features.append(required_features[i]);
  121. }
  122. }
  123. features.sort();
  124. return features;
  125. }
  126. String ProjectSettings::localize_path(const String &p_path) const {
  127. if (resource_path.is_empty() || p_path.begins_with("res://") || p_path.begins_with("user://") ||
  128. (p_path.is_absolute_path() && !p_path.begins_with(resource_path))) {
  129. return p_path.simplify_path();
  130. }
  131. Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  132. String path = p_path.replace("\\", "/").simplify_path();
  133. if (dir->change_dir(path) == OK) {
  134. String cwd = dir->get_current_dir();
  135. cwd = cwd.replace("\\", "/");
  136. // Ensure that we end with a '/'.
  137. // This is important to ensure that we do not wrongly localize the resource path
  138. // in an absolute path that just happens to contain this string but points to a
  139. // different folder (e.g. "/my/project" as resource_path would be contained in
  140. // "/my/project_data", even though the latter is not part of res://.
  141. // `plus_file("")` is an easy way to ensure we have a trailing '/'.
  142. const String res_path = resource_path.plus_file("");
  143. // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
  144. // so we must make sure we have it as well in order to compare with 'res_path'.
  145. cwd = cwd.plus_file("");
  146. if (!cwd.begins_with(res_path)) {
  147. return p_path;
  148. }
  149. return cwd.replace_first(res_path, "res://");
  150. } else {
  151. int sep = path.rfind("/");
  152. if (sep == -1) {
  153. return "res://" + path;
  154. }
  155. String parent = path.substr(0, sep);
  156. String plocal = localize_path(parent);
  157. if (plocal.is_empty()) {
  158. return "";
  159. }
  160. // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
  161. if (plocal[plocal.length() - 1] == '/') {
  162. sep += 1;
  163. }
  164. return plocal + path.substr(sep, path.size() - sep);
  165. }
  166. }
  167. void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
  168. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  169. props[p_name].initial = p_value;
  170. }
  171. void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
  172. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  173. props[p_name].restart_if_changed = p_restart;
  174. }
  175. void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) {
  176. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  177. props[p_name].basic = p_basic;
  178. }
  179. void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) {
  180. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  181. #ifdef DEBUG_METHODS_ENABLED
  182. props[p_name].ignore_value_in_docs = p_ignore;
  183. #endif
  184. }
  185. bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
  186. ERR_FAIL_COND_V_MSG(!props.has(p_name), false, "Request for nonexistent project setting: " + p_name + ".");
  187. #ifdef DEBUG_METHODS_ENABLED
  188. return props[p_name].ignore_value_in_docs;
  189. #else
  190. return false;
  191. #endif
  192. }
  193. String ProjectSettings::globalize_path(const String &p_path) const {
  194. if (p_path.begins_with("res://")) {
  195. if (!resource_path.is_empty()) {
  196. return p_path.replace("res:/", resource_path);
  197. }
  198. return p_path.replace("res://", "");
  199. } else if (p_path.begins_with("user://")) {
  200. String data_dir = OS::get_singleton()->get_user_data_dir();
  201. if (!data_dir.is_empty()) {
  202. return p_path.replace("user:/", data_dir);
  203. }
  204. return p_path.replace("user://", "");
  205. }
  206. return p_path;
  207. }
  208. bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
  209. _THREAD_SAFE_METHOD_
  210. if (p_value.get_type() == Variant::NIL) {
  211. props.erase(p_name);
  212. if (p_name.operator String().begins_with("autoload/")) {
  213. String node_name = p_name.operator String().split("/")[1];
  214. if (autoloads.has(node_name)) {
  215. remove_autoload(node_name);
  216. }
  217. }
  218. } else {
  219. if (p_name == CoreStringNames::get_singleton()->_custom_features) {
  220. Vector<String> custom_feature_array = String(p_value).split(",");
  221. for (int i = 0; i < custom_feature_array.size(); i++) {
  222. custom_features.insert(custom_feature_array[i]);
  223. }
  224. return true;
  225. }
  226. if (!disable_feature_overrides) {
  227. int dot = p_name.operator String().find(".");
  228. if (dot != -1) {
  229. Vector<String> s = p_name.operator String().split(".");
  230. bool override_valid = false;
  231. for (int i = 1; i < s.size(); i++) {
  232. String feature = s[i].strip_edges();
  233. if (OS::get_singleton()->has_feature(feature) || custom_features.has(feature)) {
  234. override_valid = true;
  235. break;
  236. }
  237. }
  238. if (override_valid) {
  239. feature_overrides[s[0]] = p_name;
  240. }
  241. }
  242. }
  243. if (props.has(p_name)) {
  244. if (!props[p_name].overridden) {
  245. props[p_name].variant = p_value;
  246. }
  247. } else {
  248. props[p_name] = VariantContainer(p_value, last_order++);
  249. }
  250. if (p_name.operator String().begins_with("autoload/")) {
  251. String node_name = p_name.operator String().split("/")[1];
  252. AutoloadInfo autoload;
  253. autoload.name = node_name;
  254. String path = p_value;
  255. if (path.begins_with("*")) {
  256. autoload.is_singleton = true;
  257. autoload.path = path.substr(1);
  258. } else {
  259. autoload.path = path;
  260. }
  261. add_autoload(autoload);
  262. }
  263. }
  264. return true;
  265. }
  266. bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
  267. _THREAD_SAFE_METHOD_
  268. StringName name = p_name;
  269. if (!disable_feature_overrides && feature_overrides.has(name)) {
  270. name = feature_overrides[name];
  271. }
  272. if (!props.has(name)) {
  273. WARN_PRINT("Property not found: " + String(name));
  274. return false;
  275. }
  276. r_ret = props[name].variant;
  277. return true;
  278. }
  279. struct _VCSort {
  280. String name;
  281. Variant::Type type = Variant::VARIANT_MAX;
  282. int order = 0;
  283. uint32_t flags = 0;
  284. bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
  285. };
  286. void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  287. _THREAD_SAFE_METHOD_
  288. Set<_VCSort> vclist;
  289. for (const KeyValue<StringName, VariantContainer> &E : props) {
  290. const VariantContainer *v = &E.value;
  291. if (v->hide_from_editor) {
  292. continue;
  293. }
  294. _VCSort vc;
  295. vc.name = E.key;
  296. vc.order = v->order;
  297. vc.type = v->variant.get_type();
  298. if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) {
  299. vc.flags = PROPERTY_USAGE_STORAGE;
  300. } else {
  301. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  302. }
  303. if (v->basic) {
  304. vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  305. }
  306. if (v->restart_if_changed) {
  307. vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  308. }
  309. vclist.insert(vc);
  310. }
  311. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  312. String prop_info_name = E->get().name;
  313. int dot = prop_info_name.find(".");
  314. if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
  315. prop_info_name = prop_info_name.substr(0, dot);
  316. }
  317. if (custom_prop_info.has(prop_info_name)) {
  318. PropertyInfo pi = custom_prop_info[prop_info_name];
  319. pi.name = E->get().name;
  320. pi.usage = E->get().flags;
  321. p_list->push_back(pi);
  322. } else {
  323. p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags));
  324. }
  325. }
  326. }
  327. bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
  328. if (PackedData::get_singleton()->is_disabled()) {
  329. return false;
  330. }
  331. bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK;
  332. if (!ok) {
  333. return false;
  334. }
  335. //if data.pck is found, all directory access will be from here
  336. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  337. using_datapack = true;
  338. return true;
  339. }
  340. void ProjectSettings::_convert_to_last_version(int p_from_version) {
  341. if (p_from_version <= 3) {
  342. // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
  343. for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
  344. Variant value = E.value.variant;
  345. if (String(E.key).begins_with("input/") && value.get_type() == Variant::ARRAY) {
  346. Array array = value;
  347. Dictionary action;
  348. action["deadzone"] = Variant(0.5f);
  349. action["events"] = array;
  350. E.value.variant = action;
  351. }
  352. }
  353. }
  354. }
  355. /*
  356. * This method is responsible for loading a project.godot file and/or data file
  357. * using the following merit order:
  358. * - If using NetworkClient, try to lookup project file or fail.
  359. * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
  360. * - Search for project PCKs automatically. For each step we try loading a potential
  361. * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds,
  362. * we try loading the project settings, and abort if it fails. Steps:
  363. * o Bundled PCK in the executable.
  364. * o [macOS only] PCK with same basename as the binary in the .app resource dir.
  365. * o PCK with same basename as the binary in the binary's directory. We handle both
  366. * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and
  367. * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck').
  368. * o PCK with the same basename as the binary in the current working directory.
  369. * Same as above for the two possible PCK file names.
  370. * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
  371. * If found, load it or fail.
  372. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
  373. * are running from source code.
  374. * If not found and `p_upwards` is true (--upwards passed by the user), look for
  375. * project files in parent folders up to the system root (used to run a game
  376. * from command line while in a subfolder).
  377. * If a project file is found, load it or fail.
  378. * If nothing was found, error out.
  379. */
  380. Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  381. // If looking for files in a network client, use it directly
  382. if (FileAccessNetworkClient::get_singleton()) {
  383. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  384. if (err == OK && !p_ignore_override) {
  385. // Optional, we don't mind if it fails
  386. _load_settings_text("res://override.cfg");
  387. }
  388. return err;
  389. }
  390. // Attempt with a user-defined main pack first
  391. if (!p_main_pack.is_empty()) {
  392. bool ok = _load_resource_pack(p_main_pack);
  393. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'.");
  394. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  395. if (err == OK && !p_ignore_override) {
  396. // Load override from location of the main pack
  397. // Optional, we don't mind if it fails
  398. _load_settings_text(p_main_pack.get_base_dir().plus_file("override.cfg"));
  399. }
  400. return err;
  401. }
  402. String exec_path = OS::get_singleton()->get_executable_path();
  403. if (!exec_path.is_empty()) {
  404. // We do several tests sequentially until one succeeds to find a PCK,
  405. // and if so, we attempt loading it at the end.
  406. // Attempt with PCK bundled into executable.
  407. bool found = _load_resource_pack(exec_path);
  408. // Attempt with exec_name.pck.
  409. // (This is the usual case when distributing a Godot game.)
  410. String exec_dir = exec_path.get_base_dir();
  411. String exec_filename = exec_path.get_file();
  412. String exec_basename = exec_filename.get_basename();
  413. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  414. // or the exec path's basename + '.pck' (Windows).
  415. // We need to test both possibilities as extensions for Linux binaries are optional
  416. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  417. #ifdef OSX_ENABLED
  418. if (!found) {
  419. // Attempt to load PCK from macOS .app bundle resources.
  420. found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_filename + ".pck"));
  421. }
  422. #endif
  423. if (!found) {
  424. // Try to load data pack at the location of the executable.
  425. // As mentioned above, we have two potential names to attempt.
  426. found = _load_resource_pack(exec_dir.plus_file(exec_basename + ".pck")) || _load_resource_pack(exec_dir.plus_file(exec_filename + ".pck"));
  427. }
  428. if (!found) {
  429. // If we couldn't find them next to the executable, we attempt
  430. // the current working directory. Same story, two tests.
  431. found = _load_resource_pack(exec_basename + ".pck") || _load_resource_pack(exec_filename + ".pck");
  432. }
  433. // If we opened our package, try and load our project.
  434. if (found) {
  435. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  436. if (err == OK && !p_ignore_override) {
  437. // Load override from location of the executable.
  438. // Optional, we don't mind if it fails.
  439. _load_settings_text(exec_path.get_base_dir().plus_file("override.cfg"));
  440. }
  441. return err;
  442. }
  443. }
  444. // Try to use the filesystem for files, according to OS.
  445. // (Only Android -when reading from pck- and iOS use this.)
  446. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  447. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  448. // If the OS would rather use a specific location, then it will not be empty.
  449. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  450. if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') {
  451. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  452. }
  453. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  454. if (err == OK && !p_ignore_override) {
  455. // Optional, we don't mind if it fails.
  456. _load_settings_text("res://override.cfg");
  457. }
  458. return err;
  459. }
  460. // Nothing was found, try to find a project file in provided path (`p_path`)
  461. // or, if requested (`p_upwards`) in parent directories.
  462. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  463. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'.");
  464. d->change_dir(p_path);
  465. String current_dir = d->get_current_dir();
  466. bool found = false;
  467. Error err;
  468. while (true) {
  469. // Set the resource path early so things can be resolved when loading.
  470. resource_path = current_dir;
  471. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  472. err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
  473. if (err == OK && !p_ignore_override) {
  474. // Optional, we don't mind if it fails.
  475. _load_settings_text(current_dir.plus_file("override.cfg"));
  476. found = true;
  477. break;
  478. }
  479. if (p_upwards) {
  480. // Try to load settings ascending through parent directories
  481. d->change_dir("..");
  482. if (d->get_current_dir() == current_dir) {
  483. break; // not doing anything useful
  484. }
  485. current_dir = d->get_current_dir();
  486. } else {
  487. break;
  488. }
  489. }
  490. if (!found) {
  491. return err;
  492. }
  493. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  494. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  495. }
  496. return OK;
  497. }
  498. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  499. Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override);
  500. if (err == OK) {
  501. String custom_settings = GLOBAL_DEF("application/config/project_settings_override", "");
  502. if (!custom_settings.is_empty()) {
  503. _load_settings_text(custom_settings);
  504. }
  505. }
  506. // Updating the default value after the project settings have loaded.
  507. bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory");
  508. project_data_dir_name = (use_hidden_directory ? "." : "") + PROJECT_DATA_DIR_NAME_SUFFIX;
  509. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  510. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  511. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  512. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  513. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  514. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  515. return err;
  516. }
  517. bool ProjectSettings::has_setting(String p_var) const {
  518. _THREAD_SAFE_METHOD_
  519. return props.has(p_var);
  520. }
  521. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  522. Error err;
  523. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  524. if (err != OK) {
  525. return err;
  526. }
  527. uint8_t hdr[4];
  528. f->get_buffer(hdr, 4);
  529. 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).");
  530. uint32_t count = f->get_32();
  531. for (uint32_t i = 0; i < count; i++) {
  532. uint32_t slen = f->get_32();
  533. CharString cs;
  534. cs.resize(slen + 1);
  535. cs[slen] = 0;
  536. f->get_buffer((uint8_t *)cs.ptr(), slen);
  537. String key;
  538. key.parse_utf8(cs.ptr());
  539. uint32_t vlen = f->get_32();
  540. Vector<uint8_t> d;
  541. d.resize(vlen);
  542. f->get_buffer(d.ptrw(), vlen);
  543. Variant value;
  544. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  545. ERR_CONTINUE_MSG(err != OK, "Error decoding property: " + key + ".");
  546. set(key, value);
  547. }
  548. return OK;
  549. }
  550. Error ProjectSettings::_load_settings_text(const String &p_path) {
  551. Error err;
  552. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  553. if (f.is_null()) {
  554. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  555. // This needs to be streamlined if we want decent error reporting
  556. return ERR_FILE_NOT_FOUND;
  557. }
  558. VariantParser::StreamFile stream;
  559. stream.f = f;
  560. String assign;
  561. Variant value;
  562. VariantParser::Tag next_tag;
  563. int lines = 0;
  564. String error_text;
  565. String section;
  566. int config_version = 0;
  567. while (true) {
  568. assign = Variant();
  569. next_tag.fields.clear();
  570. next_tag.name = String();
  571. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  572. if (err == ERR_FILE_EOF) {
  573. // If we're loading a project.godot from source code, we can operate some
  574. // ProjectSettings conversions if need be.
  575. _convert_to_last_version(config_version);
  576. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  577. return OK;
  578. }
  579. ERR_FAIL_COND_V_MSG(err != OK, err, "Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
  580. if (!assign.is_empty()) {
  581. if (section.is_empty() && assign == "config_version") {
  582. config_version = value;
  583. 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));
  584. } else {
  585. if (section.is_empty()) {
  586. set(assign, value);
  587. } else {
  588. set(section + "/" + assign, value);
  589. }
  590. }
  591. } else if (!next_tag.name.is_empty()) {
  592. section = next_tag.name;
  593. }
  594. }
  595. }
  596. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  597. // Attempt first to load the binary project.godot file.
  598. Error err = _load_settings_binary(p_bin_path);
  599. if (err == OK) {
  600. return OK;
  601. } else if (err != ERR_FILE_NOT_FOUND) {
  602. // If the file exists but can't be loaded, we want to know it.
  603. ERR_PRINT("Couldn't load file '" + p_bin_path + "', error code " + itos(err) + ".");
  604. }
  605. // Fallback to text-based project.godot file if binary was not found.
  606. err = _load_settings_text(p_text_path);
  607. if (err == OK) {
  608. return OK;
  609. } else if (err != ERR_FILE_NOT_FOUND) {
  610. ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err) + ".");
  611. }
  612. return err;
  613. }
  614. Error ProjectSettings::load_custom(const String &p_path) {
  615. if (p_path.ends_with(".binary")) {
  616. return _load_settings_binary(p_path);
  617. }
  618. return _load_settings_text(p_path);
  619. }
  620. int ProjectSettings::get_order(const String &p_name) const {
  621. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + ".");
  622. return props[p_name].order;
  623. }
  624. void ProjectSettings::set_order(const String &p_name, int p_order) {
  625. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  626. props[p_name].order = p_order;
  627. }
  628. void ProjectSettings::set_builtin_order(const String &p_name) {
  629. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  630. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  631. props[p_name].order = last_builtin_order++;
  632. }
  633. }
  634. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  635. // Return true because a false negative is worse than a false positive.
  636. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, "Request for nonexistent project setting: " + p_name + ".");
  637. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  638. }
  639. void ProjectSettings::clear(const String &p_name) {
  640. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  641. props.erase(p_name);
  642. }
  643. Error ProjectSettings::save() {
  644. Error error = save_custom(get_resource_path().plus_file("project.godot"));
  645. if (error == OK) {
  646. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  647. }
  648. return error;
  649. }
  650. Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  651. Error err;
  652. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  653. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
  654. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  655. file->store_buffer(hdr, 4);
  656. int count = 0;
  657. for (const KeyValue<String, List<String>> &E : props) {
  658. count += E.value.size();
  659. }
  660. if (!p_custom_features.is_empty()) {
  661. file->store_32(count + 1);
  662. //store how many properties are saved, add one for custom featuers, which must always go first
  663. String key = CoreStringNames::get_singleton()->_custom_features;
  664. file->store_pascal_string(key);
  665. int len;
  666. err = encode_variant(p_custom_features, nullptr, len, false);
  667. ERR_FAIL_COND_V(err != OK, err);
  668. Vector<uint8_t> buff;
  669. buff.resize(len);
  670. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  671. ERR_FAIL_COND_V(err != OK, err);
  672. file->store_32(len);
  673. file->store_buffer(buff.ptr(), buff.size());
  674. } else {
  675. file->store_32(count); //store how many properties are saved
  676. }
  677. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  678. for (String &key : E->get()) {
  679. if (!E->key().is_empty()) {
  680. key = E->key() + "/" + key;
  681. }
  682. Variant value;
  683. if (p_custom.has(key)) {
  684. value = p_custom[key];
  685. } else {
  686. value = get(key);
  687. }
  688. file->store_pascal_string(key);
  689. int len;
  690. err = encode_variant(value, nullptr, len, true);
  691. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  692. Vector<uint8_t> buff;
  693. buff.resize(len);
  694. err = encode_variant(value, buff.ptrw(), len, true);
  695. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  696. file->store_32(len);
  697. file->store_buffer(buff.ptr(), buff.size());
  698. }
  699. }
  700. return OK;
  701. }
  702. Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  703. Error err;
  704. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  705. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
  706. file->store_line("; Engine configuration file.");
  707. file->store_line("; It's best edited using the editor UI and not directly,");
  708. file->store_line("; since the parameters that go here are not all obvious.");
  709. file->store_line(";");
  710. file->store_line("; Format:");
  711. file->store_line("; [section] ; section goes between []");
  712. file->store_line("; param=value ; assign values to parameters");
  713. file->store_line("");
  714. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  715. if (!p_custom_features.is_empty()) {
  716. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  717. }
  718. file->store_string("\n");
  719. for (const Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  720. if (E != props.front()) {
  721. file->store_string("\n");
  722. }
  723. if (!E->key().is_empty()) {
  724. file->store_string("[" + E->key() + "]\n\n");
  725. }
  726. for (const String &F : E->get()) {
  727. String key = F;
  728. if (!E->key().is_empty()) {
  729. key = E->key() + "/" + key;
  730. }
  731. Variant value;
  732. if (p_custom.has(key)) {
  733. value = p_custom[key];
  734. } else {
  735. value = get(key);
  736. }
  737. String vstr;
  738. VariantWriter::write_to_string(value, vstr);
  739. file->store_string(F.property_name_encode() + "=" + vstr + "\n");
  740. }
  741. }
  742. return OK;
  743. }
  744. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  745. return save_custom(p_file);
  746. }
  747. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  748. ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  749. PackedStringArray project_features = has_setting("application/config/features") ? (PackedStringArray)get_setting("application/config/features") : PackedStringArray();
  750. // If there is no feature list currently present, force one to generate.
  751. if (project_features.is_empty()) {
  752. project_features = ProjectSettings::get_required_features();
  753. }
  754. // Check the rendering API.
  755. const String rendering_api = has_setting("rendering/quality/driver/driver_name") ? (String)get_setting("rendering/quality/driver/driver_name") : String();
  756. if (!rendering_api.is_empty()) {
  757. // Add the rendering API as a project feature if it doesn't already exist.
  758. if (!project_features.has(rendering_api)) {
  759. project_features.append(rendering_api);
  760. }
  761. }
  762. // Check for the existence of a csproj file.
  763. if (FileAccess::exists(get_resource_path().plus_file(get_safe_project_name() + ".csproj"))) {
  764. // If there is a csproj file, add the C# feature if it doesn't already exist.
  765. if (!project_features.has("C#")) {
  766. project_features.append("C#");
  767. }
  768. } else {
  769. // If there isn't a csproj file, remove the C# feature if it exists.
  770. if (project_features.has("C#")) {
  771. project_features.remove_at(project_features.find("C#"));
  772. }
  773. }
  774. project_features = _trim_to_supported_features(project_features);
  775. set_setting("application/config/features", project_features);
  776. Set<_VCSort> vclist;
  777. if (p_merge_with_current) {
  778. for (const KeyValue<StringName, VariantContainer> &G : props) {
  779. const VariantContainer *v = &G.value;
  780. if (v->hide_from_editor) {
  781. continue;
  782. }
  783. if (p_custom.has(G.key)) {
  784. continue;
  785. }
  786. _VCSort vc;
  787. vc.name = G.key; //*k;
  788. vc.order = v->order;
  789. vc.type = v->variant.get_type();
  790. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  791. if (v->variant == v->initial) {
  792. continue;
  793. }
  794. vclist.insert(vc);
  795. }
  796. }
  797. for (const KeyValue<String, Variant> &E : p_custom) {
  798. // Lookup global prop to store in the same order
  799. Map<StringName, VariantContainer>::Element *global_prop = props.find(E.key);
  800. _VCSort vc;
  801. vc.name = E.key;
  802. vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
  803. vc.type = E.value.get_type();
  804. vc.flags = PROPERTY_USAGE_STORAGE;
  805. vclist.insert(vc);
  806. }
  807. Map<String, List<String>> props;
  808. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  809. String category = E->get().name;
  810. String name = E->get().name;
  811. int div = category.find("/");
  812. if (div < 0) {
  813. category = "";
  814. } else {
  815. category = category.substr(0, div);
  816. name = name.substr(div + 1, name.size());
  817. }
  818. props[category].push_back(name);
  819. }
  820. String custom_features;
  821. for (int i = 0; i < p_custom_features.size(); i++) {
  822. if (i > 0) {
  823. custom_features += ",";
  824. }
  825. String f = p_custom_features[i].strip_edges().replace("\"", "");
  826. custom_features += f;
  827. }
  828. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  829. return _save_settings_text(p_path, props, p_custom, custom_features);
  830. } else if (p_path.ends_with(".binary")) {
  831. return _save_settings_binary(p_path, props, p_custom, custom_features);
  832. } else {
  833. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
  834. }
  835. }
  836. 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) {
  837. Variant ret;
  838. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  839. ProjectSettings::get_singleton()->set(p_var, p_default);
  840. }
  841. ret = ProjectSettings::get_singleton()->get(p_var);
  842. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  843. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  844. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  845. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  846. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  847. return ret;
  848. }
  849. Vector<String> ProjectSettings::get_optimizer_presets() const {
  850. List<PropertyInfo> pi;
  851. ProjectSettings::get_singleton()->get_property_list(&pi);
  852. Vector<String> names;
  853. for (const PropertyInfo &E : pi) {
  854. if (!E.name.begins_with("optimizer_presets/")) {
  855. continue;
  856. }
  857. names.push_back(E.name.get_slicec('/', 1));
  858. }
  859. names.sort();
  860. return names;
  861. }
  862. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  863. ERR_FAIL_COND(!p_info.has("name"));
  864. ERR_FAIL_COND(!p_info.has("type"));
  865. PropertyInfo pinfo;
  866. pinfo.name = p_info["name"];
  867. ERR_FAIL_COND(!props.has(pinfo.name));
  868. pinfo.type = Variant::Type(p_info["type"].operator int());
  869. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  870. if (p_info.has("hint")) {
  871. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  872. }
  873. if (p_info.has("hint_string")) {
  874. pinfo.hint_string = p_info["hint_string"];
  875. }
  876. set_custom_property_info(pinfo.name, pinfo);
  877. }
  878. void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
  879. ERR_FAIL_COND(!props.has(p_prop));
  880. custom_prop_info[p_prop] = p_info;
  881. custom_prop_info[p_prop].name = p_prop;
  882. }
  883. const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  884. return custom_prop_info;
  885. }
  886. void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
  887. disable_feature_overrides = p_disable;
  888. }
  889. bool ProjectSettings::is_using_datapack() const {
  890. return using_datapack;
  891. }
  892. bool ProjectSettings::property_can_revert(const String &p_name) {
  893. if (!props.has(p_name)) {
  894. return false;
  895. }
  896. return props[p_name].initial != props[p_name].variant;
  897. }
  898. Variant ProjectSettings::property_get_revert(const String &p_name) {
  899. if (!props.has(p_name)) {
  900. return Variant();
  901. }
  902. return props[p_name].initial;
  903. }
  904. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  905. set(p_setting, p_value);
  906. }
  907. Variant ProjectSettings::get_setting(const String &p_setting) const {
  908. return get(p_setting);
  909. }
  910. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  911. return custom_features.has(p_feature);
  912. }
  913. OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
  914. return autoloads;
  915. }
  916. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  917. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  918. autoloads[p_autoload.name] = p_autoload;
  919. }
  920. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  921. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  922. autoloads.erase(p_autoload);
  923. }
  924. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  925. return autoloads.has(p_autoload);
  926. }
  927. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  928. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  929. return autoloads[p_name];
  930. }
  931. void ProjectSettings::_bind_methods() {
  932. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  933. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  934. ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
  935. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  936. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  937. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  938. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  939. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  940. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  941. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  942. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  943. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  944. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert);
  945. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert);
  946. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  947. }
  948. void ProjectSettings::_add_builtin_input_map() {
  949. if (InputMap::get_singleton()) {
  950. OrderedHashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  951. for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
  952. Array events;
  953. // Convert list of input events into array
  954. for (List<Ref<InputEvent>>::Element *I = E.get().front(); I; I = I->next()) {
  955. events.push_back(I->get());
  956. }
  957. Dictionary action;
  958. action["deadzone"] = Variant(0.5f);
  959. action["events"] = events;
  960. String action_name = "input/" + E.key();
  961. GLOBAL_DEF(action_name, action);
  962. input_presets.push_back(action_name);
  963. }
  964. }
  965. }
  966. ProjectSettings::ProjectSettings() {
  967. // Initialization of engine variables should be done in the setup() method,
  968. // so that the values can be overridden from project.godot or project.binary.
  969. singleton = this;
  970. GLOBAL_DEF_BASIC("application/config/name", "");
  971. GLOBAL_DEF_BASIC("application/config/name_localized", Dictionary());
  972. custom_prop_info["application/config/name_localized"] = PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING);
  973. GLOBAL_DEF_BASIC("application/config/description", "");
  974. custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
  975. GLOBAL_DEF_BASIC("application/run/main_scene", "");
  976. custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
  977. GLOBAL_DEF("application/run/disable_stdout", false);
  978. GLOBAL_DEF("application/run/disable_stderr", false);
  979. GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true);
  980. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  981. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  982. GLOBAL_DEF("application/config/project_settings_override", "");
  983. GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres");
  984. custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
  985. PackedStringArray extensions = PackedStringArray();
  986. extensions.push_back("gd");
  987. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  988. extensions.push_back("cs");
  989. }
  990. extensions.push_back("gdshader");
  991. GLOBAL_DEF("editor/run/main_run_args", "");
  992. GLOBAL_DEF("editor/script/search_in_file_extensions", extensions);
  993. custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions");
  994. GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
  995. custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);
  996. _add_builtin_input_map();
  997. // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
  998. 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");
  999. // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
  1000. custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");
  1001. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
  1002. GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
  1003. GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
  1004. GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
  1005. custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
  1006. GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
  1007. custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
  1008. GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
  1009. custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
  1010. GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
  1011. custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
  1012. GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
  1013. custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  1014. GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
  1015. custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  1016. }
  1017. ProjectSettings::~ProjectSettings() {
  1018. singleton = nullptr;
  1019. }