project_settings.cpp 42 KB

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