project_settings.cpp 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  1. /**************************************************************************/
  2. /* project_settings.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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/core_bind.h" // For Compression enum.
  32. #include "core/input/input_map.h"
  33. #include "core/io/config_file.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_pack.h"
  37. #include "core/io/marshalls.h"
  38. #include "core/io/resource_uid.h"
  39. #include "core/object/script_language.h"
  40. #include "core/templates/rb_set.h"
  41. #include "core/variant/typed_array.h"
  42. #include "core/variant/variant_parser.h"
  43. #include "core/version.h"
  44. #ifdef TOOLS_ENABLED
  45. #include "modules/modules_enabled.gen.h" // For mono.
  46. #endif // TOOLS_ENABLED
  47. const String ProjectSettings::PROJECT_DATA_DIR_NAME_SUFFIX = "godot";
  48. ProjectSettings *ProjectSettings::singleton = nullptr;
  49. ProjectSettings *ProjectSettings::get_singleton() {
  50. return singleton;
  51. }
  52. String ProjectSettings::get_project_data_dir_name() const {
  53. return project_data_dir_name;
  54. }
  55. String ProjectSettings::get_project_data_path() const {
  56. return "res://" + get_project_data_dir_name();
  57. }
  58. String ProjectSettings::get_resource_path() const {
  59. return resource_path;
  60. }
  61. String ProjectSettings::get_imported_files_path() const {
  62. return get_project_data_path().path_join("imported");
  63. }
  64. #ifdef TOOLS_ENABLED
  65. // Returns the features that a project must have when opened with this build of Godot.
  66. // This is used by the project manager to provide the initial_settings for config/features.
  67. const PackedStringArray ProjectSettings::get_required_features() {
  68. PackedStringArray features;
  69. features.append(GODOT_VERSION_BRANCH);
  70. #ifdef REAL_T_IS_DOUBLE
  71. features.append("Double Precision");
  72. #endif
  73. return features;
  74. }
  75. // Returns the features supported by this build of Godot. Includes all required features.
  76. const PackedStringArray ProjectSettings::_get_supported_features() {
  77. PackedStringArray features = get_required_features();
  78. #ifdef MODULE_MONO_ENABLED
  79. features.append("C#");
  80. #endif
  81. // Allow pinning to a specific patch number or build type by marking
  82. // them as supported. They're only used if the user adds them manually.
  83. features.append(GODOT_VERSION_BRANCH "." _MKSTR(GODOT_VERSION_PATCH));
  84. features.append(GODOT_VERSION_FULL_CONFIG);
  85. features.append(GODOT_VERSION_FULL_BUILD);
  86. #ifdef RD_ENABLED
  87. features.append("Forward Plus");
  88. features.append("Mobile");
  89. #endif
  90. #ifdef GLES3_ENABLED
  91. features.append("GL Compatibility");
  92. #endif
  93. return features;
  94. }
  95. // Returns the features that this project needs but this build of Godot lacks.
  96. const PackedStringArray ProjectSettings::get_unsupported_features(const PackedStringArray &p_project_features) {
  97. PackedStringArray unsupported_features;
  98. PackedStringArray supported_features = singleton->_get_supported_features();
  99. for (int i = 0; i < p_project_features.size(); i++) {
  100. if (!supported_features.has(p_project_features[i])) {
  101. // Temporary compatibility code to ease upgrade to 4.0 beta 2+.
  102. if (p_project_features[i].begins_with("Vulkan")) {
  103. continue;
  104. }
  105. unsupported_features.append(p_project_features[i]);
  106. }
  107. }
  108. unsupported_features.sort();
  109. return unsupported_features;
  110. }
  111. // Returns the features that both this project has and this build of Godot has, ensuring required features exist.
  112. const PackedStringArray ProjectSettings::_trim_to_supported_features(const PackedStringArray &p_project_features) {
  113. // Remove unsupported features if present.
  114. PackedStringArray features = PackedStringArray(p_project_features);
  115. PackedStringArray supported_features = _get_supported_features();
  116. for (int i = p_project_features.size() - 1; i > -1; i--) {
  117. if (!supported_features.has(p_project_features[i])) {
  118. features.remove_at(i);
  119. }
  120. }
  121. // Add required features if not present.
  122. PackedStringArray required_features = get_required_features();
  123. for (int i = 0; i < required_features.size(); i++) {
  124. if (!features.has(required_features[i])) {
  125. features.append(required_features[i]);
  126. }
  127. }
  128. features.sort();
  129. return features;
  130. }
  131. #endif // TOOLS_ENABLED
  132. String ProjectSettings::localize_path(const String &p_path) const {
  133. String path = p_path.simplify_path();
  134. if (resource_path.is_empty() || (path.is_absolute_path() && !path.begins_with(resource_path))) {
  135. return path;
  136. }
  137. // Check if we have a special path (like res://) or a protocol identifier.
  138. int p = path.find("://");
  139. bool found = false;
  140. if (p > 0) {
  141. found = true;
  142. for (int i = 0; i < p; i++) {
  143. if (!is_ascii_alphanumeric_char(path[i])) {
  144. found = false;
  145. break;
  146. }
  147. }
  148. }
  149. if (found) {
  150. return path;
  151. }
  152. Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  153. if (dir->change_dir(path) == OK) {
  154. String cwd = dir->get_current_dir();
  155. cwd = cwd.replace("\\", "/");
  156. // Ensure that we end with a '/'.
  157. // This is important to ensure that we do not wrongly localize the resource path
  158. // in an absolute path that just happens to contain this string but points to a
  159. // different folder (e.g. "/my/project" as resource_path would be contained in
  160. // "/my/project_data", even though the latter is not part of res://.
  161. // `path_join("")` is an easy way to ensure we have a trailing '/'.
  162. const String res_path = resource_path.path_join("");
  163. // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
  164. // so we must make sure we have it as well in order to compare with 'res_path'.
  165. cwd = cwd.path_join("");
  166. if (!cwd.begins_with(res_path)) {
  167. return path;
  168. }
  169. return cwd.replace_first(res_path, "res://");
  170. } else {
  171. int sep = path.rfind_char('/');
  172. if (sep == -1) {
  173. return "res://" + path;
  174. }
  175. String parent = path.substr(0, sep);
  176. String plocal = localize_path(parent);
  177. if (plocal.is_empty()) {
  178. return "";
  179. }
  180. // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
  181. if (plocal[plocal.length() - 1] == '/') {
  182. sep += 1;
  183. }
  184. return plocal + path.substr(sep);
  185. }
  186. }
  187. void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
  188. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  189. // Duplicate so that if value is array or dictionary, changing the setting will not change the stored initial value.
  190. props[p_name].initial = p_value.duplicate();
  191. }
  192. void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
  193. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  194. props[p_name].restart_if_changed = p_restart;
  195. }
  196. void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) {
  197. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  198. props[p_name].basic = p_basic;
  199. }
  200. void ProjectSettings::set_as_internal(const String &p_name, bool p_internal) {
  201. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  202. props[p_name].internal = p_internal;
  203. }
  204. void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) {
  205. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  206. #ifdef DEBUG_METHODS_ENABLED
  207. props[p_name].ignore_value_in_docs = p_ignore;
  208. #endif
  209. }
  210. bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
  211. ERR_FAIL_COND_V_MSG(!props.has(p_name), false, vformat("Request for nonexistent project setting: '%s'.", p_name));
  212. #ifdef DEBUG_METHODS_ENABLED
  213. return props[p_name].ignore_value_in_docs;
  214. #else
  215. return false;
  216. #endif
  217. }
  218. void ProjectSettings::add_hidden_prefix(const String &p_prefix) {
  219. ERR_FAIL_COND_MSG(hidden_prefixes.has(p_prefix), vformat("Hidden prefix '%s' already exists.", p_prefix));
  220. hidden_prefixes.push_back(p_prefix);
  221. }
  222. String ProjectSettings::globalize_path(const String &p_path) const {
  223. if (p_path.begins_with("res://")) {
  224. if (!resource_path.is_empty()) {
  225. return p_path.replace("res:/", resource_path);
  226. }
  227. return p_path.replace("res://", "");
  228. } else if (p_path.begins_with("uid://")) {
  229. const String path = ResourceUID::uid_to_path(p_path);
  230. if (!resource_path.is_empty()) {
  231. return path.replace("res:/", resource_path);
  232. }
  233. return path.replace("res://", "");
  234. } else if (p_path.begins_with("user://")) {
  235. String data_dir = OS::get_singleton()->get_user_data_dir();
  236. if (!data_dir.is_empty()) {
  237. return p_path.replace("user:/", data_dir);
  238. }
  239. return p_path.replace("user://", "");
  240. }
  241. return p_path;
  242. }
  243. bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
  244. _THREAD_SAFE_METHOD_
  245. if (p_value.get_type() == Variant::NIL) {
  246. props.erase(p_name);
  247. if (p_name.operator String().begins_with("autoload/")) {
  248. String node_name = p_name.operator String().split("/")[1];
  249. if (autoloads.has(node_name)) {
  250. remove_autoload(node_name);
  251. }
  252. } else if (p_name.operator String().begins_with("global_group/")) {
  253. String group_name = p_name.operator String().get_slicec('/', 1);
  254. if (global_groups.has(group_name)) {
  255. remove_global_group(group_name);
  256. }
  257. }
  258. } else {
  259. if (p_name == CoreStringName(_custom_features)) {
  260. Vector<String> custom_feature_array = String(p_value).split(",");
  261. for (int i = 0; i < custom_feature_array.size(); i++) {
  262. custom_features.insert(custom_feature_array[i]);
  263. }
  264. _queue_changed();
  265. return true;
  266. }
  267. { // Feature overrides.
  268. int dot = p_name.operator String().find_char('.');
  269. if (dot != -1) {
  270. Vector<String> s = p_name.operator String().split(".");
  271. for (int i = 1; i < s.size(); i++) {
  272. String feature = s[i].strip_edges();
  273. Pair<StringName, StringName> feature_override(feature, p_name);
  274. if (!feature_overrides.has(s[0])) {
  275. feature_overrides[s[0]] = LocalVector<Pair<StringName, StringName>>();
  276. }
  277. feature_overrides[s[0]].push_back(feature_override);
  278. }
  279. }
  280. }
  281. if (props.has(p_name)) {
  282. props[p_name].variant = p_value;
  283. } else {
  284. props[p_name] = VariantContainer(p_value, last_order++);
  285. }
  286. if (p_name.operator String().begins_with("autoload/")) {
  287. String node_name = p_name.operator String().split("/")[1];
  288. AutoloadInfo autoload;
  289. autoload.name = node_name;
  290. String path = p_value;
  291. if (path.begins_with("*")) {
  292. autoload.is_singleton = true;
  293. autoload.path = path.substr(1).simplify_path();
  294. } else {
  295. autoload.path = path.simplify_path();
  296. }
  297. add_autoload(autoload);
  298. } else if (p_name.operator String().begins_with("global_group/")) {
  299. String group_name = p_name.operator String().get_slicec('/', 1);
  300. add_global_group(group_name, p_value);
  301. }
  302. }
  303. _queue_changed();
  304. return true;
  305. }
  306. bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
  307. _THREAD_SAFE_METHOD_
  308. if (!props.has(p_name)) {
  309. return false;
  310. }
  311. r_ret = props[p_name].variant;
  312. return true;
  313. }
  314. Variant ProjectSettings::get_setting_with_override(const StringName &p_name) const {
  315. _THREAD_SAFE_METHOD_
  316. StringName name = p_name;
  317. if (feature_overrides.has(name)) {
  318. const LocalVector<Pair<StringName, StringName>> &overrides = feature_overrides[name];
  319. for (uint32_t i = 0; i < overrides.size(); i++) {
  320. if (OS::get_singleton()->has_feature(overrides[i].first)) { // Custom features are checked in OS.has_feature() already. No need to check twice.
  321. if (props.has(overrides[i].second)) {
  322. name = overrides[i].second;
  323. break;
  324. }
  325. }
  326. }
  327. }
  328. if (!props.has(name)) {
  329. WARN_PRINT(vformat("Property not found: '%s'.", String(name)));
  330. return Variant();
  331. }
  332. return props[name].variant;
  333. }
  334. struct _VCSort {
  335. String name;
  336. Variant::Type type = Variant::VARIANT_MAX;
  337. int order = 0;
  338. uint32_t flags = 0;
  339. bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
  340. };
  341. void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  342. _THREAD_SAFE_METHOD_
  343. RBSet<_VCSort> vclist;
  344. for (const KeyValue<StringName, VariantContainer> &E : props) {
  345. const VariantContainer *v = &E.value;
  346. if (v->hide_from_editor) {
  347. continue;
  348. }
  349. _VCSort vc;
  350. vc.name = E.key;
  351. vc.order = v->order;
  352. vc.type = v->variant.get_type();
  353. bool internal = v->internal;
  354. if (!internal) {
  355. for (const String &F : hidden_prefixes) {
  356. if (vc.name.begins_with(F)) {
  357. internal = true;
  358. break;
  359. }
  360. }
  361. }
  362. if (internal) {
  363. vc.flags = PROPERTY_USAGE_STORAGE;
  364. } else {
  365. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  366. }
  367. if (v->internal) {
  368. vc.flags |= PROPERTY_USAGE_INTERNAL;
  369. }
  370. if (v->basic) {
  371. vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  372. }
  373. if (v->restart_if_changed) {
  374. vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  375. }
  376. vclist.insert(vc);
  377. }
  378. for (const _VCSort &E : vclist) {
  379. String prop_info_name = E.name;
  380. int dot = prop_info_name.find_char('.');
  381. if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
  382. prop_info_name = prop_info_name.substr(0, dot);
  383. }
  384. if (custom_prop_info.has(prop_info_name)) {
  385. PropertyInfo pi = custom_prop_info[prop_info_name];
  386. pi.name = E.name;
  387. pi.usage = E.flags;
  388. p_list->push_back(pi);
  389. } else {
  390. p_list->push_back(PropertyInfo(E.type, E.name, PROPERTY_HINT_NONE, "", E.flags));
  391. }
  392. }
  393. }
  394. void ProjectSettings::_queue_changed() {
  395. if (is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) {
  396. return;
  397. }
  398. is_changed = true;
  399. callable_mp(this, &ProjectSettings::_emit_changed).call_deferred();
  400. }
  401. void ProjectSettings::_emit_changed() {
  402. if (!is_changed) {
  403. return;
  404. }
  405. is_changed = false;
  406. emit_signal("settings_changed");
  407. }
  408. bool ProjectSettings::load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
  409. return ProjectSettings::_load_resource_pack(p_pack, p_replace_files, p_offset, false);
  410. }
  411. bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset, bool p_main_pack) {
  412. if (PackedData::get_singleton()->is_disabled()) {
  413. return false;
  414. }
  415. if (p_pack == "res://") {
  416. // Loading the resource directory as a pack source is reserved for internal use only.
  417. return false;
  418. }
  419. if (!p_main_pack && !using_datapack && !OS::get_singleton()->get_resource_dir().is_empty()) {
  420. // Add the project's resource file system to PackedData so directory access keeps working when
  421. // the game is running without a main pack, like in the editor or on Android.
  422. PackedData::get_singleton()->add_pack_source(memnew(PackedSourceDirectory));
  423. PackedData::get_singleton()->add_pack("res://", false, 0);
  424. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  425. using_datapack = true;
  426. }
  427. bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK;
  428. if (!ok) {
  429. return false;
  430. }
  431. if (project_loaded) {
  432. // This pack may have declared new global classes (make sure they are picked up).
  433. refresh_global_class_list();
  434. // This pack may have defined new UIDs, make sure they are cached.
  435. ResourceUID::get_singleton()->load_from_cache(false);
  436. }
  437. // If the data pack was found, all directory access will be from here.
  438. if (!using_datapack) {
  439. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  440. using_datapack = true;
  441. }
  442. return true;
  443. }
  444. void ProjectSettings::_convert_to_last_version(int p_from_version) {
  445. #ifndef DISABLE_DEPRECATED
  446. if (p_from_version <= 3) {
  447. // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
  448. for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
  449. Variant value = E.value.variant;
  450. if (String(E.key).begins_with("input/") && value.get_type() == Variant::ARRAY) {
  451. Array array = value;
  452. Dictionary action;
  453. action["deadzone"] = Variant(0.5f);
  454. action["events"] = array;
  455. E.value.variant = action;
  456. }
  457. }
  458. }
  459. #endif // DISABLE_DEPRECATED
  460. }
  461. /*
  462. * This method is responsible for loading a project.godot file and/or data file
  463. * using the following merit order:
  464. * - If using NetworkClient, try to lookup project file or fail.
  465. * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
  466. * - Search for project PCKs automatically. For each step we try loading a potential
  467. * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds,
  468. * we try loading the project settings, and abort if it fails. Steps:
  469. * o Bundled PCK in the executable.
  470. * o [macOS only] PCK with same basename as the binary in the .app resource dir.
  471. * o PCK with same basename as the binary in the binary's directory. We handle both
  472. * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and
  473. * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck').
  474. * o PCK with the same basename as the binary in the current working directory.
  475. * Same as above for the two possible PCK file names.
  476. * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
  477. * If found, load it or fail.
  478. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
  479. * are running from source code.
  480. * If not found and `p_upwards` is true (--upwards passed by the user), look for
  481. * project files in parent folders up to the system root (used to run a game
  482. * from command line while in a subfolder).
  483. * If a project file is found, load it or fail.
  484. * If nothing was found, error out.
  485. */
  486. Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  487. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  488. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  489. // If the OS would rather use a specific location, then it will not be empty.
  490. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  491. if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') {
  492. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  493. }
  494. }
  495. // Attempt with a user-defined main pack first
  496. if (!p_main_pack.is_empty()) {
  497. bool ok = _load_resource_pack(p_main_pack, false, 0, true);
  498. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack));
  499. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  500. if (err == OK && !p_ignore_override) {
  501. // Load override from location of the main pack
  502. // Optional, we don't mind if it fails
  503. _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
  504. }
  505. return err;
  506. }
  507. String exec_path = OS::get_singleton()->get_executable_path();
  508. if (!exec_path.is_empty()) {
  509. // We do several tests sequentially until one succeeds to find a PCK,
  510. // and if so, we attempt loading it at the end.
  511. // Attempt with PCK bundled into executable.
  512. bool found = _load_resource_pack(exec_path, false, 0, true);
  513. // Attempt with exec_name.pck.
  514. // (This is the usual case when distributing a Godot game.)
  515. String exec_dir = exec_path.get_base_dir();
  516. String exec_filename = exec_path.get_file();
  517. String exec_basename = exec_filename.get_basename();
  518. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  519. // or the exec path's basename + '.pck' (Windows).
  520. // We need to test both possibilities as extensions for Linux binaries are optional
  521. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  522. #ifdef MACOS_ENABLED
  523. if (!found) {
  524. // Attempt to load PCK from macOS .app bundle resources.
  525. found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().path_join(exec_filename + ".pck"), false, 0, true);
  526. }
  527. #endif
  528. if (!found) {
  529. // Try to load data pack at the location of the executable.
  530. // As mentioned above, we have two potential names to attempt.
  531. found = _load_resource_pack(exec_dir.path_join(exec_basename + ".pck"), false, 0, true) || _load_resource_pack(exec_dir.path_join(exec_filename + ".pck"), false, 0, true);
  532. }
  533. if (!found) {
  534. // If we couldn't find them next to the executable, we attempt
  535. // the current working directory. Same story, two tests.
  536. found = _load_resource_pack(exec_basename + ".pck", false, 0, true) || _load_resource_pack(exec_filename + ".pck", false, 0, true);
  537. }
  538. // If we opened our package, try and load our project.
  539. if (found) {
  540. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  541. if (err == OK && !p_ignore_override) {
  542. // Load overrides from the PCK and the executable location.
  543. // Optional, we don't mind if either fails.
  544. _load_settings_text("res://override.cfg");
  545. _load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
  546. }
  547. return err;
  548. }
  549. }
  550. // Try to use the filesystem for files, according to OS.
  551. // (Only Android -when reading from pck- and iOS use this.)
  552. if (!OS::get_singleton()->get_resource_dir().is_empty()) {
  553. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  554. if (err == OK && !p_ignore_override) {
  555. // Optional, we don't mind if it fails.
  556. _load_settings_text("res://override.cfg");
  557. }
  558. return err;
  559. }
  560. #ifdef MACOS_ENABLED
  561. // Attempt to load project file from macOS .app bundle resources.
  562. resource_path = OS::get_singleton()->get_bundle_resource_dir();
  563. if (!resource_path.is_empty()) {
  564. if (resource_path[resource_path.length() - 1] == '/') {
  565. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  566. }
  567. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  568. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", resource_path));
  569. d->change_dir(resource_path);
  570. Error err;
  571. err = _load_settings_text_or_binary(resource_path.path_join("project.godot"), resource_path.path_join("project.binary"));
  572. if (err == OK && !p_ignore_override) {
  573. // Optional, we don't mind if it fails.
  574. _load_settings_text(resource_path.path_join("override.cfg"));
  575. return err;
  576. }
  577. }
  578. #endif
  579. // Nothing was found, try to find a project file in provided path (`p_path`)
  580. // or, if requested (`p_upwards`) in parent directories.
  581. Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  582. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_CANT_CREATE, vformat("Cannot create DirAccess for path '%s'.", p_path));
  583. d->change_dir(p_path);
  584. String current_dir = d->get_current_dir();
  585. bool found = false;
  586. Error err;
  587. while (true) {
  588. // Set the resource path early so things can be resolved when loading.
  589. resource_path = current_dir;
  590. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  591. err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary"));
  592. if (err == OK && !p_ignore_override) {
  593. // Optional, we don't mind if it fails.
  594. _load_settings_text(current_dir.path_join("override.cfg"));
  595. found = true;
  596. break;
  597. }
  598. if (p_upwards) {
  599. // Try to load settings ascending through parent directories
  600. d->change_dir("..");
  601. if (d->get_current_dir() == current_dir) {
  602. break; // not doing anything useful
  603. }
  604. current_dir = d->get_current_dir();
  605. } else {
  606. break;
  607. }
  608. }
  609. if (!found) {
  610. return err;
  611. }
  612. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  613. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  614. }
  615. return OK;
  616. }
  617. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) {
  618. Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override);
  619. if (err == OK && !p_ignore_override) {
  620. String custom_settings = GLOBAL_GET("application/config/project_settings_override");
  621. if (!custom_settings.is_empty()) {
  622. _load_settings_text(custom_settings);
  623. }
  624. }
  625. // Updating the default value after the project settings have loaded.
  626. bool use_hidden_directory = GLOBAL_GET("application/config/use_hidden_project_data_directory");
  627. project_data_dir_name = (use_hidden_directory ? "." : "") + PROJECT_DATA_DIR_NAME_SUFFIX;
  628. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  629. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  630. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  631. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  632. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  633. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  634. load_scene_groups_cache();
  635. project_loaded = err == OK;
  636. return err;
  637. }
  638. bool ProjectSettings::has_setting(const String &p_var) const {
  639. _THREAD_SAFE_METHOD_
  640. return props.has(p_var);
  641. }
  642. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  643. Error err;
  644. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  645. if (err != OK) {
  646. return err;
  647. }
  648. uint8_t hdr[4];
  649. f->get_buffer(hdr, 4);
  650. ERR_FAIL_COND_V_MSG((hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G'), ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  651. uint32_t count = f->get_32();
  652. for (uint32_t i = 0; i < count; i++) {
  653. uint32_t slen = f->get_32();
  654. CharString cs;
  655. cs.resize(slen + 1);
  656. cs[slen] = 0;
  657. f->get_buffer((uint8_t *)cs.ptr(), slen);
  658. String key;
  659. key.parse_utf8(cs.ptr(), slen);
  660. uint32_t vlen = f->get_32();
  661. Vector<uint8_t> d;
  662. d.resize(vlen);
  663. f->get_buffer(d.ptrw(), vlen);
  664. Variant value;
  665. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  666. ERR_CONTINUE_MSG(err != OK, vformat("Error decoding property: '%s'.", key));
  667. set(key, value);
  668. }
  669. return OK;
  670. }
  671. Error ProjectSettings::_load_settings_text(const String &p_path) {
  672. Error err;
  673. Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
  674. if (f.is_null()) {
  675. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  676. // This needs to be streamlined if we want decent error reporting
  677. return ERR_FILE_NOT_FOUND;
  678. }
  679. VariantParser::StreamFile stream;
  680. stream.f = f;
  681. String assign;
  682. Variant value;
  683. VariantParser::Tag next_tag;
  684. int lines = 0;
  685. String error_text;
  686. String section;
  687. int config_version = 0;
  688. while (true) {
  689. assign = Variant();
  690. next_tag.fields.clear();
  691. next_tag.name = String();
  692. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  693. if (err == ERR_FILE_EOF) {
  694. // If we're loading a project.godot from source code, we can operate some
  695. // ProjectSettings conversions if need be.
  696. _convert_to_last_version(config_version);
  697. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  698. return OK;
  699. }
  700. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Error parsing '%s' at line %d: %s File might be corrupted.", p_path, lines, error_text));
  701. if (!assign.is_empty()) {
  702. if (section.is_empty() && assign == "config_version") {
  703. config_version = value;
  704. ERR_FAIL_COND_V_MSG(config_version > CONFIG_VERSION, 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));
  705. } else {
  706. if (section.is_empty()) {
  707. set(assign, value);
  708. } else {
  709. set(section + "/" + assign, value);
  710. }
  711. }
  712. } else if (!next_tag.name.is_empty()) {
  713. section = next_tag.name;
  714. }
  715. }
  716. }
  717. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  718. // Attempt first to load the binary project.godot file.
  719. Error err = _load_settings_binary(p_bin_path);
  720. if (err == OK) {
  721. return OK;
  722. } else if (err != ERR_FILE_NOT_FOUND) {
  723. // If the file exists but can't be loaded, we want to know it.
  724. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_bin_path, err));
  725. }
  726. // Fallback to text-based project.godot file if binary was not found.
  727. err = _load_settings_text(p_text_path);
  728. if (err == OK) {
  729. return OK;
  730. } else if (err != ERR_FILE_NOT_FOUND) {
  731. ERR_PRINT(vformat("Couldn't load file '%s', error code %d.", p_text_path, err));
  732. }
  733. return err;
  734. }
  735. Error ProjectSettings::load_custom(const String &p_path) {
  736. if (p_path.ends_with(".binary")) {
  737. return _load_settings_binary(p_path);
  738. }
  739. return _load_settings_text(p_path);
  740. }
  741. int ProjectSettings::get_order(const String &p_name) const {
  742. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, vformat("Request for nonexistent project setting: '%s'.", p_name));
  743. return props[p_name].order;
  744. }
  745. void ProjectSettings::set_order(const String &p_name, int p_order) {
  746. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  747. props[p_name].order = p_order;
  748. }
  749. void ProjectSettings::set_builtin_order(const String &p_name) {
  750. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  751. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  752. props[p_name].order = last_builtin_order++;
  753. }
  754. }
  755. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  756. // Return true because a false negative is worse than a false positive.
  757. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, vformat("Request for nonexistent project setting: '%s'.", p_name));
  758. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  759. }
  760. void ProjectSettings::clear(const String &p_name) {
  761. ERR_FAIL_COND_MSG(!props.has(p_name), vformat("Request for nonexistent project setting: '%s'.", p_name));
  762. props.erase(p_name);
  763. }
  764. Error ProjectSettings::save() {
  765. Error error = save_custom(get_resource_path().path_join("project.godot"));
  766. if (error == OK) {
  767. last_save_time = FileAccess::get_modified_time(get_resource_path().path_join("project.godot"));
  768. }
  769. return error;
  770. }
  771. Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) {
  772. Error err;
  773. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  774. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.binary at '%s'.", p_file));
  775. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  776. file->store_buffer(hdr, 4);
  777. int count = 0;
  778. for (const KeyValue<String, List<String>> &E : p_props) {
  779. count += E.value.size();
  780. }
  781. if (!p_custom_features.is_empty()) {
  782. // Store how many properties are saved, add one for custom features, which must always go first.
  783. file->store_32(uint32_t(count + 1));
  784. String key = CoreStringName(_custom_features);
  785. file->store_pascal_string(key);
  786. int len;
  787. err = encode_variant(p_custom_features, nullptr, len, false);
  788. ERR_FAIL_COND_V(err != OK, err);
  789. Vector<uint8_t> buff;
  790. buff.resize(len);
  791. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  792. ERR_FAIL_COND_V(err != OK, err);
  793. file->store_32(uint32_t(len));
  794. file->store_buffer(buff.ptr(), buff.size());
  795. } else {
  796. // Store how many properties are saved.
  797. file->store_32(uint32_t(count));
  798. }
  799. for (const KeyValue<String, List<String>> &E : p_props) {
  800. for (const String &key : E.value) {
  801. String k = key;
  802. if (!E.key.is_empty()) {
  803. k = E.key + "/" + k;
  804. }
  805. Variant value;
  806. if (p_custom.has(k)) {
  807. value = p_custom[k];
  808. } else {
  809. value = get(k);
  810. }
  811. file->store_pascal_string(k);
  812. int len;
  813. err = encode_variant(value, nullptr, len, true);
  814. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  815. Vector<uint8_t> buff;
  816. buff.resize(len);
  817. err = encode_variant(value, buff.ptrw(), len, true);
  818. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  819. file->store_32(uint32_t(len));
  820. file->store_buffer(buff.ptr(), buff.size());
  821. }
  822. }
  823. return OK;
  824. }
  825. Error ProjectSettings::_save_settings_text(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) {
  826. Error err;
  827. Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  828. ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Couldn't save project.godot - %s.", p_file));
  829. file->store_line("; Engine configuration file.");
  830. file->store_line("; It's best edited using the editor UI and not directly,");
  831. file->store_line("; since the parameters that go here are not all obvious.");
  832. file->store_line(";");
  833. file->store_line("; Format:");
  834. file->store_line("; [section] ; section goes between []");
  835. file->store_line("; param=value ; assign values to parameters");
  836. file->store_line("");
  837. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  838. if (!p_custom_features.is_empty()) {
  839. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  840. }
  841. file->store_string("\n");
  842. for (const KeyValue<String, List<String>> &E : p_props) {
  843. if (E.key != p_props.begin()->key) {
  844. file->store_string("\n");
  845. }
  846. if (!E.key.is_empty()) {
  847. file->store_string("[" + E.key + "]\n\n");
  848. }
  849. for (const String &F : E.value) {
  850. String key = F;
  851. if (!E.key.is_empty()) {
  852. key = E.key + "/" + key;
  853. }
  854. Variant value;
  855. if (p_custom.has(key)) {
  856. value = p_custom[key];
  857. } else {
  858. value = get(key);
  859. }
  860. String vstr;
  861. VariantWriter::write_to_string(value, vstr);
  862. file->store_string(F.property_name_encode() + "=" + vstr + "\n");
  863. }
  864. }
  865. return OK;
  866. }
  867. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  868. return save_custom(p_file);
  869. }
  870. #ifdef TOOLS_ENABLED
  871. bool _csproj_exists(const String &p_root_dir) {
  872. Ref<DirAccess> dir = DirAccess::open(p_root_dir);
  873. ERR_FAIL_COND_V(dir.is_null(), false);
  874. dir->list_dir_begin();
  875. String file_name = dir->_get_next();
  876. while (file_name != "") {
  877. if (!dir->current_is_dir() && file_name.get_extension() == "csproj") {
  878. return true;
  879. }
  880. file_name = dir->_get_next();
  881. }
  882. return false;
  883. }
  884. #endif // TOOLS_ENABLED
  885. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  886. ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  887. #ifdef TOOLS_ENABLED
  888. PackedStringArray project_features = get_setting("application/config/features");
  889. // If there is no feature list currently present, force one to generate.
  890. if (project_features.is_empty()) {
  891. project_features = ProjectSettings::get_required_features();
  892. }
  893. // Check the rendering API.
  894. const String rendering_api = has_setting("rendering/renderer/rendering_method") ? (String)get_setting("rendering/renderer/rendering_method") : String();
  895. if (!rendering_api.is_empty()) {
  896. // Add the rendering API as a project feature if it doesn't already exist.
  897. if (!project_features.has(rendering_api)) {
  898. project_features.append(rendering_api);
  899. }
  900. }
  901. // Check for the existence of a csproj file.
  902. if (_csproj_exists(get_resource_path())) {
  903. // If there is a csproj file, add the C# feature if it doesn't already exist.
  904. if (!project_features.has("C#")) {
  905. project_features.append("C#");
  906. }
  907. } else {
  908. // If there isn't a csproj file, remove the C# feature if it exists.
  909. if (project_features.has("C#")) {
  910. project_features.remove_at(project_features.find("C#"));
  911. }
  912. }
  913. project_features = _trim_to_supported_features(project_features);
  914. set_setting("application/config/features", project_features);
  915. #endif // TOOLS_ENABLED
  916. RBSet<_VCSort> vclist;
  917. if (p_merge_with_current) {
  918. for (const KeyValue<StringName, VariantContainer> &G : props) {
  919. const VariantContainer *v = &G.value;
  920. if (v->hide_from_editor) {
  921. continue;
  922. }
  923. if (p_custom.has(G.key)) {
  924. continue;
  925. }
  926. _VCSort vc;
  927. vc.name = G.key; //*k;
  928. vc.order = v->order;
  929. vc.type = v->variant.get_type();
  930. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  931. if (v->variant == v->initial) {
  932. continue;
  933. }
  934. vclist.insert(vc);
  935. }
  936. }
  937. for (const KeyValue<String, Variant> &E : p_custom) {
  938. // Lookup global prop to store in the same order
  939. RBMap<StringName, VariantContainer>::Iterator global_prop = props.find(E.key);
  940. _VCSort vc;
  941. vc.name = E.key;
  942. vc.order = global_prop ? global_prop->value.order : 0xFFFFFFF;
  943. vc.type = E.value.get_type();
  944. vc.flags = PROPERTY_USAGE_STORAGE;
  945. vclist.insert(vc);
  946. }
  947. RBMap<String, List<String>> save_props;
  948. for (const _VCSort &E : vclist) {
  949. String category = E.name;
  950. String name = E.name;
  951. int div = category.find_char('/');
  952. if (div < 0) {
  953. category = "";
  954. } else {
  955. category = category.substr(0, div);
  956. name = name.substr(div + 1);
  957. }
  958. save_props[category].push_back(name);
  959. }
  960. String save_features;
  961. for (int i = 0; i < p_custom_features.size(); i++) {
  962. if (i > 0) {
  963. save_features += ",";
  964. }
  965. String f = p_custom_features[i].strip_edges().remove_char('\"');
  966. save_features += f;
  967. }
  968. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  969. return _save_settings_text(p_path, save_props, p_custom, save_features);
  970. } else if (p_path.ends_with(".binary")) {
  971. return _save_settings_binary(p_path, save_props, p_custom, save_features);
  972. } else {
  973. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, vformat("Unknown config file format: '%s'.", p_path));
  974. }
  975. }
  976. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
  977. Variant ret;
  978. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  979. ProjectSettings::get_singleton()->set(p_var, p_default);
  980. }
  981. ret = GLOBAL_GET(p_var);
  982. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  983. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  984. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  985. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  986. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  987. ProjectSettings::get_singleton()->set_as_internal(p_var, p_internal);
  988. return ret;
  989. }
  990. Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
  991. Variant ret = _GLOBAL_DEF(p_info.name, p_default, p_restart_if_changed, p_ignore_value_in_docs, p_basic, p_internal);
  992. ProjectSettings::get_singleton()->set_custom_property_info(p_info);
  993. return ret;
  994. }
  995. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  996. ERR_FAIL_COND(!p_info.has("name"));
  997. ERR_FAIL_COND(!p_info.has("type"));
  998. PropertyInfo pinfo;
  999. pinfo.name = p_info["name"];
  1000. ERR_FAIL_COND(!props.has(pinfo.name));
  1001. pinfo.type = Variant::Type(p_info["type"].operator int());
  1002. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  1003. if (p_info.has("hint")) {
  1004. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  1005. }
  1006. if (p_info.has("hint_string")) {
  1007. pinfo.hint_string = p_info["hint_string"];
  1008. }
  1009. set_custom_property_info(pinfo);
  1010. }
  1011. void ProjectSettings::set_custom_property_info(const PropertyInfo &p_info) {
  1012. const String &prop_name = p_info.name;
  1013. ERR_FAIL_COND(!props.has(prop_name));
  1014. custom_prop_info[prop_name] = p_info;
  1015. }
  1016. const HashMap<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  1017. return custom_prop_info;
  1018. }
  1019. bool ProjectSettings::is_using_datapack() const {
  1020. return using_datapack;
  1021. }
  1022. bool ProjectSettings::is_project_loaded() const {
  1023. return project_loaded;
  1024. }
  1025. bool ProjectSettings::_property_can_revert(const StringName &p_name) const {
  1026. return props.has(p_name);
  1027. }
  1028. bool ProjectSettings::_property_get_revert(const StringName &p_name, Variant &r_property) const {
  1029. const RBMap<StringName, ProjectSettings::VariantContainer>::Element *value = props.find(p_name);
  1030. if (value) {
  1031. r_property = value->value().initial.duplicate();
  1032. return true;
  1033. }
  1034. return false;
  1035. }
  1036. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  1037. set(p_setting, p_value);
  1038. }
  1039. Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_default_value) const {
  1040. if (has_setting(p_setting)) {
  1041. return get(p_setting);
  1042. } else {
  1043. return p_default_value;
  1044. }
  1045. }
  1046. void ProjectSettings::refresh_global_class_list() {
  1047. // This is called after mounting a new PCK file to pick up class changes.
  1048. is_global_class_list_loaded = false; // Make sure we read from the freshly mounted PCK.
  1049. Array script_classes = get_global_class_list();
  1050. for (int i = 0; i < script_classes.size(); i++) {
  1051. Dictionary c = script_classes[i];
  1052. if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base") || !c.has("is_abstract") || !c.has("is_tool")) {
  1053. continue;
  1054. }
  1055. ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"], c["is_abstract"], c["is_tool"]);
  1056. }
  1057. }
  1058. TypedArray<Dictionary> ProjectSettings::get_global_class_list() {
  1059. if (is_global_class_list_loaded) {
  1060. return global_class_list;
  1061. }
  1062. Ref<ConfigFile> cf;
  1063. cf.instantiate();
  1064. if (cf->load(get_global_class_list_path()) == OK) {
  1065. global_class_list = cf->get_value("", "list", Array());
  1066. } else {
  1067. #ifndef TOOLS_ENABLED
  1068. // Script classes can't be recreated in exported project, so print an error.
  1069. ERR_PRINT("Could not load global script cache.");
  1070. #endif
  1071. }
  1072. // File read succeeded or failed. If it failed, assume everything is still okay.
  1073. // We will later receive updated class data in store_global_class_list().
  1074. is_global_class_list_loaded = true;
  1075. return global_class_list;
  1076. }
  1077. String ProjectSettings::get_global_class_list_path() const {
  1078. return get_project_data_path().path_join("global_script_class_cache.cfg");
  1079. }
  1080. void ProjectSettings::store_global_class_list(const Array &p_classes) {
  1081. Ref<ConfigFile> cf;
  1082. cf.instantiate();
  1083. cf->set_value("", "list", p_classes);
  1084. cf->save(get_global_class_list_path());
  1085. global_class_list = p_classes;
  1086. }
  1087. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  1088. return custom_features.has(p_feature);
  1089. }
  1090. const HashMap<StringName, ProjectSettings::AutoloadInfo> &ProjectSettings::get_autoload_list() const {
  1091. return autoloads;
  1092. }
  1093. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  1094. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  1095. autoloads[p_autoload.name] = p_autoload;
  1096. }
  1097. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  1098. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  1099. autoloads.erase(p_autoload);
  1100. }
  1101. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  1102. return autoloads.has(p_autoload);
  1103. }
  1104. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  1105. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  1106. return autoloads[p_name];
  1107. }
  1108. const HashMap<StringName, String> &ProjectSettings::get_global_groups_list() const {
  1109. return global_groups;
  1110. }
  1111. void ProjectSettings::add_global_group(const StringName &p_name, const String &p_description) {
  1112. ERR_FAIL_COND_MSG(p_name == StringName(), "Trying to add global group with no name.");
  1113. global_groups[p_name] = p_description;
  1114. }
  1115. void ProjectSettings::remove_global_group(const StringName &p_name) {
  1116. ERR_FAIL_COND_MSG(!global_groups.has(p_name), "Trying to remove non-existent global group.");
  1117. global_groups.erase(p_name);
  1118. }
  1119. bool ProjectSettings::has_global_group(const StringName &p_name) const {
  1120. return global_groups.has(p_name);
  1121. }
  1122. void ProjectSettings::remove_scene_groups_cache(const StringName &p_path) {
  1123. scene_groups_cache.erase(p_path);
  1124. }
  1125. void ProjectSettings::add_scene_groups_cache(const StringName &p_path, const HashSet<StringName> &p_cache) {
  1126. scene_groups_cache[p_path] = p_cache;
  1127. }
  1128. void ProjectSettings::save_scene_groups_cache() {
  1129. Ref<ConfigFile> cf;
  1130. cf.instantiate();
  1131. for (const KeyValue<StringName, HashSet<StringName>> &E : scene_groups_cache) {
  1132. if (E.value.is_empty()) {
  1133. continue;
  1134. }
  1135. Array list;
  1136. for (const StringName &group : E.value) {
  1137. list.push_back(group);
  1138. }
  1139. cf->set_value(E.key, "groups", list);
  1140. }
  1141. cf->save(get_scene_groups_cache_path());
  1142. }
  1143. String ProjectSettings::get_scene_groups_cache_path() const {
  1144. return get_project_data_path().path_join("scene_groups_cache.cfg");
  1145. }
  1146. void ProjectSettings::load_scene_groups_cache() {
  1147. Ref<ConfigFile> cf;
  1148. cf.instantiate();
  1149. if (cf->load(get_scene_groups_cache_path()) == OK) {
  1150. List<String> scene_paths;
  1151. cf->get_sections(&scene_paths);
  1152. for (const String &E : scene_paths) {
  1153. Array scene_groups = cf->get_value(E, "groups", Array());
  1154. HashSet<StringName> cache;
  1155. for (const Variant &scene_group : scene_groups) {
  1156. cache.insert(scene_group);
  1157. }
  1158. add_scene_groups_cache(E, cache);
  1159. }
  1160. }
  1161. }
  1162. const HashMap<StringName, HashSet<StringName>> &ProjectSettings::get_scene_groups_cache() const {
  1163. return scene_groups_cache;
  1164. }
  1165. #ifdef TOOLS_ENABLED
  1166. void ProjectSettings::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1167. const String pf = p_function;
  1168. if (p_idx == 0) {
  1169. if (pf == "has_setting" || pf == "set_setting" || pf == "get_setting" || pf == "get_setting_with_override" ||
  1170. pf == "set_order" || pf == "get_order" || pf == "set_initial_value" || pf == "set_as_basic" ||
  1171. pf == "set_as_internal" || pf == "set_restart_if_changed" || pf == "clear") {
  1172. for (const KeyValue<StringName, VariantContainer> &E : props) {
  1173. if (E.value.hide_from_editor) {
  1174. continue;
  1175. }
  1176. r_options->push_back(String(E.key).quote());
  1177. }
  1178. }
  1179. }
  1180. Object::get_argument_options(p_function, p_idx, r_options);
  1181. }
  1182. #endif
  1183. void ProjectSettings::_bind_methods() {
  1184. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  1185. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  1186. ClassDB::bind_method(D_METHOD("get_setting", "name", "default_value"), &ProjectSettings::get_setting, DEFVAL(Variant()));
  1187. ClassDB::bind_method(D_METHOD("get_setting_with_override", "name"), &ProjectSettings::get_setting_with_override);
  1188. ClassDB::bind_method(D_METHOD("get_global_class_list"), &ProjectSettings::get_global_class_list);
  1189. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  1190. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  1191. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  1192. ClassDB::bind_method(D_METHOD("set_as_basic", "name", "basic"), &ProjectSettings::set_as_basic);
  1193. ClassDB::bind_method(D_METHOD("set_as_internal", "name", "internal"), &ProjectSettings::set_as_internal);
  1194. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  1195. ClassDB::bind_method(D_METHOD("set_restart_if_changed", "name", "restart"), &ProjectSettings::set_restart_if_changed);
  1196. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  1197. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  1198. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  1199. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  1200. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::load_resource_pack, DEFVAL(true), DEFVAL(0));
  1201. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  1202. ADD_SIGNAL(MethodInfo("settings_changed"));
  1203. }
  1204. void ProjectSettings::_add_builtin_input_map() {
  1205. if (InputMap::get_singleton()) {
  1206. HashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  1207. for (KeyValue<String, List<Ref<InputEvent>>> &E : builtins) {
  1208. Array events;
  1209. // Convert list of input events into array
  1210. for (List<Ref<InputEvent>>::Element *I = E.value.front(); I; I = I->next()) {
  1211. events.push_back(I->get());
  1212. }
  1213. Dictionary action;
  1214. action["deadzone"] = Variant(InputMap::DEFAULT_TOGGLE_DEADZONE);
  1215. action["events"] = events;
  1216. String action_name = "input/" + E.key;
  1217. GLOBAL_DEF(action_name, action);
  1218. input_presets.push_back(action_name);
  1219. }
  1220. }
  1221. }
  1222. ProjectSettings::ProjectSettings() {
  1223. // Initialization of engine variables should be done in the setup() method,
  1224. // so that the values can be overridden from project.godot or project.binary.
  1225. CRASH_COND_MSG(singleton != nullptr, "Instantiating a new ProjectSettings singleton is not supported.");
  1226. singleton = this;
  1227. #ifdef TOOLS_ENABLED
  1228. // Available only at runtime in editor builds. Needs to be processed before anything else to work properly.
  1229. if (!Engine::get_singleton()->is_editor_hint()) {
  1230. String editor_features = OS::get_singleton()->get_environment("GODOT_EDITOR_CUSTOM_FEATURES");
  1231. if (!editor_features.is_empty()) {
  1232. PackedStringArray feature_list = editor_features.split(",");
  1233. for (const String &s : feature_list) {
  1234. custom_features.insert(s);
  1235. }
  1236. }
  1237. }
  1238. #endif
  1239. GLOBAL_DEF_BASIC("application/config/name", "");
  1240. GLOBAL_DEF_BASIC(PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary());
  1241. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT), "");
  1242. GLOBAL_DEF_BASIC("application/config/version", "");
  1243. GLOBAL_DEF_INTERNAL(PropertyInfo(Variant::STRING, "application/config/tags"), PackedStringArray());
  1244. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), "");
  1245. GLOBAL_DEF("application/run/disable_stdout", false);
  1246. GLOBAL_DEF("application/run/disable_stderr", false);
  1247. GLOBAL_DEF("application/run/print_header", true);
  1248. GLOBAL_DEF("application/run/enable_alt_space_menu", false);
  1249. GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true);
  1250. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  1251. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  1252. GLOBAL_DEF("application/config/project_settings_override", "");
  1253. GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
  1254. GLOBAL_DEF("application/config/auto_accept_quit", true);
  1255. GLOBAL_DEF("application/config/quit_on_go_back", true);
  1256. // The default window size is tuned to:
  1257. // - Have a 16:9 aspect ratio,
  1258. // - Have both dimensions divisible by 8 to better play along with video recording,
  1259. // - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings).
  1260. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "1,7680,1,or_greater"), 1152); // 8K resolution
  1261. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "1,4320,1,or_greater"), 648); // 8K resolution
  1262. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), 0);
  1263. // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
  1264. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_position_type", PROPERTY_HINT_ENUM, "Absolute,Center of Primary Screen,Center of Other Screen,Center of Screen With Mouse Pointer,Center of Screen With Keyboard Focus"), 1);
  1265. GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR2I, "display/window/size/initial_position"), Vector2i());
  1266. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), 0);
  1267. GLOBAL_DEF_BASIC("display/window/size/resizable", true);
  1268. GLOBAL_DEF_BASIC("display/window/size/borderless", false);
  1269. GLOBAL_DEF("display/window/size/always_on_top", false);
  1270. GLOBAL_DEF("display/window/size/transparent", false);
  1271. GLOBAL_DEF("display/window/size/extend_to_title", false);
  1272. GLOBAL_DEF("display/window/size/no_focus", false);
  1273. GLOBAL_DEF("display/window/size/sharp_corners", false);
  1274. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution
  1275. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution
  1276. GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true);
  1277. GLOBAL_DEF("animation/warnings/check_invalid_track_paths", true);
  1278. GLOBAL_DEF("animation/warnings/check_angle_interpolation_type_conflicting", true);
  1279. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"), "res://default_bus_layout.tres");
  1280. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type", PROPERTY_HINT_ENUM, "Stream,Sample"), 0);
  1281. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/default_playback_type.web", PROPERTY_HINT_ENUM, "Stream,Sample"), 1);
  1282. GLOBAL_DEF_RST("audio/general/text_to_speech", false);
  1283. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1284. GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f);
  1285. GLOBAL_DEF(PropertyInfo(Variant::INT, "audio/general/ios/session_category", PROPERTY_HINT_ENUM, "Ambient,Multi Route,Play and Record,Playback,Record,Solo Ambient"), 0);
  1286. GLOBAL_DEF("audio/general/ios/mix_with_others", false);
  1287. _add_builtin_input_map();
  1288. // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
  1289. custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor");
  1290. GLOBAL_DEF("display/window/subwindows/embed_subwindows", true);
  1291. // Keep the enum values in sync with the `DisplayServer::VSyncMode` enum.
  1292. custom_prop_info["display/window/vsync/vsync_mode"] = PropertyInfo(Variant::INT, "display/window/vsync/vsync_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Adaptive,Mailbox");
  1293. GLOBAL_DEF("display/window/frame_pacing/android/enable_frame_pacing", true);
  1294. GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/frame_pacing/android/swappy_mode", PROPERTY_HINT_ENUM, "pipeline_forced_on,auto_fps_pipeline_forced_on,auto_fps_auto_pipeline"), 2);
  1295. #ifdef DISABLE_DEPRECATED
  1296. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Safe:1,Separate");
  1297. #else
  1298. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Unsafe (deprecated),Safe,Separate");
  1299. #endif
  1300. GLOBAL_DEF("physics/2d/run_on_separate_thread", false);
  1301. GLOBAL_DEF("physics/3d/run_on_separate_thread", false);
  1302. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/mode", PROPERTY_HINT_ENUM, "disabled,canvas_items,viewport"), "disabled");
  1303. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/aspect", PROPERTY_HINT_ENUM, "ignore,keep,keep_width,keep_height,expand"), "keep");
  1304. GLOBAL_DEF_BASIC(PropertyInfo(Variant::FLOAT, "display/window/stretch/scale", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), 1.0);
  1305. GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/window/stretch/scale_mode", PROPERTY_HINT_ENUM, "fractional,integer"), "fractional");
  1306. GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"), 16384);
  1307. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "debug/settings/profiler/max_timestamp_query_elements", PROPERTY_HINT_RANGE, "256,65535,1"), 256);
  1308. GLOBAL_DEF(PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"), Compression::zstd_long_distance_matching);
  1309. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"), Compression::zstd_level);
  1310. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"), Compression::zstd_window_log_size);
  1311. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::zlib_level);
  1312. GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::gzip_level);
  1313. GLOBAL_DEF("debug/settings/crash_handler/message",
  1314. String("Please include this when reporting the bug to the project developer."));
  1315. GLOBAL_DEF("debug/settings/crash_handler/message.editor",
  1316. String("Please include this when reporting the bug on: https://github.com/godotengine/godot/issues"));
  1317. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/occlusion_culling/bvh_build_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), 2);
  1318. GLOBAL_DEF_RST("rendering/occlusion_culling/jitter_projection", true);
  1319. GLOBAL_DEF_RST("internationalization/rendering/force_right_to_left_layout_direction", false);
  1320. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "internationalization/rendering/root_node_layout_direction", PROPERTY_HINT_ENUM, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale"), 0);
  1321. GLOBAL_DEF_BASIC("internationalization/rendering/root_node_auto_translate", true);
  1322. GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/timers/incremental_search_max_interval_msec", PROPERTY_HINT_RANGE, "0,10000,1,or_greater"), 2000);
  1323. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "gui/timers/tooltip_delay_sec", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater"), 0.5);
  1324. #ifdef TOOLS_ENABLED
  1325. GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5);
  1326. #endif
  1327. GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
  1328. GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);
  1329. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/frame_queue_size", PROPERTY_HINT_RANGE, "2,3,1"), 2);
  1330. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/swapchain_image_count", PROPERTY_HINT_RANGE, "2,4,1"), 3);
  1331. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/block_size_kb", PROPERTY_HINT_RANGE, "4,2048,1,or_greater"), 256);
  1332. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/max_size_mb", PROPERTY_HINT_RANGE, "1,1024,1,or_greater"), 128);
  1333. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_upload_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1334. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/staging_buffer/texture_download_region_size_px", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1335. GLOBAL_DEF_RST(PropertyInfo(Variant::BOOL, "rendering/rendering_device/pipeline_cache/enable"), true);
  1336. GLOBAL_DEF(PropertyInfo(Variant::FLOAT, "rendering/rendering_device/pipeline_cache/save_chunk_size_mb", PROPERTY_HINT_RANGE, "0.000001,64.0,0.001,or_greater"), 3.0);
  1337. GLOBAL_DEF(PropertyInfo(Variant::INT, "rendering/rendering_device/vulkan/max_descriptors_per_pool", PROPERTY_HINT_RANGE, "1,256,1,or_greater"), 64);
  1338. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", 16384);
  1339. custom_prop_info["rendering/rendering_device/d3d12/max_resource_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_resource_descriptors_per_frame", PROPERTY_HINT_RANGE, "512,262144");
  1340. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", 1024);
  1341. custom_prop_info["rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_sampler_descriptors_per_frame", PROPERTY_HINT_RANGE, "256,2048");
  1342. GLOBAL_DEF_RST("rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", 512);
  1343. custom_prop_info["rendering/rendering_device/d3d12/max_misc_descriptors_per_frame"] = PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/max_misc_descriptors_per_frame", PROPERTY_HINT_RANGE, "32,4096");
  1344. // The default value must match the minor part of the Agility SDK version
  1345. // installed by the scripts provided in the repository
  1346. // (check `misc/scripts/install_d3d12_sdk_windows.py`).
  1347. // For example, if the script installs 1.613.3, the default value must be 613.
  1348. GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/d3d12/agility_sdk_version", PROPERTY_HINT_RANGE, "0,10000,1,or_greater,hide_slider"), 613);
  1349. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), 1);
  1350. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/textures/canvas_textures/default_texture_repeat", PROPERTY_HINT_ENUM, "Disable,Enable,Mirror"), 0);
  1351. GLOBAL_DEF("collada/use_ambient", false);
  1352. // Input settings
  1353. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_long_press_as_right_click", false);
  1354. GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_pan_and_scale_gestures", false);
  1355. GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "input_devices/pointing/android/rotary_input_scroll_axis", PROPERTY_HINT_ENUM, "Horizontal,Vertical"), 1);
  1356. GLOBAL_DEF("input_devices/pointing/android/override_volume_buttons", false);
  1357. // These properties will not show up in the dialog. If you want to exclude whole groups, use add_hidden_prefix().
  1358. GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray());
  1359. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray());
  1360. GLOBAL_DEF_INTERNAL("internationalization/locale/translations", PackedStringArray());
  1361. GLOBAL_DEF_INTERNAL("internationalization/locale/translations_pot_files", PackedStringArray());
  1362. GLOBAL_DEF_INTERNAL("internationalization/locale/translation_add_builtin_strings_to_pot", false);
  1363. ProjectSettings::get_singleton()->add_hidden_prefix("input/");
  1364. }
  1365. ProjectSettings::ProjectSettings(const String &p_path) {
  1366. if (load_custom(p_path) == OK) {
  1367. resource_path = p_path.get_base_dir();
  1368. project_loaded = true;
  1369. }
  1370. }
  1371. ProjectSettings::~ProjectSettings() {
  1372. if (singleton == this) {
  1373. singleton = nullptr;
  1374. }
  1375. }