1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Move global script class cache to separate file

This commit is contained in:
kobewi
2022-12-25 15:08:32 +01:00
parent 0f0b853c98
commit 6444c7d127
6 changed files with 76 additions and 32 deletions

View File

@@ -186,6 +186,7 @@ void ScriptServer::unregister_language(const ScriptLanguage *p_language) {
void ScriptServer::init_languages() {
{ // Load global classes.
global_classes_clear();
#ifndef DISABLE_DEPRECATED
if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) {
Array script_classes = GLOBAL_GET("_global_script_classes");
@@ -196,6 +197,17 @@ void ScriptServer::init_languages() {
}
add_global_class(c["class"], c["base"], c["language"], c["path"]);
}
ProjectSettings::get_singleton()->clear("_global_script_classes");
}
#endif
Array script_classes = ProjectSettings::get_singleton()->get_global_class_list();
for (int i = 0; i < script_classes.size(); i++) {
Dictionary c = script_classes[i];
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
continue;
}
add_global_class(c["class"], c["base"], c["language"], c["path"]);
}
}
@@ -291,6 +303,17 @@ void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
}
void ScriptServer::save_global_classes() {
Dictionary class_icons;
Array script_classes = ProjectSettings::get_singleton()->get_global_class_list();
for (int i = 0; i < script_classes.size(); i++) {
Dictionary d = script_classes[i];
if (!d.has("name") || !d.has("icon")) {
continue;
}
class_icons[d["name"]] = d["icon"];
}
List<StringName> gc;
get_global_class_list(&gc);
Array gcarr;
@@ -300,25 +323,10 @@ void ScriptServer::save_global_classes() {
d["language"] = global_classes[E].language;
d["path"] = global_classes[E].path;
d["base"] = global_classes[E].base;
d["icon"] = class_icons.get(E, "");
gcarr.push_back(d);
}
Array old;
if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) {
old = GLOBAL_GET("_global_script_classes");
}
if ((!old.is_empty() || gcarr.is_empty()) && gcarr.hash() == old.hash()) {
return;
}
if (gcarr.is_empty()) {
if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) {
ProjectSettings::get_singleton()->clear("_global_script_classes");
}
} else {
ProjectSettings::get_singleton()->set("_global_script_classes", gcarr);
}
ProjectSettings::get_singleton()->save();
ProjectSettings::get_singleton()->store_global_class_list(gcarr);
}
////////////////////