project_settings.cpp 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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/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 looking for files in a network client, use it directly
  306. if (FileAccessNetworkClient::get_singleton()) {
  307. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  308. if (err == OK && !p_ignore_override) {
  309. // Optional, we don't mind if it fails
  310. _load_settings_text("res://override.cfg");
  311. }
  312. return err;
  313. }
  314. // Attempt with a user-defined main pack first
  315. if (p_main_pack != "") {
  316. bool ok = _load_resource_pack(p_main_pack);
  317. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'.");
  318. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  319. if (err == OK && !p_ignore_override) {
  320. // Load override from location of the main pack
  321. // Optional, we don't mind if it fails
  322. _load_settings_text(p_main_pack.get_base_dir().plus_file("override.cfg"));
  323. }
  324. return err;
  325. }
  326. String exec_path = OS::get_singleton()->get_executable_path();
  327. if (exec_path != "") {
  328. // We do several tests sequentially until one succeeds to find a PCK,
  329. // and if so we attempt loading it at the end.
  330. // Attempt with PCK bundled into executable.
  331. bool found = _load_resource_pack(exec_path);
  332. // Attempt with exec_name.pck.
  333. // (This is the usual case when distributing a Godot game.)
  334. String exec_dir = exec_path.get_base_dir();
  335. String exec_filename = exec_path.get_file();
  336. String exec_basename = exec_filename.get_basename();
  337. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  338. // or the exec path's basename + '.pck' (Windows).
  339. // We need to test both possibilities as extensions for Linux binaries are optional
  340. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  341. #ifdef OSX_ENABLED
  342. if (!found) {
  343. // Attempt to load PCK from macOS .app bundle resources.
  344. 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"));
  345. }
  346. #endif
  347. if (!found) {
  348. // Try to load data pack at the location of the executable.
  349. // As mentioned above, we have two potential names to attempt.
  350. found = _load_resource_pack(exec_dir.plus_file(exec_basename + ".pck")) || _load_resource_pack(exec_dir.plus_file(exec_filename + ".pck"));
  351. }
  352. if (!found) {
  353. // If we couldn't find them next to the executable, we attempt
  354. // the current working directory. Same story, two tests.
  355. found = _load_resource_pack(exec_basename + ".pck") || _load_resource_pack(exec_filename + ".pck");
  356. }
  357. // If we opened our package, try and load our project.
  358. if (found) {
  359. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  360. if (err == OK && !p_ignore_override) {
  361. // Load override from location of the executable.
  362. // Optional, we don't mind if it fails.
  363. _load_settings_text(exec_path.get_base_dir().plus_file("override.cfg"));
  364. }
  365. return err;
  366. }
  367. }
  368. // Try to use the filesystem for files, according to OS.
  369. // (Only Android -when reading from pck- and iOS use this.)
  370. if (OS::get_singleton()->get_resource_dir() != "") {
  371. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  372. // If the OS would rather use a specific location, then it will not be empty.
  373. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  374. if (resource_path != "" && resource_path[resource_path.length() - 1] == '/') {
  375. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  376. }
  377. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  378. if (err == OK && !p_ignore_override) {
  379. // Optional, we don't mind if it fails.
  380. _load_settings_text("res://override.cfg");
  381. }
  382. return err;
  383. }
  384. // Nothing was found, try to find a project file in provided path (`p_path`)
  385. // or, if requested (`p_upwards`) in parent directories.
  386. DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  387. ERR_FAIL_COND_V_MSG(!d, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'.");
  388. d->change_dir(p_path);
  389. String current_dir = d->get_current_dir();
  390. String candidate = current_dir;
  391. bool found = false;
  392. Error err;
  393. while (true) {
  394. err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
  395. if (err == OK && !p_ignore_override) {
  396. // Optional, we don't mind if it fails.
  397. _load_settings_text(current_dir.plus_file("override.cfg"));
  398. candidate = current_dir;
  399. found = true;
  400. break;
  401. }
  402. if (p_upwards) {
  403. // Try to load settings ascending through parent directories
  404. d->change_dir("..");
  405. if (d->get_current_dir() == current_dir) {
  406. break; // not doing anything useful
  407. }
  408. current_dir = d->get_current_dir();
  409. } else {
  410. break;
  411. }
  412. }
  413. resource_path = candidate;
  414. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  415. memdelete(d);
  416. if (!found) {
  417. return err;
  418. }
  419. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  420. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  421. }
  422. return OK;
  423. }
  424. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  425. Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override);
  426. if (err == OK) {
  427. String custom_settings = GLOBAL_DEF("application/config/project_settings_override", "");
  428. if (custom_settings != "") {
  429. _load_settings_text(custom_settings);
  430. }
  431. }
  432. // Updating the default value after the project settings have loaded.
  433. bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory");
  434. project_data_dir_name = (use_hidden_directory ? "." : "") + PROJECT_DATA_DIR_NAME_SUFFIX;
  435. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  436. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  437. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  438. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  439. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  440. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  441. return err;
  442. }
  443. bool ProjectSettings::has_setting(String p_var) const {
  444. _THREAD_SAFE_METHOD_
  445. return props.has(p_var);
  446. }
  447. void ProjectSettings::set_registering_order(bool p_enable) {
  448. registering_order = p_enable;
  449. }
  450. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  451. Error err;
  452. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  453. if (err != OK) {
  454. return err;
  455. }
  456. uint8_t hdr[4];
  457. f->get_buffer(hdr, 4);
  458. if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
  459. memdelete(f);
  460. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  461. }
  462. uint32_t count = f->get_32();
  463. for (uint32_t i = 0; i < count; i++) {
  464. uint32_t slen = f->get_32();
  465. CharString cs;
  466. cs.resize(slen + 1);
  467. cs[slen] = 0;
  468. f->get_buffer((uint8_t *)cs.ptr(), slen);
  469. String key;
  470. key.parse_utf8(cs.ptr());
  471. uint32_t vlen = f->get_32();
  472. Vector<uint8_t> d;
  473. d.resize(vlen);
  474. f->get_buffer(d.ptrw(), vlen);
  475. Variant value;
  476. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  477. ERR_CONTINUE_MSG(err != OK, "Error decoding property: " + key + ".");
  478. set(key, value);
  479. }
  480. f->close();
  481. memdelete(f);
  482. return OK;
  483. }
  484. Error ProjectSettings::_load_settings_text(const String &p_path) {
  485. Error err;
  486. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  487. if (!f) {
  488. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  489. // This needs to be streamlined if we want decent error reporting
  490. return ERR_FILE_NOT_FOUND;
  491. }
  492. VariantParser::StreamFile stream;
  493. stream.f = f;
  494. String assign;
  495. Variant value;
  496. VariantParser::Tag next_tag;
  497. int lines = 0;
  498. String error_text;
  499. String section;
  500. int config_version = 0;
  501. while (true) {
  502. assign = Variant();
  503. next_tag.fields.clear();
  504. next_tag.name = String();
  505. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  506. if (err == ERR_FILE_EOF) {
  507. memdelete(f);
  508. // If we're loading a project.godot from source code, we can operate some
  509. // ProjectSettings conversions if need be.
  510. _convert_to_last_version(config_version);
  511. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  512. return OK;
  513. } else if (err != OK) {
  514. ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
  515. memdelete(f);
  516. return err;
  517. }
  518. if (assign != String()) {
  519. if (section == String() && assign == "config_version") {
  520. config_version = value;
  521. if (config_version > CONFIG_VERSION) {
  522. memdelete(f);
  523. 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));
  524. }
  525. } else {
  526. if (section == String()) {
  527. set(assign, value);
  528. } else {
  529. set(section + "/" + assign, value);
  530. }
  531. }
  532. } else if (next_tag.name != String()) {
  533. section = next_tag.name;
  534. }
  535. }
  536. }
  537. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  538. // Attempt first to load the binary project.godot file.
  539. Error err = _load_settings_binary(p_bin_path);
  540. if (err == OK) {
  541. return OK;
  542. } else if (err != ERR_FILE_NOT_FOUND) {
  543. // If the file exists but can't be loaded, we want to know it.
  544. ERR_PRINT("Couldn't load file '" + p_bin_path + "', error code " + itos(err) + ".");
  545. }
  546. // Fallback to text-based project.godot file if binary was not found.
  547. err = _load_settings_text(p_text_path);
  548. if (err == OK) {
  549. return OK;
  550. } else if (err != ERR_FILE_NOT_FOUND) {
  551. ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err) + ".");
  552. }
  553. return err;
  554. }
  555. int ProjectSettings::get_order(const String &p_name) const {
  556. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + ".");
  557. return props[p_name].order;
  558. }
  559. void ProjectSettings::set_order(const String &p_name, int p_order) {
  560. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  561. props[p_name].order = p_order;
  562. }
  563. void ProjectSettings::set_builtin_order(const String &p_name) {
  564. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  565. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  566. props[p_name].order = last_builtin_order++;
  567. }
  568. }
  569. void ProjectSettings::clear(const String &p_name) {
  570. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  571. props.erase(p_name);
  572. }
  573. Error ProjectSettings::save() {
  574. Error error = save_custom(get_resource_path().plus_file("project.godot"));
  575. if (error == OK) {
  576. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  577. }
  578. return error;
  579. }
  580. Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  581. Error err;
  582. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  583. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
  584. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  585. file->store_buffer(hdr, 4);
  586. int count = 0;
  587. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  588. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  589. count++;
  590. }
  591. }
  592. if (p_custom_features != String()) {
  593. file->store_32(count + 1);
  594. //store how many properties are saved, add one for custom featuers, which must always go first
  595. String key = CoreStringNames::get_singleton()->_custom_features;
  596. file->store_pascal_string(key);
  597. int len;
  598. err = encode_variant(p_custom_features, nullptr, len, false);
  599. if (err != OK) {
  600. memdelete(file);
  601. ERR_FAIL_V(err);
  602. }
  603. Vector<uint8_t> buff;
  604. buff.resize(len);
  605. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  606. if (err != OK) {
  607. memdelete(file);
  608. ERR_FAIL_V(err);
  609. }
  610. file->store_32(len);
  611. file->store_buffer(buff.ptr(), buff.size());
  612. } else {
  613. file->store_32(count); //store how many properties are saved
  614. }
  615. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  616. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  617. String key = F->get();
  618. if (E->key() != "") {
  619. key = E->key() + "/" + key;
  620. }
  621. Variant value;
  622. if (p_custom.has(key)) {
  623. value = p_custom[key];
  624. } else {
  625. value = get(key);
  626. }
  627. file->store_pascal_string(key);
  628. int len;
  629. err = encode_variant(value, nullptr, len, true);
  630. if (err != OK) {
  631. memdelete(file);
  632. }
  633. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  634. Vector<uint8_t> buff;
  635. buff.resize(len);
  636. err = encode_variant(value, buff.ptrw(), len, true);
  637. if (err != OK) {
  638. memdelete(file);
  639. }
  640. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  641. file->store_32(len);
  642. file->store_buffer(buff.ptr(), buff.size());
  643. }
  644. }
  645. file->close();
  646. memdelete(file);
  647. return OK;
  648. }
  649. Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  650. Error err;
  651. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  652. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
  653. file->store_line("; Engine configuration file.");
  654. file->store_line("; It's best edited using the editor UI and not directly,");
  655. file->store_line("; since the parameters that go here are not all obvious.");
  656. file->store_line(";");
  657. file->store_line("; Format:");
  658. file->store_line("; [section] ; section goes between []");
  659. file->store_line("; param=value ; assign values to parameters");
  660. file->store_line("");
  661. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  662. if (p_custom_features != String()) {
  663. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  664. }
  665. file->store_string("\n");
  666. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  667. if (E != props.front()) {
  668. file->store_string("\n");
  669. }
  670. if (E->key() != "") {
  671. file->store_string("[" + E->key() + "]\n\n");
  672. }
  673. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  674. String key = F->get();
  675. if (E->key() != "") {
  676. key = E->key() + "/" + key;
  677. }
  678. Variant value;
  679. if (p_custom.has(key)) {
  680. value = p_custom[key];
  681. } else {
  682. value = get(key);
  683. }
  684. String vstr;
  685. VariantWriter::write_to_string(value, vstr);
  686. file->store_string(F->get().property_name_encode() + "=" + vstr + "\n");
  687. }
  688. }
  689. file->close();
  690. memdelete(file);
  691. return OK;
  692. }
  693. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  694. return save_custom(p_file);
  695. };
  696. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  697. ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  698. Set<_VCSort> vclist;
  699. if (p_merge_with_current) {
  700. for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
  701. const VariantContainer *v = &G->get();
  702. if (v->hide_from_editor) {
  703. continue;
  704. }
  705. if (p_custom.has(G->key())) {
  706. continue;
  707. }
  708. _VCSort vc;
  709. vc.name = G->key(); //*k;
  710. vc.order = v->order;
  711. vc.type = v->variant.get_type();
  712. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  713. if (v->variant == v->initial) {
  714. continue;
  715. }
  716. vclist.insert(vc);
  717. }
  718. }
  719. for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
  720. // Lookup global prop to store in the same order
  721. Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
  722. _VCSort vc;
  723. vc.name = E->key();
  724. vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
  725. vc.type = E->get().get_type();
  726. vc.flags = PROPERTY_USAGE_STORAGE;
  727. vclist.insert(vc);
  728. }
  729. Map<String, List<String>> props;
  730. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  731. String category = E->get().name;
  732. String name = E->get().name;
  733. int div = category.find("/");
  734. if (div < 0) {
  735. category = "";
  736. } else {
  737. category = category.substr(0, div);
  738. name = name.substr(div + 1, name.size());
  739. }
  740. props[category].push_back(name);
  741. }
  742. String custom_features;
  743. for (int i = 0; i < p_custom_features.size(); i++) {
  744. if (i > 0) {
  745. custom_features += ",";
  746. }
  747. String f = p_custom_features[i].strip_edges().replace("\"", "");
  748. custom_features += f;
  749. }
  750. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  751. return _save_settings_text(p_path, props, p_custom, custom_features);
  752. } else if (p_path.ends_with(".binary")) {
  753. return _save_settings_binary(p_path, props, p_custom, custom_features);
  754. } else {
  755. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
  756. }
  757. }
  758. Variant _GLOBAL_DEF_ALIAS(const String &p_var, const String &p_old_name, const Variant &p_default, bool p_restart_if_changed) {
  759. // if the new name setting isn't present, try the old one
  760. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  761. if (ProjectSettings::get_singleton()->has_setting(p_old_name)) {
  762. // if the old setting is present, get the value and set it in the new setting
  763. Variant value = ProjectSettings::get_singleton()->get(p_old_name);
  764. ProjectSettings::get_singleton()->set(p_var, value);
  765. }
  766. }
  767. return _GLOBAL_DEF(p_var, p_default, p_restart_if_changed);
  768. }
  769. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs) {
  770. Variant ret;
  771. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  772. ProjectSettings::get_singleton()->set(p_var, p_default);
  773. }
  774. ret = ProjectSettings::get_singleton()->get(p_var);
  775. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  776. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  777. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  778. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  779. return ret;
  780. }
  781. Vector<String> ProjectSettings::get_optimizer_presets() const {
  782. List<PropertyInfo> pi;
  783. ProjectSettings::get_singleton()->get_property_list(&pi);
  784. Vector<String> names;
  785. for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
  786. if (!E->get().name.begins_with("optimizer_presets/")) {
  787. continue;
  788. }
  789. names.push_back(E->get().name.get_slicec('/', 1));
  790. }
  791. names.sort();
  792. return names;
  793. }
  794. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  795. ERR_FAIL_COND(!p_info.has("name"));
  796. ERR_FAIL_COND(!p_info.has("type"));
  797. PropertyInfo pinfo;
  798. pinfo.name = p_info["name"];
  799. ERR_FAIL_COND(!props.has(pinfo.name));
  800. pinfo.type = Variant::Type(p_info["type"].operator int());
  801. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  802. if (p_info.has("hint")) {
  803. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  804. }
  805. if (p_info.has("hint_string")) {
  806. pinfo.hint_string = p_info["hint_string"];
  807. }
  808. set_custom_property_info(pinfo.name, pinfo);
  809. }
  810. void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
  811. ERR_FAIL_COND(!props.has(p_prop));
  812. custom_prop_info[p_prop] = p_info;
  813. custom_prop_info[p_prop].name = p_prop;
  814. }
  815. const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  816. return custom_prop_info;
  817. }
  818. void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
  819. disable_feature_overrides = p_disable;
  820. }
  821. bool ProjectSettings::is_using_datapack() const {
  822. return using_datapack;
  823. }
  824. bool ProjectSettings::property_can_revert(const String &p_name) {
  825. if (!props.has(p_name)) {
  826. return false;
  827. }
  828. return props[p_name].initial != props[p_name].variant;
  829. }
  830. Variant ProjectSettings::property_get_revert(const String &p_name) {
  831. if (!props.has(p_name)) {
  832. return Variant();
  833. }
  834. return props[p_name].initial;
  835. }
  836. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  837. set(p_setting, p_value);
  838. }
  839. Variant ProjectSettings::get_setting(const String &p_setting) const {
  840. return get(p_setting);
  841. }
  842. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  843. return custom_features.has(p_feature);
  844. }
  845. void ProjectSettings::_bind_methods() {
  846. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  847. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  848. ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
  849. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  850. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  851. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  852. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  853. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  854. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  855. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  856. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  857. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  858. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert);
  859. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert);
  860. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  861. ADD_SIGNAL(MethodInfo("project_settings_changed"));
  862. }
  863. ProjectSettings::ProjectSettings() {
  864. // Initialization of engine variables should be done in the setup() method,
  865. // so that the values can be overridden from project.godot or project.binary.
  866. singleton = this;
  867. last_order = NO_BUILTIN_ORDER_BASE;
  868. last_builtin_order = 0;
  869. disable_feature_overrides = false;
  870. registering_order = true;
  871. Array events;
  872. Dictionary action;
  873. Ref<InputEventKey> key;
  874. Ref<InputEventJoypadButton> joyb;
  875. GLOBAL_DEF("application/config/name", "");
  876. GLOBAL_DEF("application/config/description", "");
  877. custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
  878. GLOBAL_DEF("application/run/main_scene", "");
  879. custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
  880. GLOBAL_DEF("application/run/disable_stdout", false);
  881. GLOBAL_DEF("application/run/disable_stderr", false);
  882. GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true);
  883. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  884. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  885. GLOBAL_DEF("application/config/project_settings_override", "");
  886. GLOBAL_DEF("audio/default_bus_layout", "res://default_bus_layout.tres");
  887. custom_prop_info["audio/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
  888. PoolStringArray extensions = PoolStringArray();
  889. extensions.push_back("gd");
  890. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  891. extensions.push_back("cs");
  892. }
  893. extensions.push_back("gdshader");
  894. extensions.push_back("shader");
  895. GLOBAL_DEF("editor/main_run_args", "");
  896. GLOBAL_DEF("editor/search_in_file_extensions", extensions);
  897. custom_prop_info["editor/search_in_file_extensions"] = PropertyInfo(Variant::POOL_STRING_ARRAY, "editor/search_in_file_extensions");
  898. GLOBAL_DEF("editor/script_templates_search_path", "res://script_templates");
  899. custom_prop_info["editor/script_templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script_templates_search_path", PROPERTY_HINT_DIR);
  900. GLOBAL_DEF("editor/version_control/autoload_on_startup", false);
  901. GLOBAL_DEF("editor/version_control/plugin_name", "");
  902. action = Dictionary();
  903. action["deadzone"] = Variant(0.5f);
  904. events = Array();
  905. key.instance();
  906. key->set_scancode(KEY_ENTER);
  907. events.push_back(key);
  908. key.instance();
  909. key->set_scancode(KEY_KP_ENTER);
  910. events.push_back(key);
  911. key.instance();
  912. key->set_scancode(KEY_SPACE);
  913. events.push_back(key);
  914. joyb.instance();
  915. joyb->set_button_index(JOY_BUTTON_0);
  916. events.push_back(joyb);
  917. action["events"] = events;
  918. GLOBAL_DEF("input/ui_accept", action);
  919. input_presets.push_back("input/ui_accept");
  920. action = Dictionary();
  921. action["deadzone"] = Variant(0.5f);
  922. events = Array();
  923. key.instance();
  924. key->set_scancode(KEY_SPACE);
  925. events.push_back(key);
  926. joyb.instance();
  927. joyb->set_button_index(JOY_BUTTON_3);
  928. events.push_back(joyb);
  929. action["events"] = events;
  930. GLOBAL_DEF("input/ui_select", action);
  931. input_presets.push_back("input/ui_select");
  932. action = Dictionary();
  933. action["deadzone"] = Variant(0.5f);
  934. events = Array();
  935. key.instance();
  936. key->set_scancode(KEY_ESCAPE);
  937. events.push_back(key);
  938. joyb.instance();
  939. joyb->set_button_index(JOY_BUTTON_1);
  940. events.push_back(joyb);
  941. action["events"] = events;
  942. GLOBAL_DEF("input/ui_cancel", action);
  943. input_presets.push_back("input/ui_cancel");
  944. action = Dictionary();
  945. action["deadzone"] = Variant(0.5f);
  946. events = Array();
  947. key.instance();
  948. key->set_scancode(KEY_TAB);
  949. events.push_back(key);
  950. action["events"] = events;
  951. GLOBAL_DEF("input/ui_focus_next", action);
  952. input_presets.push_back("input/ui_focus_next");
  953. action = Dictionary();
  954. action["deadzone"] = Variant(0.5f);
  955. events = Array();
  956. key.instance();
  957. key->set_scancode(KEY_TAB);
  958. key->set_shift(true);
  959. events.push_back(key);
  960. action["events"] = events;
  961. GLOBAL_DEF("input/ui_focus_prev", action);
  962. input_presets.push_back("input/ui_focus_prev");
  963. action = Dictionary();
  964. action["deadzone"] = Variant(0.5f);
  965. events = Array();
  966. key.instance();
  967. key->set_scancode(KEY_LEFT);
  968. events.push_back(key);
  969. joyb.instance();
  970. joyb->set_button_index(JOY_DPAD_LEFT);
  971. events.push_back(joyb);
  972. action["events"] = events;
  973. GLOBAL_DEF("input/ui_left", action);
  974. input_presets.push_back("input/ui_left");
  975. action = Dictionary();
  976. action["deadzone"] = Variant(0.5f);
  977. events = Array();
  978. key.instance();
  979. key->set_scancode(KEY_RIGHT);
  980. events.push_back(key);
  981. joyb.instance();
  982. joyb->set_button_index(JOY_DPAD_RIGHT);
  983. events.push_back(joyb);
  984. action["events"] = events;
  985. GLOBAL_DEF("input/ui_right", action);
  986. input_presets.push_back("input/ui_right");
  987. action = Dictionary();
  988. action["deadzone"] = Variant(0.5f);
  989. events = Array();
  990. key.instance();
  991. key->set_scancode(KEY_UP);
  992. events.push_back(key);
  993. joyb.instance();
  994. joyb->set_button_index(JOY_DPAD_UP);
  995. events.push_back(joyb);
  996. action["events"] = events;
  997. GLOBAL_DEF("input/ui_up", action);
  998. input_presets.push_back("input/ui_up");
  999. action = Dictionary();
  1000. action["deadzone"] = Variant(0.5f);
  1001. events = Array();
  1002. key.instance();
  1003. key->set_scancode(KEY_DOWN);
  1004. events.push_back(key);
  1005. joyb.instance();
  1006. joyb->set_button_index(JOY_DPAD_DOWN);
  1007. events.push_back(joyb);
  1008. action["events"] = events;
  1009. GLOBAL_DEF("input/ui_down", action);
  1010. input_presets.push_back("input/ui_down");
  1011. action = Dictionary();
  1012. action["deadzone"] = Variant(0.5f);
  1013. events = Array();
  1014. key.instance();
  1015. key->set_scancode(KEY_PAGEUP);
  1016. events.push_back(key);
  1017. action["events"] = events;
  1018. GLOBAL_DEF("input/ui_page_up", action);
  1019. input_presets.push_back("input/ui_page_up");
  1020. action = Dictionary();
  1021. action["deadzone"] = Variant(0.5f);
  1022. events = Array();
  1023. key.instance();
  1024. key->set_scancode(KEY_PAGEDOWN);
  1025. events.push_back(key);
  1026. action["events"] = events;
  1027. GLOBAL_DEF("input/ui_page_down", action);
  1028. input_presets.push_back("input/ui_page_down");
  1029. action = Dictionary();
  1030. action["deadzone"] = Variant(0.5f);
  1031. events = Array();
  1032. key.instance();
  1033. key->set_scancode(KEY_HOME);
  1034. events.push_back(key);
  1035. action["events"] = events;
  1036. GLOBAL_DEF("input/ui_home", action);
  1037. input_presets.push_back("input/ui_home");
  1038. action = Dictionary();
  1039. action["deadzone"] = Variant(0.5f);
  1040. events = Array();
  1041. key.instance();
  1042. key->set_scancode(KEY_END);
  1043. events.push_back(key);
  1044. action["events"] = events;
  1045. GLOBAL_DEF("input/ui_end", action);
  1046. input_presets.push_back("input/ui_end");
  1047. 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");
  1048. custom_prop_info["rendering/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
  1049. custom_prop_info["physics/2d/thread_model"] = PropertyInfo(Variant::INT, "physics/2d/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
  1050. 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");
  1051. // Required to make the project setting appear even if the physics engine is GodotPhysics,
  1052. // while also making it appear in the ProjectSettings class documentation.
  1053. GLOBAL_DEF("physics/3d/smooth_trimesh_collision", false);
  1054. GLOBAL_DEF("rendering/quality/filters/sharpen_intensity", 0.0);
  1055. custom_prop_info["rendering/quality/filters/sharpen_intensity"] = PropertyInfo(Variant::REAL, "rendering/quality/filters/sharpen_intensity", PROPERTY_HINT_RANGE, "0,1");
  1056. GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
  1057. custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
  1058. GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
  1059. custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
  1060. GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
  1061. custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
  1062. GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
  1063. custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
  1064. GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
  1065. custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  1066. GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
  1067. custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  1068. // Would ideally be defined in an Android-specific file, but then it doesn't appear in the docs
  1069. GLOBAL_DEF("android/modules", "");
  1070. using_datapack = false;
  1071. }
  1072. ProjectSettings::~ProjectSettings() {
  1073. singleton = nullptr;
  1074. }