diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index ed0d4916793..d2aad1d63a8 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -196,19 +196,19 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p else local_path = ProjectSettings::get_singleton()->localize_path(p_path); + if (!p_no_cache && ResourceCache::has(local_path)) { + + if (OS::get_singleton()->is_stdout_verbose()) + print_line("load resource: " + local_path + " (cached)"); + + return RES(ResourceCache::get(local_path)); + } + bool xl_remapped = false; String path = _path_remap(local_path, &xl_remapped); ERR_FAIL_COND_V(path == "", RES()); - if (!p_no_cache && ResourceCache::has(path)) { - - if (OS::get_singleton()->is_stdout_verbose()) - print_line("load resource: " + path + " (cached)"); - - return RES(ResourceCache::get(path)); - } - if (OS::get_singleton()->is_stdout_verbose()) print_line("load resource: " + path); @@ -247,23 +247,23 @@ Ref ResourceLoader::load_interactive(const String &p_ else local_path = ProjectSettings::get_singleton()->localize_path(p_path); - bool xl_remapped = false; - String path = _path_remap(local_path, &xl_remapped); - - ERR_FAIL_COND_V(path == "", Ref()); - - if (!p_no_cache && ResourceCache::has(path)) { + if (!p_no_cache && ResourceCache::has(local_path)) { if (OS::get_singleton()->is_stdout_verbose()) - print_line("load resource: " + path + " (cached)"); + print_line("load resource: " + local_path + " (cached)"); - Ref res_cached = ResourceCache::get(path); + Ref res_cached = ResourceCache::get(local_path); Ref ril = Ref(memnew(ResourceInteractiveLoaderDefault)); ril->resource = res_cached; return ril; } + bool xl_remapped = false; + String path = _path_remap(local_path, &xl_remapped); + + ERR_FAIL_COND_V(path == "", Ref()); + if (OS::get_singleton()->is_stdout_verbose()) print_line("load resource: "); @@ -426,9 +426,11 @@ String ResourceLoader::get_resource_type(const String &p_path) { String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) { - if (translation_remaps.has(p_path)) { + String new_path = p_path; - Vector &v = *translation_remaps.getptr(p_path); + if (translation_remaps.has(new_path)) { + + Vector &v = *translation_remaps.getptr(new_path); String locale = TranslationServer::get_singleton()->get_locale(); if (r_translation_remapped) { *r_translation_remapped = true; @@ -443,12 +445,16 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem continue; if (l.begins_with(locale)) { - return v[i].left(split); + new_path = v[i].left(split); + break; } } } - return p_path; + if (path_remaps.has(new_path)) { + new_path = path_remaps[new_path]; + } + return new_path; } String ResourceLoader::import_remap(const String &p_path) { @@ -515,6 +521,27 @@ void ResourceLoader::clear_translation_remaps() { translation_remaps.clear(); } +void ResourceLoader::load_path_remaps() { + + if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) + return; + + PoolVector remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths"); + int rc = remaps.size(); + ERR_FAIL_COND(rc & 1); //must be even + PoolVector::Read r = remaps.read(); + + for (int i = 0; i < rc; i += 2) { + + path_remaps[r[i]] = r[i + 1]; + } +} + +void ResourceLoader::clear_path_remaps() { + + path_remaps.clear(); +} + ResourceLoadErrorNotify ResourceLoader::err_notify = NULL; void *ResourceLoader::err_notify_ud = NULL; @@ -526,3 +553,4 @@ bool ResourceLoader::timestamp_on_load = false; SelfList::List ResourceLoader::remapped_list; HashMap > ResourceLoader::translation_remaps; +HashMap ResourceLoader::path_remaps; diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 5deffbca1a5..05f01d8d312 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -91,6 +91,7 @@ class ResourceLoader { static DependencyErrorNotify dep_err_notify; static bool abort_on_missing_resource; static HashMap > translation_remaps; + static HashMap path_remaps; static String _path_remap(const String &p_path, bool *r_translation_remapped = NULL); friend class Resource; @@ -137,6 +138,9 @@ public: static String path_remap(const String &p_path); static String import_remap(const String &p_path); + static void load_path_remaps(); + static void clear_path_remaps(); + static void reload_translation_remaps(); static void load_translation_remaps(); static void clear_translation_remaps(); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index d0d13fdbcff..91767d55b11 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4708,6 +4708,7 @@ EditorNode::EditorNode() { EditorHelp::generate_doc(); //before any editor classes are crated SceneState::set_disable_placeholders(true); ResourceLoader::clear_translation_remaps(); //no remaps using during editor + ResourceLoader::clear_path_remaps(); editor_initialize_certificates(); //for asset sharing InputDefault *id = Object::cast_to(Input::get_singleton()); diff --git a/main/main.cpp b/main/main.cpp index 1328807121c..c6e20f6d3b8 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1136,6 +1136,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) { translation_server->load_translations(); ResourceLoader::load_translation_remaps(); //load remaps for resources + ResourceLoader::load_path_remaps(); + audio_server->load_default_bus_layout(); if (use_debug_profiler && script_debugger) { @@ -1816,6 +1818,9 @@ void Main::cleanup() { OS::get_singleton()->_execpath = ""; OS::get_singleton()->_local_clipboard = ""; + ResourceLoader::clear_translation_remaps(); + ResourceLoader::clear_path_remaps(); + ScriptServer::finish_languages(); #ifdef TOOLS_ENABLED diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 1e007ddb0fb..e707032ed85 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -30,6 +30,7 @@ #include "register_types.h" #include "gdscript.h" +#include "gdscript_tokenizer.h" #include "io/file_access_encrypted.h" #include "io/resource_loader.h" #include "os/file_access.h" @@ -38,6 +39,45 @@ GDScriptLanguage *script_language_gd = NULL; ResourceFormatLoaderGDScript *resource_loader_gd = NULL; ResourceFormatSaverGDScript *resource_saver_gd = NULL; +#ifdef TOOLS_ENABLED + +#include "editor/editor_export.h" +#include "editor/editor_node.h" +#include "editor/editor_settings.h" + +class EditorExportGDScript : public EditorExportPlugin { + + GDCLASS(EditorExportGDScript, EditorExportPlugin); + +public: + virtual void _export_file(const String &p_path, const String &p_type, const Set &p_features) { + + if (!p_path.ends_with(".gd")) + return; + + Vector file = FileAccess::get_file_as_array(p_path); + if (file.empty()) + return; + String txt; + txt.parse_utf8((const char *)file.ptr(), file.size()); + file = GDScriptTokenizerBuffer::parse_code_string(txt); + + if (file.empty()) + return; + + add_file(p_path.get_basename() + ".gdc", file, true); + } +}; + +static void _editor_init() { + + Ref gd_export; + gd_export.instance(); + EditorExport::get_singleton()->add_export_plugin(gd_export); +} + +#endif + void register_gdscript_types() { ClassDB::register_class(); @@ -49,6 +89,10 @@ void register_gdscript_types() { ResourceLoader::add_resource_format_loader(resource_loader_gd); resource_saver_gd = memnew(ResourceFormatSaverGDScript); ResourceSaver::add_resource_format_saver(resource_saver_gd); + +#ifdef TOOLS_ENABLED + EditorNode::add_init_callback(_editor_init); +#endif } void unregister_gdscript_types() {