project_settings.cpp 39 KB

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