project_settings.cpp 39 KB

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