project_settings.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*************************************************************************/
  2. /* project_settings.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "object.h"
  33. #include "os/thread_safe.h"
  34. #include "set.h"
  35. /**
  36. @author Juan Linietsky <reduzio@gmail.com>
  37. */
  38. class ProjectSettings : public Object {
  39. GDCLASS(ProjectSettings, Object);
  40. _THREAD_SAFE_CLASS_
  41. public:
  42. typedef Map<String, Variant> CustomMap;
  43. enum {
  44. //properties that are not for built in values begin from this value, so builtin ones are displayed first
  45. NO_BUILTIN_ORDER_BASE = 1 << 16
  46. };
  47. protected:
  48. struct VariantContainer {
  49. int order;
  50. bool persist;
  51. Variant variant;
  52. Variant initial;
  53. bool hide_from_editor;
  54. bool overridden;
  55. VariantContainer() :
  56. order(0),
  57. persist(false),
  58. hide_from_editor(false),
  59. overridden(false) {
  60. }
  61. VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) :
  62. order(p_order),
  63. persist(p_persist),
  64. variant(p_variant),
  65. hide_from_editor(false),
  66. overridden(false) {
  67. }
  68. };
  69. bool registering_order;
  70. int last_order;
  71. int last_builtin_order;
  72. Map<StringName, VariantContainer> props;
  73. String resource_path;
  74. Map<StringName, PropertyInfo> custom_prop_info;
  75. bool disable_feature_overrides;
  76. bool using_datapack;
  77. List<String> input_presets;
  78. Set<String> custom_features;
  79. Map<StringName, StringName> feature_overrides;
  80. bool _set(const StringName &p_name, const Variant &p_value);
  81. bool _get(const StringName &p_name, Variant &r_ret) const;
  82. void _get_property_list(List<PropertyInfo> *p_list) const;
  83. static ProjectSettings *singleton;
  84. Error _load_settings_text(const String p_path);
  85. Error _load_settings_binary(const String p_path);
  86. Error _load_settings_text_or_binary(const String p_text_path, const String p_bin_path);
  87. 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());
  88. 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());
  89. Error _save_custom_bnd(const String &p_file);
  90. bool _load_resource_pack(const String &p_pack);
  91. void _add_property_info_bind(const Dictionary &p_info);
  92. protected:
  93. static void _bind_methods();
  94. public:
  95. void set_setting(const String &p_setting, const Variant &p_value);
  96. Variant get_setting(const String &p_setting) const;
  97. bool has_setting(String p_var) const;
  98. String localize_path(const String &p_path) const;
  99. String globalize_path(const String &p_path) const;
  100. void set_initial_value(const String &p_name, const Variant &p_value);
  101. bool property_can_revert(const String &p_name);
  102. Variant property_get_revert(const String &p_name);
  103. String get_resource_path() const;
  104. static ProjectSettings *get_singleton();
  105. void clear(const String &p_name);
  106. int get_order(const String &p_name) const;
  107. void set_order(const String &p_name, int p_order);
  108. void set_builtin_order(const String &p_name);
  109. Error setup(const String &p_path, const String &p_main_pack, bool p_upwards = false);
  110. 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);
  111. Error save();
  112. void set_custom_property_info(const String &p_prop, const PropertyInfo &p_info);
  113. Vector<String> get_optimizer_presets() const;
  114. List<String> get_input_presets() const { return input_presets; }
  115. void set_disable_feature_overrides(bool p_disable);
  116. void register_global_defaults();
  117. bool is_using_datapack() const;
  118. void set_registering_order(bool p_enable);
  119. bool has_custom_feature(const String &p_feature) const;
  120. ProjectSettings();
  121. ~ProjectSettings();
  122. };
  123. //not a macro any longer
  124. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default);
  125. #define GLOBAL_DEF(m_var, m_value) _GLOBAL_DEF(m_var, m_value)
  126. #define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get(m_var)
  127. #endif