project_settings.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*************************************************************************/
  2. /* project_settings.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef GLOBAL_CONFIG_H
  31. #define GLOBAL_CONFIG_H
  32. #include "core/object.h"
  33. #include "core/os/thread_safe.h"
  34. #include "core/set.h"
  35. class ProjectSettings : public Object {
  36. GDCLASS(ProjectSettings, Object);
  37. _THREAD_SAFE_CLASS_
  38. public:
  39. typedef Map<String, Variant> CustomMap;
  40. enum {
  41. //properties that are not for built in values begin from this value, so builtin ones are displayed first
  42. NO_BUILTIN_ORDER_BASE = 1 << 16
  43. };
  44. protected:
  45. struct VariantContainer {
  46. int order;
  47. bool persist;
  48. Variant variant;
  49. Variant initial;
  50. bool hide_from_editor;
  51. bool overridden;
  52. bool restart_if_changed;
  53. VariantContainer() :
  54. order(0),
  55. persist(false),
  56. hide_from_editor(false),
  57. overridden(false),
  58. restart_if_changed(false) {
  59. }
  60. VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) :
  61. order(p_order),
  62. persist(p_persist),
  63. variant(p_variant),
  64. hide_from_editor(false),
  65. overridden(false),
  66. restart_if_changed(false) {
  67. }
  68. };
  69. bool registering_order;
  70. int last_order;
  71. int last_builtin_order;
  72. uint64_t last_save_time = 0;
  73. Map<StringName, VariantContainer> props;
  74. String resource_path;
  75. Map<StringName, PropertyInfo> custom_prop_info;
  76. bool disable_feature_overrides;
  77. bool using_datapack;
  78. List<String> input_presets;
  79. Set<String> custom_features;
  80. Map<StringName, StringName> feature_overrides;
  81. bool _set(const StringName &p_name, const Variant &p_value);
  82. bool _get(const StringName &p_name, Variant &r_ret) const;
  83. void _get_property_list(List<PropertyInfo> *p_list) const;
  84. static ProjectSettings *singleton;
  85. Error _load_settings_text(const String &p_path);
  86. Error _load_settings_binary(const String &p_path);
  87. Error _load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path);
  88. Error _save_settings_text(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
  89. Error _save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
  90. Error _save_custom_bnd(const String &p_file);
  91. void _convert_to_last_version(int p_from_version);
  92. bool _load_resource_pack(const String &p_pack, bool p_replace_files = true, int p_offset = 0);
  93. void _add_property_info_bind(const Dictionary &p_info);
  94. Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false);
  95. static void _bind_methods();
  96. public:
  97. static const int CONFIG_VERSION = 4;
  98. void set_setting(const String &p_setting, const Variant &p_value);
  99. Variant get_setting(const String &p_setting) const;
  100. bool has_setting(String p_var) const;
  101. String localize_path(const String &p_path) const;
  102. String globalize_path(const String &p_path) const;
  103. void set_initial_value(const String &p_name, const Variant &p_value);
  104. void set_restart_if_changed(const String &p_name, bool p_restart);
  105. bool property_can_revert(const String &p_name);
  106. Variant property_get_revert(const String &p_name);
  107. String get_resource_path() const;
  108. static ProjectSettings *get_singleton();
  109. void clear(const String &p_name);
  110. int get_order(const String &p_name) const;
  111. void set_order(const String &p_name, int p_order);
  112. void set_builtin_order(const String &p_name);
  113. Error setup(const String &p_path, const String &p_main_pack, bool p_upwards = false);
  114. Error save_custom(const String &p_path = "", const CustomMap &p_custom = CustomMap(), const Vector<String> &p_custom_features = Vector<String>(), bool p_merge_with_current = true);
  115. Error save();
  116. void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info);
  117. const Map<StringName, PropertyInfo> &get_custom_property_info() const;
  118. uint64_t get_last_saved_time() { return last_save_time; }
  119. Vector<String> get_optimizer_presets() const;
  120. List<String> get_input_presets() const { return input_presets; }
  121. void set_disable_feature_overrides(bool p_disable);
  122. bool is_using_datapack() const;
  123. void set_registering_order(bool p_enable);
  124. bool has_custom_feature(const String &p_feature) const;
  125. ProjectSettings();
  126. ~ProjectSettings();
  127. };
  128. //not a macro any longer
  129. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed = false);
  130. Variant _GLOBAL_DEF_ALIAS(const String &p_var, const String &p_old_name, const Variant &p_default, bool p_restart_if_changed = false);
  131. #define GLOBAL_DEF(m_var, m_value) _GLOBAL_DEF(m_var, m_value)
  132. #define GLOBAL_DEF_RST(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true)
  133. #define GLOBAL_DEF_ALIAS(m_var, m_old_name, m_value) _GLOBAL_DEF_ALIAS(m_var, m_old_name, m_value)
  134. #define GLOBAL_DEF_ALIAS_RST(m_var, m_old_name, m_value) _GLOBAL_DEF(m_var, m_old_name, m_value, true)
  135. #define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get(m_var)
  136. #endif