2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* project_settings.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2020-03-25 11:10:34 +01:00
|
|
|
#ifndef PROJECT_SETTINGS_H
|
|
|
|
#define PROJECT_SETTINGS_H
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/object/class_db.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
|
2023-02-03 19:37:52 +01:00
|
|
|
template <typename T>
|
|
|
|
class TypedArray;
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
class ProjectSettings : public Object {
|
|
|
|
GDCLASS(ProjectSettings, Object);
|
2014-02-10 02:10:30 +01:00
|
|
|
_THREAD_SAFE_CLASS_
|
2023-07-11 16:07:35 +02:00
|
|
|
friend class TestProjectSettingsInternalsAccessor;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-06-14 18:33:57 +02:00
|
|
|
bool is_changed = false;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2022-05-13 15:04:37 +02:00
|
|
|
typedef HashMap<String, Variant> CustomMap;
|
2021-10-13 22:56:18 +02:00
|
|
|
static const String PROJECT_DATA_DIR_NAME_SUFFIX;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-16 03:39:36 +01:00
|
|
|
enum {
|
2022-09-09 02:29:59 +02:00
|
|
|
// Properties that are not for built in values begin from this value, so builtin ones are displayed first.
|
2017-07-18 02:05:38 +02:00
|
|
|
NO_BUILTIN_ORDER_BASE = 1 << 16
|
2015-12-16 03:39:36 +01:00
|
|
|
};
|
2022-09-09 02:29:59 +02:00
|
|
|
|
2022-08-09 21:36:02 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-11-24 17:12:56 +01:00
|
|
|
const static PackedStringArray get_required_features();
|
|
|
|
const static PackedStringArray get_unsupported_features(const PackedStringArray &p_project_features);
|
2022-08-09 21:36:02 +02:00
|
|
|
#endif // TOOLS_ENABLED
|
2015-12-16 03:39:36 +01:00
|
|
|
|
2020-06-18 01:45:08 +02:00
|
|
|
struct AutoloadInfo {
|
|
|
|
StringName name;
|
|
|
|
String path;
|
|
|
|
bool is_singleton = false;
|
|
|
|
};
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
struct VariantContainer {
|
2020-05-12 17:01:17 +02:00
|
|
|
int order = 0;
|
|
|
|
bool persist = false;
|
2021-02-17 17:44:49 +01:00
|
|
|
bool basic = false;
|
2022-06-06 15:22:57 +02:00
|
|
|
bool internal = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant variant;
|
2017-01-05 13:16:00 +01:00
|
|
|
Variant initial;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool hide_from_editor = false;
|
|
|
|
bool restart_if_changed = false;
|
2020-05-20 21:49:39 +02:00
|
|
|
#ifdef DEBUG_METHODS_ENABLED
|
|
|
|
bool ignore_value_in_docs = false;
|
|
|
|
#endif
|
2020-05-12 17:01:17 +02:00
|
|
|
|
|
|
|
VariantContainer() {}
|
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) :
|
|
|
|
order(p_order),
|
|
|
|
persist(p_persist),
|
2020-05-12 17:01:17 +02:00
|
|
|
variant(p_variant) {
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2020-08-14 10:04:34 +02:00
|
|
|
int last_order = NO_BUILTIN_ORDER_BASE;
|
|
|
|
int last_builtin_order = 0;
|
2021-01-17 01:09:17 +01:00
|
|
|
uint64_t last_save_time = 0;
|
|
|
|
|
2022-05-17 10:53:59 +02:00
|
|
|
RBMap<StringName, VariantContainer> props; // NOTE: Key order is used e.g. in the save_custom method.
|
2014-02-10 02:10:30 +01:00
|
|
|
String resource_path;
|
2022-05-13 15:04:37 +02:00
|
|
|
HashMap<StringName, PropertyInfo> custom_prop_info;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool using_datapack = false;
|
2023-02-19 21:05:16 +01:00
|
|
|
bool project_loaded = false;
|
2015-12-14 22:36:53 +01:00
|
|
|
List<String> input_presets;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-05-19 17:00:06 +02:00
|
|
|
HashSet<String> custom_features;
|
2023-01-13 13:16:49 +01:00
|
|
|
HashMap<StringName, LocalVector<Pair<StringName, StringName>>> feature_overrides;
|
2017-07-19 22:00:46 +02:00
|
|
|
|
2022-06-08 17:52:19 +02:00
|
|
|
LocalVector<String> hidden_prefixes;
|
2022-05-08 10:09:19 +02:00
|
|
|
HashMap<StringName, AutoloadInfo> autoloads;
|
2022-05-12 10:20:12 +02:00
|
|
|
HashMap<StringName, String> global_groups;
|
|
|
|
HashMap<StringName, HashSet<StringName>> scene_groups_cache;
|
2020-06-18 01:45:08 +02:00
|
|
|
|
2023-02-03 19:37:52 +01:00
|
|
|
Array global_class_list;
|
|
|
|
bool is_global_class_list_loaded = false;
|
|
|
|
|
2021-09-10 17:32:29 +02:00
|
|
|
String project_data_dir_name;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2022-08-12 20:43:14 +02:00
|
|
|
bool _property_can_revert(const StringName &p_name) const;
|
|
|
|
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-06-14 18:33:57 +02:00
|
|
|
void _queue_changed();
|
|
|
|
void _emit_changed();
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
static ProjectSettings *singleton;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2019-07-10 11:54:12 +02:00
|
|
|
Error _load_settings_text(const String &p_path);
|
|
|
|
Error _load_settings_binary(const String &p_path);
|
|
|
|
Error _load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-05-17 10:53:59 +02:00
|
|
|
Error _save_settings_text(const String &p_file, const RBMap<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
|
|
|
|
Error _save_settings_binary(const String &p_file, const RBMap<String, List<String>> &props, const CustomMap &p_custom = CustomMap(), const String &p_custom_features = String());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error _save_custom_bnd(const String &p_file);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-08-09 21:36:02 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-11-24 17:12:56 +01:00
|
|
|
const static PackedStringArray _get_supported_features();
|
|
|
|
const static PackedStringArray _trim_to_supported_features(const PackedStringArray &p_project_features);
|
2022-08-09 21:36:02 +02:00
|
|
|
#endif // TOOLS_ENABLED
|
2021-11-24 17:12:56 +01:00
|
|
|
|
2018-12-21 12:20:48 +01:00
|
|
|
void _convert_to_last_version(int p_from_version);
|
2018-02-21 22:06:34 +01:00
|
|
|
|
2020-07-13 18:22:06 +02:00
|
|
|
bool _load_resource_pack(const String &p_pack, bool p_replace_files = true, int p_offset = 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _add_property_info_bind(const Dictionary &p_info);
|
2016-08-16 22:10:53 +02:00
|
|
|
|
2021-11-22 16:10:31 +01:00
|
|
|
Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false, bool p_ignore_override = false);
|
2018-11-18 14:56:21 +01:00
|
|
|
|
2020-12-07 12:31:51 +01:00
|
|
|
void _add_builtin_input_map();
|
|
|
|
|
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
static void _bind_methods();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2021-11-24 17:12:56 +01:00
|
|
|
static const int CONFIG_VERSION = 5;
|
2018-12-21 12:20:48 +01:00
|
|
|
|
2017-10-05 20:34:34 +02:00
|
|
|
void set_setting(const String &p_setting, const Variant &p_value);
|
2022-06-13 23:35:02 +02:00
|
|
|
Variant get_setting(const String &p_setting, const Variant &p_default_value = Variant()) const;
|
2023-02-03 19:37:52 +01:00
|
|
|
TypedArray<Dictionary> get_global_class_list();
|
2024-03-06 18:14:21 +01:00
|
|
|
void refresh_global_class_list();
|
2022-12-25 15:08:32 +01:00
|
|
|
void store_global_class_list(const Array &p_classes);
|
2023-01-31 10:52:43 +01:00
|
|
|
String get_global_class_list_path() const;
|
2017-10-05 20:34:34 +02:00
|
|
|
|
2024-01-09 02:36:19 +01:00
|
|
|
bool has_setting(const String &p_var) const;
|
2017-03-05 16:44:50 +01:00
|
|
|
String localize_path(const String &p_path) const;
|
|
|
|
String globalize_path(const String &p_path) const;
|
2017-01-05 13:16:00 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_initial_value(const String &p_name, const Variant &p_value);
|
2021-02-17 17:44:49 +01:00
|
|
|
void set_as_basic(const String &p_name, bool p_basic);
|
2022-06-06 15:22:57 +02:00
|
|
|
void set_as_internal(const String &p_name, bool p_internal);
|
2018-07-19 23:58:15 +02:00
|
|
|
void set_restart_if_changed(const String &p_name, bool p_restart);
|
2020-05-20 21:49:39 +02:00
|
|
|
void set_ignore_value_in_docs(const String &p_name, bool p_ignore);
|
|
|
|
bool get_ignore_value_in_docs(const String &p_name) const;
|
2022-06-08 17:52:19 +02:00
|
|
|
void add_hidden_prefix(const String &p_prefix);
|
2020-05-20 21:49:39 +02:00
|
|
|
|
2021-09-10 17:32:29 +02:00
|
|
|
String get_project_data_dir_name() const;
|
|
|
|
String get_project_data_path() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
String get_resource_path() const;
|
2021-09-10 17:32:29 +02:00
|
|
|
String get_imported_files_path() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
static ProjectSettings *get_singleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void clear(const String &p_name);
|
|
|
|
int get_order(const String &p_name) const;
|
|
|
|
void set_order(const String &p_name, int p_order);
|
2017-07-18 02:05:38 +02:00
|
|
|
void set_builtin_order(const String &p_name);
|
2020-07-15 18:33:34 +02:00
|
|
|
bool is_builtin_setting(const String &p_name) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-11-22 16:10:31 +01:00
|
|
|
Error setup(const String &p_path, const String &p_main_pack, bool p_upwards = false, bool p_ignore_override = false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-11-24 17:12:56 +01:00
|
|
|
Error load_custom(const String &p_path);
|
2017-07-26 15:28:54 +02:00
|
|
|
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);
|
2014-02-10 02:10:30 +01:00
|
|
|
Error save();
|
2022-11-08 19:53:22 +01:00
|
|
|
void set_custom_property_info(const PropertyInfo &p_info);
|
2022-05-13 15:04:37 +02:00
|
|
|
const HashMap<StringName, PropertyInfo> &get_custom_property_info() const;
|
2021-01-17 01:09:17 +01:00
|
|
|
uint64_t get_last_saved_time() { return last_save_time; }
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-12-14 22:36:53 +01:00
|
|
|
List<String> get_input_presets() const { return input_presets; }
|
|
|
|
|
2023-01-13 13:16:49 +01:00
|
|
|
Variant get_setting_with_override(const StringName &p_name) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
bool is_using_datapack() const;
|
2023-02-19 21:05:16 +01:00
|
|
|
bool is_project_loaded() const;
|
2014-02-19 15:57:14 +01:00
|
|
|
|
2018-07-18 10:22:59 +02:00
|
|
|
bool has_custom_feature(const String &p_feature) const;
|
|
|
|
|
2022-05-08 10:09:19 +02:00
|
|
|
const HashMap<StringName, AutoloadInfo> &get_autoload_list() const;
|
2020-06-18 01:45:08 +02:00
|
|
|
void add_autoload(const AutoloadInfo &p_autoload);
|
|
|
|
void remove_autoload(const StringName &p_autoload);
|
|
|
|
bool has_autoload(const StringName &p_autoload) const;
|
|
|
|
AutoloadInfo get_autoload(const StringName &p_name) const;
|
|
|
|
|
2022-05-12 10:20:12 +02:00
|
|
|
const HashMap<StringName, String> &get_global_groups_list() const;
|
|
|
|
void add_global_group(const StringName &p_name, const String &p_description);
|
|
|
|
void remove_global_group(const StringName &p_name);
|
|
|
|
bool has_global_group(const StringName &p_name) const;
|
|
|
|
|
|
|
|
const HashMap<StringName, HashSet<StringName>> &get_scene_groups_cache() const;
|
|
|
|
void add_scene_groups_cache(const StringName &p_path, const HashSet<StringName> &p_cache);
|
|
|
|
void remove_scene_groups_cache(const StringName &p_path);
|
|
|
|
void save_scene_groups_cache();
|
|
|
|
String get_scene_groups_cache_path() const;
|
|
|
|
void load_scene_groups_cache();
|
|
|
|
|
2024-01-03 20:27:08 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
|
|
|
|
#endif
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
ProjectSettings();
|
2023-03-18 02:39:12 +01:00
|
|
|
ProjectSettings(const String &p_path);
|
2017-07-19 22:00:46 +02:00
|
|
|
~ProjectSettings();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2022-06-06 15:22:57 +02:00
|
|
|
// Not a macro any longer.
|
|
|
|
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed = false, bool p_ignore_value_in_docs = false, bool p_basic = false, bool p_internal = false);
|
2022-11-08 19:53:22 +01:00
|
|
|
Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p_restart_if_changed = false, bool p_ignore_value_in_docs = false, bool p_basic = false, bool p_internal = false);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define GLOBAL_DEF(m_var, m_value) _GLOBAL_DEF(m_var, m_value)
|
2018-07-19 23:58:15 +02:00
|
|
|
#define GLOBAL_DEF_RST(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true)
|
2020-05-20 21:49:39 +02:00
|
|
|
#define GLOBAL_DEF_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, true)
|
|
|
|
#define GLOBAL_DEF_RST_NOVAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, true)
|
2023-01-13 13:16:49 +01:00
|
|
|
#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get_setting_with_override(m_var)
|
2017-01-05 13:16:00 +01:00
|
|
|
|
2021-02-17 17:44:49 +01:00
|
|
|
#define GLOBAL_DEF_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, false, true)
|
|
|
|
#define GLOBAL_DEF_RST_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, false, true)
|
|
|
|
#define GLOBAL_DEF_NOVAL_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, true, true)
|
|
|
|
#define GLOBAL_DEF_RST_NOVAL_BASIC(m_var, m_value) _GLOBAL_DEF(m_var, m_value, true, true, true)
|
|
|
|
|
2022-06-06 15:22:57 +02:00
|
|
|
#define GLOBAL_DEF_INTERNAL(m_var, m_value) _GLOBAL_DEF(m_var, m_value, false, false, false, true)
|
|
|
|
|
2020-03-25 11:10:34 +01:00
|
|
|
#endif // PROJECT_SETTINGS_H
|