project_settings.cpp 41 KB

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