11#include " jvm_resource_format_loader.h"
22
3- #include " hash.h"
43#include " api/language/names.h"
54#include " api/script/jvm_script.h"
65#include " api/script/jvm_script_manager.h"
76#include " api/script/language/gdj_script.h"
87#include " api/script/language/java_script.h"
98#include " api/script/language/kotlin_script.h"
109#include " api/script/language/scala_script.h"
10+ #include < classes/file_access.hpp>
11+ #include < classes/resource_uid.hpp>
12+ #include " engine/utilities.h"
13+ #include " hash.h"
1114
1215using namespace godot ;
1316
14- void JvmResourceFormatLoader::get_recognized_extensions (List<String>* p_extensions) const {
15- p_extensions->push_back (GODOT_JVM_REGISTRATION_FILE_EXTENSION);
16- p_extensions->push_back (GODOT_KOTLIN_SCRIPT_EXTENSION);
17- p_extensions->push_back (GODOT_JAVA_SCRIPT_EXTENSION);
18- p_extensions->push_back (GODOT_SCALA_SCRIPT_EXTENSION);
17+ PackedStringArray JvmResourceFormatLoader::_get_recognized_extensions () const {
18+ PackedStringArray extensions;
19+ extensions.push_back (GODOT_JVM_REGISTRATION_FILE_EXTENSION);
20+ extensions.push_back (GODOT_KOTLIN_SCRIPT_EXTENSION);
21+ extensions.push_back (GODOT_JAVA_SCRIPT_EXTENSION);
22+ extensions.push_back (GODOT_SCALA_SCRIPT_EXTENSION);
23+ return extensions;
1924}
2025
21- String JvmResourceFormatLoader::get_resource_type (const String& p_path) const {
26+ String JvmResourceFormatLoader::_get_resource_type (const String& p_path) const {
2227 String ext = p_path.get_extension ().to_lower ();
2328
2429 if (ext == GODOT_JVM_REGISTRATION_FILE_EXTENSION) {
@@ -33,18 +38,18 @@ String JvmResourceFormatLoader::get_resource_type(const String& p_path) const {
3338 return " " ;
3439}
3540
36- bool JvmResourceFormatLoader::handles_type (const String & p_type) const {
37- return p_type == " Script"
38- || p_type == GODOT_JVM_SCRIPT_NAME
39- || p_type == GODOT_KOTLIN_SCRIPT_NAME
40- || p_type == GODOT_JAVA_SCRIPT_NAME
41- || p_type == GODOT_SCALA_SCRIPT_NAME;
41+ bool JvmResourceFormatLoader::_handles_type (const StringName & p_type) const {
42+ return p_type == SNAME ( " Script" )
43+ || p_type == SNAME ( GODOT_JVM_SCRIPT_NAME)
44+ || p_type == SNAME ( GODOT_KOTLIN_SCRIPT_NAME)
45+ || p_type == SNAME ( GODOT_JAVA_SCRIPT_NAME)
46+ || p_type == SNAME ( GODOT_SCALA_SCRIPT_NAME) ;
4247}
4348
4449Error JvmResourceFormatLoader::read_all_file_utf8 (const String& p_path, String& r_content) {
4550 Vector<uint8_t > source_file;
46- Error err ;
47- Ref<FileAccess> file_access { FileAccess::open (p_path, FileAccess::READ, &err)} ;
51+ Ref<FileAccess> file_access { FileAccess::open (p_path, FileAccess::READ)} ;
52+ Error err = FileAccess::get_open_error () ;
4853 JVM_ERR_FAIL_COND_V_MSG (err != OK, err, " Cannot open file '" + p_path + " '." );
4954
5055 const String source = file_access->get_as_utf8_string ();
@@ -54,7 +59,7 @@ Error JvmResourceFormatLoader::read_all_file_utf8(const String& p_path, String&
5459 return OK;
5560}
5661
57- Ref<Resource> JvmResourceFormatLoader::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) {
62+ Variant JvmResourceFormatLoader::_load (const String& p_path, const String& p_original_path, bool p_use_sub_threads, int32_t p_cache_mode) {
5863 Ref<JvmScript> jvm_script;
5964
6065 String extension = p_path.get_extension ();
@@ -72,40 +77,30 @@ Ref<Resource> JvmResourceFormatLoader::load(const String& p_path, const String&
7277 } else if (extension == GODOT_SCALA_SCRIPT_EXTENSION) {
7378 jvm_script = JvmScriptManager::get_instance ()->get_or_create_source_script <ScalaScript>(p_path, &script_is_new, r_error);
7479 } else {
75- if (r_error) { *r_error = Error::ERR_FILE_UNRECOGNIZED; }
7680 return nullptr ;
7781 }
7882
79- if (jvm_script.is_valid ()) {
8083#ifdef TOOLS_ENABLED
81- if (!script_is_new && is_source) {
82- MessageQueue::get_singleton ()->push_callable (
83- callable_mp (JvmScriptManager::get_instance (), &JvmScriptManager::invalidate_source).bind (Ref<SourceScript>(jvm_script))
84- );
85- }
86- #endif
87- } else {
88- if (r_error) { *r_error = Error::ERR_UNAVAILABLE; }
84+ if (jvm_script.is_valid () && !script_is_new && is_source) {
85+ callable_mp (JvmScriptManager::get_instance (), &JvmScriptManager::invalidate_source).bind (Ref<SourceScript>(jvm_script))
86+ .call_deferred ();
8987 }
88+ #endif
9089
9190 return jvm_script;
9291}
9392
94- ResourceUID::ID JvmResourceFormatLoader::get_resource_uid (const String& p_path) const {
93+ int64_t JvmResourceFormatLoader::_get_resource_uid (const String& p_path) const {
9594 String extension = p_path.get_extension ();
96- ResourceUID::ID id = ResourceUID::INVALID_ID;
95+ int64_t id = ResourceUID::INVALID_ID;
9796 if (extension == GODOT_JVM_REGISTRATION_FILE_EXTENSION) {
98- id = (JvmScript::get_script_file_name (p_path) + UUID_HASH_SEED). hash64 ( );
97+ id = (int64_t ) hash64 ( JvmScript::get_script_file_name (p_path) + UUID_HASH_SEED);
9998 id &= 0x7FFFFFFFFFFFFFFF ;
10099 } else if (extension == GODOT_KOTLIN_SCRIPT_EXTENSION || extension == GODOT_JAVA_SCRIPT_EXTENSION || extension == GODOT_SCALA_SCRIPT_EXTENSION) {
101100 String source;
102101 Error error;
103- id = (String (SourceScript::parse_source_to_fqdn (p_path, source, &error)) + UUID_HASH_SEED). hash64 ( );
102+ id = (int64_t ) hash64 ( String (SourceScript::parse_source_to_fqdn (p_path, source, &error)) + UUID_HASH_SEED);
104103 id &= 0x7FFFFFFFFFFFFFFF ;
105104 }
106105 return id;
107- }
108-
109- bool JvmResourceFormatLoader::has_custom_uid_support () const {
110- return true ;
111- }
106+ }
0 commit comments