Skip to content

Commit

Permalink
Merge pull request #72445 from reduz/restore-script-class-cache-if-re…
Browse files Browse the repository at this point in the history
…moved

Restore script class cache if removed
  • Loading branch information
akien-mga committed Jan 31, 2023
2 parents e768e02 + 79897dd commit e1648b3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ Array ProjectSettings::get_global_class_list() {

Ref<ConfigFile> cf;
cf.instantiate();
if (cf->load(get_project_data_path().path_join("global_script_class_cache.cfg")) == OK) {
if (cf->load(get_global_class_list_path()) == OK) {
script_classes = cf->get_value("", "list");
} else {
#ifndef TOOLS_ENABLED
Expand All @@ -1148,11 +1148,15 @@ Array ProjectSettings::get_global_class_list() {
return script_classes;
}

String ProjectSettings::get_global_class_list_path() const {
return get_project_data_path().path_join("global_script_class_cache.cfg");
}

void ProjectSettings::store_global_class_list(const Array &p_classes) {
Ref<ConfigFile> cf;
cf.instantiate();
cf->set_value("", "list", p_classes);
cf->save(get_project_data_path().path_join("global_script_class_cache.cfg"));
cf->save(get_global_class_list_path());
}

bool ProjectSettings::has_custom_feature(const String &p_feature) const {
Expand Down
1 change: 1 addition & 0 deletions core/config/project_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class ProjectSettings : public Object {
Variant get_setting(const String &p_setting, const Variant &p_default_value = Variant()) const;
Array get_global_class_list();
void store_global_class_list(const Array &p_classes);
String get_global_class_list_path() const;

bool has_setting(String p_var) const;
String localize_path(const String &p_path) const;
Expand Down
8 changes: 8 additions & 0 deletions core/object/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ void ScriptServer::save_global_classes() {
ProjectSettings::get_singleton()->store_global_class_list(gcarr);
}

bool ScriptServer::has_global_classes() {
return !global_classes.is_empty();
}

String ScriptServer::get_global_class_cache_file_path() {
return ProjectSettings::get_singleton()->get_global_class_list_path();
}

////////////////////

Variant ScriptInstance::call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
Expand Down
2 changes: 2 additions & 0 deletions core/object/script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class ScriptServer {
static void get_global_class_list(List<StringName> *r_global_classes);
static void get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes);
static void save_global_classes();
static bool has_global_classes();
static String get_global_class_cache_file_path();

static void init_languages();
static void finish_languages();
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,11 @@ void EditorFileSystem::_update_script_classes() {
void EditorFileSystem::_update_pending_script_classes() {
if (!update_script_paths.is_empty()) {
_update_script_classes();
} else {
// In case the class cache file was removed somehow, regenerate it.
if (ScriptServer::has_global_classes() && !FileAccess::exists(ScriptServer::get_global_class_cache_file_path())) {
ScriptServer::save_global_classes();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
HashSet<String> paths;
Vector<String> path_remaps;

paths.insert(ProjectSettings::get_singleton()->get_project_data_path().path_join("global_script_class_cache.cfg"));
paths.insert(ProjectSettings::get_singleton()->get_global_class_list_path());
if (p_preset->get_export_filter() == EditorExportPreset::EXPORT_ALL_RESOURCES) {
//find stuff
_export_find_resources(EditorFileSystem::get_singleton()->get_filesystem(), paths);
Expand Down

0 comments on commit e1648b3

Please sign in to comment.