project_settings.cpp 43 KB

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