MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / _load

Method _load

utility/import_info.cpp:532–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

530}
531
532Error ImportInfoModern::_load(const String &p_path) {
533 cf.instantiate();
534 String path = p_path;
535 path = GDRESettings::get_singleton()->localize_path(p_path);
536 Error err = cf->load(path);
537 if (err) {
538 cf = Ref<ConfigFileCompat>();
539 }
540 ERR_FAIL_COND_V_MSG(err != OK, err, "Could not load " + path);
541 import_md_path = path;
542 preferred_import_path = cf->get_value("remap", "path", "");
543
544 Vector<String> dest_files;
545
546 // Godot 4.x started stripping the deps section from the .import file, need to recreate it
547 if (!cf->has_section("deps")) {
548 dirty = true;
549 // the source file is the import_md path minus ".import"
550 String source_file = import_md_path.get_basename();
551 if (!preferred_import_path.is_empty()) {
552 set_source_file(source_file);
553 cf->set_value("deps", "dest_files", vec_to_array({ preferred_import_path }));
554 } else {
555 // this is a multi-path import, get all the "path.*" key values
556 dest_files = get_remap_paths(cf);
557 // No path values at all; may be a translation file
558 if (dest_files.is_empty()) {
559 String importer = cf->get_value("remap", "importer", "");
560 if (importer == "csv_translation") {
561 // They recently started removing the path from the [remap] section for these types
562 String prefix = source_file.get_basename();
563 if (dest_files.size() == 0) {
564 dest_files = Glob::glob(prefix + ".*.translation");
565 }
566 // The reason for doing this is because the editor expects the files in the [deps]
567 // section to be in the same order as the project settings, otherwise it will force a re-import
568 PackedStringArray translation_files = GDRESettings::get_singleton()->get_project_setting("internationalization/locale/translations", PackedStringArray());
569 Vector<String> translation_files_set;
570 for (auto &file : translation_files) {
571 if (dest_files.has(file)) {
572 translation_files_set.push_back(file);
573 }
574 }
575 if (dest_files.size() == translation_files_set.size()) {
576 dest_files = translation_files_set;
577 } else {
578 // otherwise, just move the fallback locale to the front.
579 String fallback_locale = GDRESettings::get_singleton()->get_project_setting("internationalization/locale/fallback", "en");
580 String suffix = fallback_locale.to_lower() + ".translation";
581 for (int i = 0; i < dest_files.size(); i++) {
582 if (dest_files[i].ends_with(suffix)) {
583 String first_file = dest_files[i];
584 dest_files.remove_at(i);
585 dest_files.insert(0, first_file);
586 break;
587 }
588 }
589 }

Callers 2

load_from_fileMethod · 0.45
create_dummyMethod · 0.45

Calls 15

vec_to_arrayFunction · 0.85
get_remap_pathsFunction · 0.85
hashset_to_arrayFunction · 0.85
vector_to_hashsetFunction · 0.85
localize_pathMethod · 0.80
has_sectionMethod · 0.80
get_project_settingMethod · 0.80
push_backMethod · 0.80
get_section_keysMethod · 0.80
get_source_countMethod · 0.80
get_editorMethod · 0.80

Tested by

no test coverage detected