project_settings.cpp 42 KB

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