project_settings.cpp 39 KB

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