MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / load

Method load

modules/mono/csharp_script.cpp:2822–2879  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2820/*************** RESOURCE ***************/
2821
2822Ref<Resource> ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
2823 if (r_error) {
2824 *r_error = ERR_FILE_CANT_OPEN;
2825 }
2826
2827 /// @todo Ignore anything inside bin/ and obj/ in tools builds?
2828
2829 String real_path = p_path;
2830 if (p_path.begins_with("csharp://")) {
2831 // This is a virtual path used by generic types, extract the real path.
2832 real_path = "res://" + p_path.trim_prefix("csharp://");
2833 real_path = real_path.substr(0, real_path.rfind_char(':'));
2834 }
2835
2836 Ref<CSharpScript> scr;
2837
2838 if (GDMonoCache::godot_api_cache_updated) {
2839 GDMonoCache::managed_callbacks.ScriptManagerBridge_GetOrCreateScriptBridgeForPath(&p_path, &scr);
2840 ERR_FAIL_COND_V_MSG(scr.is_null(), Ref<Resource>(), "Could not create C# script '" + real_path + "'.");
2841 } else {
2842 scr.instantiate();
2843 }
2844
2845#ifdef DEBUG_ENABLED
2846 Error err = scr->load_source_code(real_path);
2847 ERR_FAIL_COND_V_MSG(err != OK, Ref<Resource>(), "Cannot load C# script file '" + real_path + "'.");
2848#endif // DEBUG_ENABLED
2849
2850 // Only one instance of a C# script is allowed to exist.
2851 ERR_FAIL_COND_V_MSG(!scr->get_path().is_empty() && scr->get_path() != p_original_path, Ref<Resource>(),
2852 "The C# script path is different from the path it was registered in the C# dictionary.");
2853
2854 Ref<Resource> existing = ResourceCache::get_ref(p_path);
2855 switch (p_cache_mode) {
2856 case ResourceFormatLoader::CACHE_MODE_IGNORE:
2857 case ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP:
2858 break;
2859 case ResourceFormatLoader::CACHE_MODE_REUSE:
2860 if (existing.is_null()) {
2861 scr->set_path(p_original_path);
2862 } else {
2863 scr = existing;
2864 }
2865 break;
2866 case ResourceFormatLoader::CACHE_MODE_REPLACE:
2867 case ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP:
2868 scr->set_path(p_original_path, true);
2869 break;
2870 }
2871
2872 scr->reload();
2873
2874 if (r_error) {
2875 *r_error = OK;
2876 }
2877
2878 return scr;
2879}

Callers

nothing calls this directly

Calls 11

begins_withMethod · 0.80
trim_prefixMethod · 0.80
substrMethod · 0.80
rfind_charMethod · 0.80
is_nullMethod · 0.45
instantiateMethod · 0.45
load_source_codeMethod · 0.45
is_emptyMethod · 0.45
get_pathMethod · 0.45
set_pathMethod · 0.45
reloadMethod · 0.45

Tested by

no test coverage detected