| 2032 | } |
| 2033 | |
| 2034 | int EditorNode::_save_external_resources(bool p_also_save_external_data) { |
| 2035 | int flg = 0; |
| 2036 | if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) { |
| 2037 | flg |= ResourceSaver::FLAG_COMPRESS; |
| 2038 | } |
| 2039 | flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; |
| 2040 | |
| 2041 | HashSet<String> edited_resources; |
| 2042 | int saved = 0; |
| 2043 | List<Ref<Resource>> cached; |
| 2044 | ResourceCache::get_cached_resources(&cached); |
| 2045 | |
| 2046 | for (Ref<Resource> res : cached) { |
| 2047 | if (!res->is_edited()) { |
| 2048 | continue; |
| 2049 | } |
| 2050 | |
| 2051 | String path = res->get_path(); |
| 2052 | if (path.begins_with("res://")) { |
| 2053 | int subres_pos = path.find("::"); |
| 2054 | if (subres_pos == -1) { |
| 2055 | // Actual resource. |
| 2056 | edited_resources.insert(path); |
| 2057 | } else { |
| 2058 | edited_resources.insert(path.substr(0, subres_pos)); |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | res->set_edited(false); |
| 2063 | } |
| 2064 | |
| 2065 | bool script_was_saved = false; |
| 2066 | for (const String &E : edited_resources) { |
| 2067 | Ref<Resource> res = ResourceCache::get_ref(E); |
| 2068 | if (res.is_null()) { |
| 2069 | continue; // Maybe it was erased in a thread, who knows. |
| 2070 | } |
| 2071 | Ref<PackedScene> ps = res; |
| 2072 | if (ps.is_valid()) { |
| 2073 | continue; // Do not save PackedScenes, this will mess up the editor. |
| 2074 | } |
| 2075 | if (!script_was_saved) { |
| 2076 | Ref<Script> scr = res; |
| 2077 | script_was_saved = scr.is_valid(); |
| 2078 | } |
| 2079 | ResourceSaver::save(res, res->get_path(), flg); |
| 2080 | saved++; |
| 2081 | } |
| 2082 | |
| 2083 | if (script_was_saved) { |
| 2084 | ScriptEditor::get_singleton()->update_script_times(); |
| 2085 | } |
| 2086 | |
| 2087 | if (p_also_save_external_data) { |
| 2088 | for (int i = 0; i < editor_data.get_editor_plugin_count(); i++) { |
| 2089 | EditorPlugin *plugin = editor_data.get_editor_plugin(i); |
| 2090 | if (!plugin->get_unsaved_status().is_empty()) { |
| 2091 | plugin->save_external_data(); |
nothing calls this directly
no test coverage detected