project_settings.cpp 61 KB

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