project_settings.cpp 46 KB

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