project_settings.cpp 41 KB

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