Merge pull request #58920 from timothyqiu/autoload-cap

This commit is contained in:
Rémi Verschelde 2022-03-09 09:20:34 +01:00 committed by GitHub
commit 70c5e7b0b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 30 deletions

View file

@ -52,7 +52,7 @@ void EditorAutoloadSettings::_notification(int p_what) {
file_dialog->add_filter("*." + E); file_dialog->add_filter("*." + E);
} }
for (const AutoLoadInfo &info : autoload_cache) { for (const AutoloadInfo &info : autoload_cache) {
if (info.node && info.in_editor) { if (info.node && info.in_editor) {
get_tree()->get_root()->call_deferred(SNAME("add_child"), info.node); get_tree()->get_root()->call_deferred(SNAME("add_child"), info.node);
} }
@ -122,7 +122,7 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
for (const String &E : keywords) { for (const String &E : keywords) {
if (E == p_name) { if (E == p_name) {
if (r_error) { if (r_error) {
*r_error = TTR("Invalid name.") + " " + TTR("Keyword cannot be used as an AutoLoad name."); *r_error = TTR("Invalid name.") + " " + TTR("Keyword cannot be used as an Autoload name.");
} }
return false; return false;
@ -227,7 +227,7 @@ void EditorAutoloadSettings::_autoload_edited() {
path = "*" + path; path = "*" + path;
} }
undo_redo->create_action(TTR("Toggle AutoLoad Globals")); undo_redo->create_action(TTR("Toggle Autoload Globals"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), base, path); undo_redo->add_do_property(ProjectSettings::get_singleton(), base, path);
undo_redo->add_undo_property(ProjectSettings::get_singleton(), base, ProjectSettings::get_singleton()->get(base)); undo_redo->add_undo_property(ProjectSettings::get_singleton(), base, ProjectSettings::get_singleton()->get(base));
@ -378,13 +378,13 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
Object *obj = ClassDB::instantiate(ibt); Object *obj = ClassDB::instantiate(ibt);
ERR_FAIL_COND_V_MSG(!obj, nullptr, "Cannot instance script for AutoLoad, expected 'Node' inheritance, got: " + String(ibt) + "."); ERR_FAIL_COND_V_MSG(!obj, nullptr, "Cannot instance script for Autoload, expected 'Node' inheritance, got: " + String(ibt) + ".");
n = Object::cast_to<Node>(obj); n = Object::cast_to<Node>(obj);
n->set_script(script); n->set_script(script);
} }
ERR_FAIL_COND_V_MSG(!n, nullptr, "Path in AutoLoad not a node or script: " + p_path + "."); ERR_FAIL_COND_V_MSG(!n, nullptr, "Path in Autoload not a node or script: " + p_path + ".");
return n; return n;
} }
@ -396,10 +396,10 @@ void EditorAutoloadSettings::update_autoload() {
updating_autoload = true; updating_autoload = true;
Map<String, AutoLoadInfo> to_remove; Map<String, AutoloadInfo> to_remove;
List<AutoLoadInfo *> to_add; List<AutoloadInfo *> to_add;
for (const AutoLoadInfo &info : autoload_cache) { for (const AutoloadInfo &info : autoload_cache) {
to_remove.insert(info.name, info); to_remove.insert(info.name, info);
} }
@ -423,7 +423,7 @@ void EditorAutoloadSettings::update_autoload() {
continue; continue;
} }
AutoLoadInfo info; AutoloadInfo info;
info.is_singleton = path.begins_with("*"); info.is_singleton = path.begins_with("*");
if (info.is_singleton) { if (info.is_singleton) {
@ -436,7 +436,7 @@ void EditorAutoloadSettings::update_autoload() {
bool need_to_add = true; bool need_to_add = true;
if (to_remove.has(name)) { if (to_remove.has(name)) {
AutoLoadInfo &old_info = to_remove[name]; AutoloadInfo &old_info = to_remove[name];
if (old_info.path == info.path) { if (old_info.path == info.path) {
// Still the same resource, check status // Still the same resource, check status
info.node = old_info.node; info.node = old_info.node;
@ -478,8 +478,8 @@ void EditorAutoloadSettings::update_autoload() {
} }
// Remove deleted/changed autoloads // Remove deleted/changed autoloads
for (KeyValue<String, AutoLoadInfo> &E : to_remove) { for (KeyValue<String, AutoloadInfo> &E : to_remove) {
AutoLoadInfo &info = E.value; AutoloadInfo &info = E.value;
if (info.is_singleton) { if (info.is_singleton) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) { for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->remove_named_global_constant(info.name); ScriptServer::get_language(i)->remove_named_global_constant(info.name);
@ -500,7 +500,7 @@ void EditorAutoloadSettings::update_autoload() {
// Load new/changed autoloads // Load new/changed autoloads
List<Node *> nodes_to_add; List<Node *> nodes_to_add;
for (AutoLoadInfo *info : to_add) { for (AutoloadInfo *info : to_add) {
info->node = _create_autoload(info->path); info->node = _create_autoload(info->path);
ERR_CONTINUE(!info->node); ERR_CONTINUE(!info->node);
@ -632,8 +632,8 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
int order = ProjectSettings::get_singleton()->get_order("autoload/" + name); int order = ProjectSettings::get_singleton()->get_order("autoload/" + name);
AutoLoadInfo aux; AutoloadInfo aux;
List<AutoLoadInfo>::Element *E = nullptr; List<AutoloadInfo>::Element *E = nullptr;
if (!move_to_back) { if (!move_to_back) {
aux.order = order; aux.order = order;
@ -649,7 +649,7 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
for (int i = 0; i < autoloads.size(); i++) { for (int i = 0; i < autoloads.size(); i++) {
aux.order = ProjectSettings::get_singleton()->get_order("autoload/" + autoloads[i]); aux.order = ProjectSettings::get_singleton()->get_order("autoload/" + autoloads[i]);
List<AutoLoadInfo>::Element *I = autoload_cache.find(aux); List<AutoloadInfo>::Element *I = autoload_cache.find(aux);
if (move_to_back) { if (move_to_back) {
autoload_cache.move_to_back(I); autoload_cache.move_to_back(I);
@ -664,7 +664,7 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
int i = 0; int i = 0;
for (const AutoLoadInfo &F : autoload_cache) { for (const AutoloadInfo &F : autoload_cache) {
orders.write[i++] = F.order; orders.write[i++] = F.order;
} }
@ -676,7 +676,7 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &
i = 0; i = 0;
for (const AutoLoadInfo &F : autoload_cache) { for (const AutoloadInfo &F : autoload_cache) {
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, orders[i++]); undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, orders[i++]);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, F.order); undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, F.order);
} }
@ -697,18 +697,18 @@ bool EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_
String error; String error;
if (!_autoload_name_is_valid(name, &error)) { if (!_autoload_name_is_valid(name, &error)) {
EditorNode::get_singleton()->show_warning(TTR("Can't add AutoLoad:") + "\n" + error); EditorNode::get_singleton()->show_warning(TTR("Can't add Autoload:") + "\n" + error);
return false; return false;
} }
const String &path = p_path; const String &path = p_path;
if (!FileAccess::exists(path)) { if (!FileAccess::exists(path)) {
EditorNode::get_singleton()->show_warning(TTR("Can't add AutoLoad:") + "\n" + vformat(TTR("%s is an invalid path. File does not exist."), path)); EditorNode::get_singleton()->show_warning(TTR("Can't add Autoload:") + "\n" + vformat(TTR("%s is an invalid path. File does not exist."), path));
return false; return false;
} }
if (!path.begins_with("res://")) { if (!path.begins_with("res://")) {
EditorNode::get_singleton()->show_warning(TTR("Can't add AutoLoad:") + "\n" + vformat(TTR("%s is an invalid path. Not in resource path (res://)."), path)); EditorNode::get_singleton()->show_warning(TTR("Can't add Autoload:") + "\n" + vformat(TTR("%s is an invalid path. Not in resource path (res://)."), path));
return false; return false;
} }
@ -716,7 +716,7 @@ bool EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_
UndoRedo *undo_redo = EditorNode::get_undo_redo(); UndoRedo *undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Add AutoLoad")); undo_redo->create_action(TTR("Add Autoload"));
// Singleton autoloads are represented with a leading "*" in their path. // Singleton autoloads are represented with a leading "*" in their path.
undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path); undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path);
@ -791,7 +791,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
continue; continue;
} }
AutoLoadInfo info; AutoloadInfo info;
info.is_singleton = path.begins_with("*"); info.is_singleton = path.begins_with("*");
if (info.is_singleton) { if (info.is_singleton) {
@ -812,7 +812,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
autoload_cache.push_back(info); autoload_cache.push_back(info);
} }
for (AutoLoadInfo &info : autoload_cache) { for (AutoloadInfo &info : autoload_cache) {
info.node = _create_autoload(info.path); info.node = _create_autoload(info.path);
if (info.node) { if (info.node) {
@ -921,7 +921,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
} }
EditorAutoloadSettings::~EditorAutoloadSettings() { EditorAutoloadSettings::~EditorAutoloadSettings() {
for (const AutoLoadInfo &info : autoload_cache) { for (const AutoloadInfo &info : autoload_cache) {
if (info.node && !info.in_editor) { if (info.node && !info.in_editor) {
memdelete(info.node); memdelete(info.node);
} }

View file

@ -49,7 +49,7 @@ class EditorAutoloadSettings : public VBoxContainer {
String autoload_changed; String autoload_changed;
struct AutoLoadInfo { struct AutoloadInfo {
String name; String name;
String path; String path;
bool is_singleton = false; bool is_singleton = false;
@ -57,12 +57,12 @@ class EditorAutoloadSettings : public VBoxContainer {
int order = 0; int order = 0;
Node *node = nullptr; Node *node = nullptr;
bool operator==(const AutoLoadInfo &p_info) const { bool operator==(const AutoloadInfo &p_info) const {
return order == p_info.order; return order == p_info.order;
} }
}; };
List<AutoLoadInfo> autoload_cache; List<AutoloadInfo> autoload_cache;
bool updating_autoload; bool updating_autoload;
int number_of_autoloads; int number_of_autoloads;

View file

@ -663,7 +663,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
tab_container->add_child(localization_editor); tab_container->add_child(localization_editor);
autoload_settings = memnew(EditorAutoloadSettings); autoload_settings = memnew(EditorAutoloadSettings);
autoload_settings->set_name(TTR("AutoLoad")); autoload_settings->set_name(TTR("Autoload"));
autoload_settings->connect("autoload_changed", callable_mp(this, &ProjectSettingsEditor::queue_save)); autoload_settings->connect("autoload_changed", callable_mp(this, &ProjectSettingsEditor::queue_save));
tab_container->add_child(autoload_settings); tab_container->add_child(autoload_settings);

View file

@ -120,7 +120,7 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr
} break; } break;
case CompletionKind::NODE_PATHS: { case CompletionKind::NODE_PATHS: {
{ {
// AutoLoads // Autoloads.
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) { for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {