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,22 +38,22 @@ 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 uint64_t len = file_access->get_length ();
51- source_file.resize (len + 1 );
56+ source_file.resize (( int64_t ) len + 1 );
5257 uint8_t * w = source_file.ptrw ();
5358 uint64_t r = file_access->get_buffer (w, len);
5459 ERR_FAIL_COND_V (r != len, ERR_CANT_OPEN);
@@ -61,7 +66,7 @@ Error JvmResourceFormatLoader::read_all_file_utf8(const String& p_path, String&
6166 return OK;
6267}
6368
64- 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) {
69+ Variant JvmResourceFormatLoader::_load (const String& p_path, const String& p_original_path, bool p_use_sub_threads, int32_t p_cache_mode) {
6570 Ref<JvmScript> jvm_script;
6671
6772 String extension = p_path.get_extension ();
@@ -79,40 +84,30 @@ Ref<Resource> JvmResourceFormatLoader::load(const String& p_path, const String&
7984 } else if (extension == GODOT_SCALA_SCRIPT_EXTENSION) {
8085 jvm_script = JvmScriptManager::get_instance ()->get_or_create_source_script <ScalaScript>(p_path, &script_is_new, r_error);
8186 } else {
82- if (r_error) { *r_error = Error::ERR_FILE_UNRECOGNIZED; }
8387 return nullptr ;
8488 }
8589
86- if (jvm_script.is_valid ()) {
8790#ifdef TOOLS_ENABLED
88- if (!script_is_new && is_source) {
89- MessageQueue::get_singleton ()->push_callable (
90- callable_mp (JvmScriptManager::get_instance (), &JvmScriptManager::invalidate_source).bind (Ref<SourceScript>(jvm_script))
91- );
92- }
93- #endif
94- } else {
95- if (r_error) { *r_error = Error::ERR_UNAVAILABLE; }
91+ if (jvm_script.is_valid () && !script_is_new && is_source) {
92+ callable_mp (JvmScriptManager::get_instance (), &JvmScriptManager::invalidate_source).bind (Ref<SourceScript>(jvm_script))
93+ .call_deferred ();
9694 }
95+ #endif
9796
9897 return jvm_script;
9998}
10099
101- ResourceUID::ID JvmResourceFormatLoader::get_resource_uid (const String& p_path) const {
100+ int64_t JvmResourceFormatLoader::_get_resource_uid (const String& p_path) const {
102101 String extension = p_path.get_extension ();
103- ResourceUID::ID id = ResourceUID::INVALID_ID;
102+ int64_t id = ResourceUID::INVALID_ID;
104103 if (extension == GODOT_JVM_REGISTRATION_FILE_EXTENSION) {
105- id = (JvmScript::get_script_file_name (p_path) + UUID_HASH_SEED). hash64 ( );
104+ id = (int64_t ) hash64 ( JvmScript::get_script_file_name (p_path) + UUID_HASH_SEED);
106105 id &= 0x7FFFFFFFFFFFFFFF ;
107106 } else if (extension == GODOT_KOTLIN_SCRIPT_EXTENSION || extension == GODOT_JAVA_SCRIPT_EXTENSION || extension == GODOT_SCALA_SCRIPT_EXTENSION) {
108107 String source;
109108 Error error;
110- id = (String (SourceScript::parse_source_to_fqdn (p_path, source, &error)) + UUID_HASH_SEED). hash64 ( );
109+ id = (int64_t ) hash64 ( String (SourceScript::parse_source_to_fqdn (p_path, source, &error)) + UUID_HASH_SEED);
111110 id &= 0x7FFFFFFFFFFFFFFF ;
112111 }
113112 return id;
114- }
115-
116- bool JvmResourceFormatLoader::has_custom_uid_support () const {
117- return true ;
118- }
113+ }
0 commit comments