summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2020-06-17 20:45:08 -0300
committerGeorge Marques <george@gmarqu.es>2020-07-06 12:35:51 -0300
commit965436554721a344e8a1aa4873a6d01ebea1043d (patch)
treef972b2ac9fe722e78c75ef8181a58bb9499416b8 /core
parenta535b9160dbbcfad1884ff4a147672a0eb366a9d (diff)
Add a map of autoloads to ProjectSettings
So places that need to look into it can use the list instead of parsing ProjectSettings details (like checking "*" in path for testing if it's singleton).
Diffstat (limited to 'core')
-rw-r--r--core/project_settings.cpp42
-rw-r--r--core/project_settings.h14
2 files changed, 56 insertions, 0 deletions
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 7e96735d67..3f9585c03c 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -144,6 +144,12 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
if (p_value.get_type() == Variant::NIL) {
props.erase(p_name);
+ if (p_name.operator String().begins_with("autoload/")) {
+ String node_name = p_name.operator String().split("/")[1];
+ if (autoloads.has(node_name)) {
+ remove_autoload(node_name);
+ }
+ }
} else {
if (p_name == CoreStringNames::get_singleton()->_custom_features) {
Vector<String> custom_feature_array = String(p_value).split(",");
@@ -181,6 +187,19 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
} else {
props[p_name] = VariantContainer(p_value, last_order++);
}
+ if (p_name.operator String().begins_with("autoload/")) {
+ String node_name = p_name.operator String().split("/")[1];
+ AutoloadInfo autoload;
+ autoload.name = node_name;
+ String path = p_value;
+ if (path.begins_with("*")) {
+ autoload.is_singleton = true;
+ autoload.path = path.substr(1);
+ } else {
+ autoload.path = path;
+ }
+ add_autoload(autoload);
+ }
}
return true;
@@ -945,6 +964,29 @@ bool ProjectSettings::has_custom_feature(const String &p_feature) const {
return custom_features.has(p_feature);
}
+Map<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
+ return autoloads;
+}
+
+void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
+ ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
+ autoloads[p_autoload.name] = p_autoload;
+}
+
+void ProjectSettings::remove_autoload(const StringName &p_autoload) {
+ ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
+ autoloads.erase(p_autoload);
+}
+
+bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
+ return autoloads.has(p_autoload);
+}
+
+ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
+ ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
+ return autoloads[p_name];
+}
+
void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
diff --git a/core/project_settings.h b/core/project_settings.h
index 3ed80738a1..4aceafe3c0 100644
--- a/core/project_settings.h
+++ b/core/project_settings.h
@@ -47,6 +47,12 @@ public:
NO_BUILTIN_ORDER_BASE = 1 << 16
};
+ struct AutoloadInfo {
+ StringName name;
+ String path;
+ bool is_singleton = false;
+ };
+
protected:
struct VariantContainer {
int order = 0;
@@ -79,6 +85,8 @@ protected:
Set<String> custom_features;
Map<StringName, StringName> feature_overrides;
+ Map<StringName, AutoloadInfo> autoloads;
+
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
@@ -148,6 +156,12 @@ public:
bool has_custom_feature(const String &p_feature) const;
+ Map<StringName, AutoloadInfo> get_autoload_list() const;
+ 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;
+
ProjectSettings();
~ProjectSettings();
};