project_settings.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  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_PRINTS("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. // Attempt with PCK bundled into executable
  301. if (!found) {
  302. if (_load_resource_pack(exec_path)) {
  303. found = true;
  304. }
  305. }
  306. // If we opened our package, try and load our project
  307. if (found) {
  308. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  309. if (err == OK) {
  310. // Load override from location of executable
  311. // Optional, we don't mind if it fails
  312. _load_settings_text(exec_path.get_base_dir().plus_file("override.cfg"));
  313. }
  314. return err;
  315. }
  316. }
  317. // Try to use the filesystem for files, according to OS. (only Android -when reading from pck- and iOS use this)
  318. if (OS::get_singleton()->get_resource_dir() != "") {
  319. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  320. // If the OS would rather use a specific location, then it will not be empty.
  321. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  322. if (resource_path != "" && resource_path[resource_path.length() - 1] == '/') {
  323. resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
  324. }
  325. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  326. if (err == OK) {
  327. // Optional, we don't mind if it fails
  328. _load_settings_text("res://override.cfg");
  329. }
  330. return err;
  331. }
  332. // Nothing was found, try to find a project file in provided path (`p_path`)
  333. // or, if requested (`p_upwards`) in parent directories.
  334. DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  335. ERR_FAIL_COND_V_MSG(!d, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'.");
  336. d->change_dir(p_path);
  337. String current_dir = d->get_current_dir();
  338. String candidate = current_dir;
  339. bool found = false;
  340. Error err;
  341. while (true) {
  342. err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
  343. if (err == OK) {
  344. // Optional, we don't mind if it fails
  345. _load_settings_text(current_dir.plus_file("override.cfg"));
  346. candidate = current_dir;
  347. found = true;
  348. break;
  349. }
  350. if (p_upwards) {
  351. // Try to load settings ascending through parent directories
  352. d->change_dir("..");
  353. if (d->get_current_dir() == current_dir)
  354. break; // not doing anything useful
  355. current_dir = d->get_current_dir();
  356. } else {
  357. break;
  358. }
  359. }
  360. resource_path = candidate;
  361. resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case
  362. memdelete(d);
  363. if (!found)
  364. return err;
  365. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/')
  366. resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
  367. return OK;
  368. }
  369. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
  370. Error err = _setup(p_path, p_main_pack, p_upwards);
  371. if (err == OK) {
  372. String custom_settings = GLOBAL_DEF("application/config/project_settings_override", "");
  373. if (custom_settings != "") {
  374. _load_settings_text(custom_settings);
  375. }
  376. }
  377. return err;
  378. }
  379. bool ProjectSettings::has_setting(String p_var) const {
  380. _THREAD_SAFE_METHOD_
  381. return props.has(p_var);
  382. }
  383. void ProjectSettings::set_registering_order(bool p_enable) {
  384. registering_order = p_enable;
  385. }
  386. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  387. Error err;
  388. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  389. if (err != OK) {
  390. return err;
  391. }
  392. uint8_t hdr[4];
  393. f->get_buffer(hdr, 4);
  394. if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
  395. memdelete(f);
  396. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  397. }
  398. uint32_t count = f->get_32();
  399. for (uint32_t i = 0; i < count; i++) {
  400. uint32_t slen = f->get_32();
  401. CharString cs;
  402. cs.resize(slen + 1);
  403. cs[slen] = 0;
  404. f->get_buffer((uint8_t *)cs.ptr(), slen);
  405. String key;
  406. key.parse_utf8(cs.ptr());
  407. uint32_t vlen = f->get_32();
  408. Vector<uint8_t> d;
  409. d.resize(vlen);
  410. f->get_buffer(d.ptrw(), vlen);
  411. Variant value;
  412. err = decode_variant(value, d.ptr(), d.size(), NULL, true);
  413. ERR_CONTINUE_MSG(err != OK, "Error decoding property: " + key + ".");
  414. set(key, value);
  415. }
  416. f->close();
  417. memdelete(f);
  418. return OK;
  419. }
  420. Error ProjectSettings::_load_settings_text(const String &p_path) {
  421. Error err;
  422. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  423. if (!f) {
  424. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  425. // This needs to be streamlined if we want decent error reporting
  426. return ERR_FILE_NOT_FOUND;
  427. }
  428. VariantParser::StreamFile stream;
  429. stream.f = f;
  430. String assign;
  431. Variant value;
  432. VariantParser::Tag next_tag;
  433. int lines = 0;
  434. String error_text;
  435. String section;
  436. int config_version = 0;
  437. while (true) {
  438. assign = Variant();
  439. next_tag.fields.clear();
  440. next_tag.name = String();
  441. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
  442. if (err == ERR_FILE_EOF) {
  443. memdelete(f);
  444. // If we're loading a project.godot from source code, we can operate some
  445. // ProjectSettings conversions if need be.
  446. _convert_to_last_version(config_version);
  447. return OK;
  448. } else if (err != OK) {
  449. ERR_PRINTS("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
  450. memdelete(f);
  451. return err;
  452. }
  453. if (assign != String()) {
  454. if (section == String() && assign == "config_version") {
  455. config_version = value;
  456. if (config_version > CONFIG_VERSION) {
  457. memdelete(f);
  458. 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));
  459. }
  460. } else {
  461. if (section == String()) {
  462. set(assign, value);
  463. } else {
  464. set(section + "/" + assign, value);
  465. }
  466. }
  467. } else if (next_tag.name != String()) {
  468. section = next_tag.name;
  469. }
  470. }
  471. }
  472. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  473. // Attempt first to load the text-based project.godot file
  474. Error err_text = _load_settings_text(p_text_path);
  475. if (err_text == OK) {
  476. return OK;
  477. } else if (err_text != ERR_FILE_NOT_FOUND) {
  478. // If the text-based file exists but can't be loaded, we want to know it
  479. ERR_PRINTS("Couldn't load file '" + p_text_path + "', error code " + itos(err_text) + ".");
  480. return err_text;
  481. }
  482. // Fallback to binary project.binary file if text-based was not found
  483. Error err_bin = _load_settings_binary(p_bin_path);
  484. return err_bin;
  485. }
  486. int ProjectSettings::get_order(const String &p_name) const {
  487. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + ".");
  488. return props[p_name].order;
  489. }
  490. void ProjectSettings::set_order(const String &p_name, int p_order) {
  491. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  492. props[p_name].order = p_order;
  493. }
  494. void ProjectSettings::set_builtin_order(const String &p_name) {
  495. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  496. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  497. props[p_name].order = last_builtin_order++;
  498. }
  499. }
  500. void ProjectSettings::clear(const String &p_name) {
  501. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  502. props.erase(p_name);
  503. }
  504. Error ProjectSettings::save() {
  505. return save_custom(get_resource_path().plus_file("project.godot"));
  506. }
  507. Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom, const String &p_custom_features) {
  508. Error err;
  509. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  510. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
  511. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  512. file->store_buffer(hdr, 4);
  513. int count = 0;
  514. for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
  515. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  516. count++;
  517. }
  518. }
  519. if (p_custom_features != String()) {
  520. file->store_32(count + 1);
  521. //store how many properties are saved, add one for custom featuers, which must always go first
  522. String key = CoreStringNames::get_singleton()->_custom_features;
  523. file->store_32(key.length());
  524. file->store_string(key);
  525. int len;
  526. err = encode_variant(p_custom_features, NULL, len, false);
  527. if (err != OK) {
  528. memdelete(file);
  529. ERR_FAIL_V(err);
  530. }
  531. Vector<uint8_t> buff;
  532. buff.resize(len);
  533. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  534. if (err != OK) {
  535. memdelete(file);
  536. ERR_FAIL_V(err);
  537. }
  538. file->store_32(len);
  539. file->store_buffer(buff.ptr(), buff.size());
  540. } else {
  541. file->store_32(count); //store how many properties are saved
  542. }
  543. for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
  544. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  545. String key = F->get();
  546. if (E->key() != "")
  547. key = E->key() + "/" + key;
  548. Variant value;
  549. if (p_custom.has(key))
  550. value = p_custom[key];
  551. else
  552. value = get(key);
  553. file->store_32(key.length());
  554. file->store_string(key);
  555. int len;
  556. err = encode_variant(value, NULL, 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. Vector<uint8_t> buff;
  561. buff.resize(len);
  562. err = encode_variant(value, buff.ptrw(), len, true);
  563. if (err != OK)
  564. memdelete(file);
  565. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  566. file->store_32(len);
  567. file->store_buffer(buff.ptr(), buff.size());
  568. }
  569. }
  570. file->close();
  571. memdelete(file);
  572. return OK;
  573. }
  574. Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom, const String &p_custom_features) {
  575. Error err;
  576. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  577. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
  578. file->store_line("; Engine configuration file.");
  579. file->store_line("; It's best edited using the editor UI and not directly,");
  580. file->store_line("; since the parameters that go here are not all obvious.");
  581. file->store_line(";");
  582. file->store_line("; Format:");
  583. file->store_line("; [section] ; section goes between []");
  584. file->store_line("; param=value ; assign values to parameters");
  585. file->store_line("");
  586. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  587. if (p_custom_features != String())
  588. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  589. file->store_string("\n");
  590. for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
  591. if (E != props.front())
  592. file->store_string("\n");
  593. if (E->key() != "")
  594. file->store_string("[" + E->key() + "]\n\n");
  595. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  596. String key = F->get();
  597. if (E->key() != "")
  598. key = E->key() + "/" + key;
  599. Variant value;
  600. if (p_custom.has(key))
  601. value = p_custom[key];
  602. else
  603. value = get(key);
  604. String vstr;
  605. VariantWriter::write_to_string(value, vstr);
  606. file->store_string(F->get().property_name_encode() + "=" + vstr + "\n");
  607. }
  608. }
  609. file->close();
  610. memdelete(file);
  611. return OK;
  612. }
  613. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  614. return save_custom(p_file);
  615. };
  616. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  617. ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  618. Set<_VCSort> vclist;
  619. if (p_merge_with_current) {
  620. for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
  621. const VariantContainer *v = &G->get();
  622. if (v->hide_from_editor)
  623. continue;
  624. if (p_custom.has(G->key()))
  625. continue;
  626. _VCSort vc;
  627. vc.name = G->key(); //*k;
  628. vc.order = v->order;
  629. vc.type = v->variant.get_type();
  630. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  631. if (v->variant == v->initial)
  632. continue;
  633. vclist.insert(vc);
  634. }
  635. }
  636. for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
  637. // Lookup global prop to store in the same order
  638. Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
  639. _VCSort vc;
  640. vc.name = E->key();
  641. vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
  642. vc.type = E->get().get_type();
  643. vc.flags = PROPERTY_USAGE_STORAGE;
  644. vclist.insert(vc);
  645. }
  646. Map<String, List<String> > props;
  647. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  648. String category = E->get().name;
  649. String name = E->get().name;
  650. int div = category.find("/");
  651. if (div < 0)
  652. category = "";
  653. else {
  654. category = category.substr(0, div);
  655. name = name.substr(div + 1, name.size());
  656. }
  657. props[category].push_back(name);
  658. }
  659. String custom_features;
  660. for (int i = 0; i < p_custom_features.size(); i++) {
  661. if (i > 0)
  662. custom_features += ",";
  663. String f = p_custom_features[i].strip_edges().replace("\"", "");
  664. custom_features += f;
  665. }
  666. if (p_path.ends_with(".godot"))
  667. return _save_settings_text(p_path, props, p_custom, custom_features);
  668. else if (p_path.ends_with(".binary"))
  669. return _save_settings_binary(p_path, props, p_custom, custom_features);
  670. else {
  671. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
  672. }
  673. }
  674. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed) {
  675. Variant ret;
  676. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  677. ProjectSettings::get_singleton()->set(p_var, p_default);
  678. }
  679. ret = ProjectSettings::get_singleton()->get(p_var);
  680. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  681. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  682. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  683. return ret;
  684. }
  685. Vector<String> ProjectSettings::get_optimizer_presets() const {
  686. List<PropertyInfo> pi;
  687. ProjectSettings::get_singleton()->get_property_list(&pi);
  688. Vector<String> names;
  689. for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
  690. if (!E->get().name.begins_with("optimizer_presets/"))
  691. continue;
  692. names.push_back(E->get().name.get_slicec('/', 1));
  693. }
  694. names.sort();
  695. return names;
  696. }
  697. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  698. ERR_FAIL_COND(!p_info.has("name"));
  699. ERR_FAIL_COND(!p_info.has("type"));
  700. PropertyInfo pinfo;
  701. pinfo.name = p_info["name"];
  702. ERR_FAIL_COND(!props.has(pinfo.name));
  703. pinfo.type = Variant::Type(p_info["type"].operator int());
  704. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  705. if (p_info.has("hint"))
  706. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  707. if (p_info.has("hint_string"))
  708. pinfo.hint_string = p_info["hint_string"];
  709. set_custom_property_info(pinfo.name, pinfo);
  710. }
  711. void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
  712. ERR_FAIL_COND(!props.has(p_prop));
  713. custom_prop_info[p_prop] = p_info;
  714. custom_prop_info[p_prop].name = p_prop;
  715. }
  716. const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  717. return custom_prop_info;
  718. }
  719. void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
  720. disable_feature_overrides = p_disable;
  721. }
  722. bool ProjectSettings::is_using_datapack() const {
  723. return using_datapack;
  724. }
  725. bool ProjectSettings::property_can_revert(const String &p_name) {
  726. if (!props.has(p_name))
  727. return false;
  728. return props[p_name].initial != props[p_name].variant;
  729. }
  730. Variant ProjectSettings::property_get_revert(const String &p_name) {
  731. if (!props.has(p_name))
  732. return Variant();
  733. return props[p_name].initial;
  734. }
  735. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  736. set(p_setting, p_value);
  737. }
  738. Variant ProjectSettings::get_setting(const String &p_setting) const {
  739. return get(p_setting);
  740. }
  741. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  742. return custom_features.has(p_feature);
  743. }
  744. void ProjectSettings::_bind_methods() {
  745. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  746. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  747. ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
  748. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  749. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  750. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  751. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  752. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  753. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  754. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  755. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  756. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files"), &ProjectSettings::_load_resource_pack, DEFVAL(true));
  757. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert);
  758. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert);
  759. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  760. }
  761. ProjectSettings::ProjectSettings() {
  762. singleton = this;
  763. last_order = NO_BUILTIN_ORDER_BASE;
  764. last_builtin_order = 0;
  765. disable_feature_overrides = false;
  766. registering_order = true;
  767. Array events;
  768. Dictionary action;
  769. Ref<InputEventKey> key;
  770. Ref<InputEventJoypadButton> joyb;
  771. GLOBAL_DEF("application/config/name", "");
  772. GLOBAL_DEF("application/config/description", "");
  773. custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
  774. GLOBAL_DEF("application/run/main_scene", "");
  775. custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
  776. GLOBAL_DEF("application/run/disable_stdout", false);
  777. GLOBAL_DEF("application/run/disable_stderr", false);
  778. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  779. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  780. GLOBAL_DEF("application/config/project_settings_override", "");
  781. GLOBAL_DEF("audio/default_bus_layout", "res://default_bus_layout.tres");
  782. custom_prop_info["audio/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
  783. PoolStringArray extensions = PoolStringArray();
  784. extensions.push_back("gd");
  785. if (Engine::get_singleton()->has_singleton("GodotSharp"))
  786. extensions.push_back("cs");
  787. extensions.push_back("shader");
  788. GLOBAL_DEF("editor/search_in_file_extensions", extensions);
  789. custom_prop_info["editor/search_in_file_extensions"] = PropertyInfo(Variant::POOL_STRING_ARRAY, "editor/search_in_file_extensions");
  790. GLOBAL_DEF("editor/script_templates_search_path", "res://script_templates");
  791. custom_prop_info["editor/script_templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script_templates_search_path", PROPERTY_HINT_DIR);
  792. action = Dictionary();
  793. action["deadzone"] = Variant(0.5f);
  794. events = Array();
  795. key.instance();
  796. key->set_scancode(KEY_ENTER);
  797. events.push_back(key);
  798. key.instance();
  799. key->set_scancode(KEY_KP_ENTER);
  800. events.push_back(key);
  801. key.instance();
  802. key->set_scancode(KEY_SPACE);
  803. events.push_back(key);
  804. joyb.instance();
  805. joyb->set_button_index(JOY_BUTTON_0);
  806. events.push_back(joyb);
  807. action["events"] = events;
  808. GLOBAL_DEF("input/ui_accept", action);
  809. input_presets.push_back("input/ui_accept");
  810. action = Dictionary();
  811. action["deadzone"] = Variant(0.5f);
  812. events = Array();
  813. key.instance();
  814. key->set_scancode(KEY_SPACE);
  815. events.push_back(key);
  816. joyb.instance();
  817. joyb->set_button_index(JOY_BUTTON_3);
  818. events.push_back(joyb);
  819. action["events"] = events;
  820. GLOBAL_DEF("input/ui_select", action);
  821. input_presets.push_back("input/ui_select");
  822. action = Dictionary();
  823. action["deadzone"] = Variant(0.5f);
  824. events = Array();
  825. key.instance();
  826. key->set_scancode(KEY_ESCAPE);
  827. events.push_back(key);
  828. joyb.instance();
  829. joyb->set_button_index(JOY_BUTTON_1);
  830. events.push_back(joyb);
  831. action["events"] = events;
  832. GLOBAL_DEF("input/ui_cancel", action);
  833. input_presets.push_back("input/ui_cancel");
  834. action = Dictionary();
  835. action["deadzone"] = Variant(0.5f);
  836. events = Array();
  837. key.instance();
  838. key->set_scancode(KEY_TAB);
  839. events.push_back(key);
  840. action["events"] = events;
  841. GLOBAL_DEF("input/ui_focus_next", action);
  842. input_presets.push_back("input/ui_focus_next");
  843. action = Dictionary();
  844. action["deadzone"] = Variant(0.5f);
  845. events = Array();
  846. key.instance();
  847. key->set_scancode(KEY_TAB);
  848. key->set_shift(true);
  849. events.push_back(key);
  850. action["events"] = events;
  851. GLOBAL_DEF("input/ui_focus_prev", action);
  852. input_presets.push_back("input/ui_focus_prev");
  853. action = Dictionary();
  854. action["deadzone"] = Variant(0.5f);
  855. events = Array();
  856. key.instance();
  857. key->set_scancode(KEY_LEFT);
  858. events.push_back(key);
  859. joyb.instance();
  860. joyb->set_button_index(JOY_DPAD_LEFT);
  861. events.push_back(joyb);
  862. action["events"] = events;
  863. GLOBAL_DEF("input/ui_left", action);
  864. input_presets.push_back("input/ui_left");
  865. action = Dictionary();
  866. action["deadzone"] = Variant(0.5f);
  867. events = Array();
  868. key.instance();
  869. key->set_scancode(KEY_RIGHT);
  870. events.push_back(key);
  871. joyb.instance();
  872. joyb->set_button_index(JOY_DPAD_RIGHT);
  873. events.push_back(joyb);
  874. action["events"] = events;
  875. GLOBAL_DEF("input/ui_right", action);
  876. input_presets.push_back("input/ui_right");
  877. action = Dictionary();
  878. action["deadzone"] = Variant(0.5f);
  879. events = Array();
  880. key.instance();
  881. key->set_scancode(KEY_UP);
  882. events.push_back(key);
  883. joyb.instance();
  884. joyb->set_button_index(JOY_DPAD_UP);
  885. events.push_back(joyb);
  886. action["events"] = events;
  887. GLOBAL_DEF("input/ui_up", action);
  888. input_presets.push_back("input/ui_up");
  889. action = Dictionary();
  890. action["deadzone"] = Variant(0.5f);
  891. events = Array();
  892. key.instance();
  893. key->set_scancode(KEY_DOWN);
  894. events.push_back(key);
  895. joyb.instance();
  896. joyb->set_button_index(JOY_DPAD_DOWN);
  897. events.push_back(joyb);
  898. action["events"] = events;
  899. GLOBAL_DEF("input/ui_down", action);
  900. input_presets.push_back("input/ui_down");
  901. action = Dictionary();
  902. action["deadzone"] = Variant(0.5f);
  903. events = Array();
  904. key.instance();
  905. key->set_scancode(KEY_PAGEUP);
  906. events.push_back(key);
  907. action["events"] = events;
  908. GLOBAL_DEF("input/ui_page_up", action);
  909. input_presets.push_back("input/ui_page_up");
  910. action = Dictionary();
  911. action["deadzone"] = Variant(0.5f);
  912. events = Array();
  913. key.instance();
  914. key->set_scancode(KEY_PAGEDOWN);
  915. events.push_back(key);
  916. action["events"] = events;
  917. GLOBAL_DEF("input/ui_page_down", action);
  918. input_presets.push_back("input/ui_page_down");
  919. action = Dictionary();
  920. action["deadzone"] = Variant(0.5f);
  921. events = Array();
  922. key.instance();
  923. key->set_scancode(KEY_HOME);
  924. events.push_back(key);
  925. action["events"] = events;
  926. GLOBAL_DEF("input/ui_home", action);
  927. input_presets.push_back("input/ui_home");
  928. action = Dictionary();
  929. action["deadzone"] = Variant(0.5f);
  930. events = Array();
  931. key.instance();
  932. key->set_scancode(KEY_END);
  933. events.push_back(key);
  934. action["events"] = events;
  935. GLOBAL_DEF("input/ui_end", action);
  936. input_presets.push_back("input/ui_end");
  937. 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");
  938. custom_prop_info["rendering/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
  939. custom_prop_info["physics/2d/thread_model"] = PropertyInfo(Variant::INT, "physics/2d/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
  940. 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");
  941. GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
  942. custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
  943. //assigning here, because using GLOBAL_GET on every block for compressing can be slow
  944. Compression::zstd_long_distance_matching = GLOBAL_DEF("compression/formats/zstd/long_distance_matching", false);
  945. custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
  946. Compression::zstd_level = GLOBAL_DEF("compression/formats/zstd/compression_level", 3);
  947. custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
  948. Compression::zstd_window_log_size = GLOBAL_DEF("compression/formats/zstd/window_log_size", 27);
  949. custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
  950. Compression::zlib_level = GLOBAL_DEF("compression/formats/zlib/compression_level", Z_DEFAULT_COMPRESSION);
  951. custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  952. Compression::gzip_level = GLOBAL_DEF("compression/formats/gzip/compression_level", Z_DEFAULT_COMPRESSION);
  953. custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  954. // Would ideally be defined in an Android-specific file, but then it doesn't appear in the docs
  955. GLOBAL_DEF("android/modules", "");
  956. using_datapack = false;
  957. }
  958. ProjectSettings::~ProjectSettings() {
  959. singleton = NULL;
  960. }