@@ -12,6 +12,7 @@ var hashmap := {}
12
12
func _get_name () -> String :
13
13
return "Godot Mod Loader Export Plugin"
14
14
15
+
15
16
func _export_begin (features : PackedStringArray , is_debug : bool , path : String , flags : int ) -> void :
16
17
hashmap .clear ()
17
18
regex_getter_setter = RegEx .new ()
@@ -31,20 +32,12 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
31
32
32
33
# we need to stop all vanilla methods from forming inheritance chains
33
34
# since the generated methods will fulfill inheritance requirements
34
- var class_prefix = str (hash (path ))
35
+ var class_prefix : = str (hash (path ))
35
36
var method_store : Array [String ] = []
36
37
var mod_loader_hooks_start_string := """
37
38
# ModLoader Hooks - The following code has been automatically added by the Godot Mod Loader export plugin.
38
39
"""
39
40
40
- # print("--------------------Property List")
41
- # print(JSON.stringify(current_script.get_script_property_list(), "\t"))
42
- # print("--------------------Constant Map")
43
- # print(JSON.stringify(current_script.get_script_constant_map(), "\t"))
44
- # print("-------------------- Method List")
45
- # print(JSON.stringify(current_script.get_script_method_list(), "\t"))
46
- # print("--------------------")
47
- # print(path.get_file())
48
41
var getters_setters := collect_getters_and_setters (source_code )
49
42
50
43
for method in current_script .get_script_method_list ():
@@ -58,16 +51,15 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
58
51
if not is_func_moddable (method_first_line_start , source_code ):
59
52
continue
60
53
61
- # print(method.flags)
62
54
var type_string := get_return_type_string (method .return )
63
55
var is_static := true if method .flags == METHOD_FLAG_STATIC + METHOD_FLAG_NORMAL else false
64
56
var method_arg_string_with_defaults_and_types := get_function_parameters (method .name , source_code , is_static )
65
57
var method_arg_string_names_only := get_function_arg_name_string (method .args )
66
58
67
- var hash_before = ModLoaderMod .get_hook_hash (path , method .name , true )
68
- var hash_after = ModLoaderMod .get_hook_hash (path , method .name , false )
69
- var hash_before_data = [path , method .name ,true ]
70
- var hash_after_data = [path , method .name ,false ]
59
+ var hash_before : = ModLoaderMod .get_hook_hash (path , method .name , true )
60
+ var hash_after : = ModLoaderMod .get_hook_hash (path , method .name , false )
61
+ var hash_before_data : = [path , method .name ,true ]
62
+ var hash_after_data : = [path , method .name ,false ]
71
63
if hashmap .has (hash_before ):
72
64
push_error (HASH_COLLISION_ERROR % [hashmap [hash_before ], hash_before_data ])
73
65
if hashmap .has (hash_after ):
@@ -104,19 +96,6 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
104
96
skip ()
105
97
add_file (path , source_code .to_utf8_buffer (), false )
106
98
107
- static func handle_class_name (text : String ) -> String :
108
- var class_name_start_index := text .find ("class_name" )
109
- if class_name_start_index == - 1 :
110
- return ""
111
- var class_name_end_index := text .find ("\n " , class_name_start_index )
112
- var class_name_line := text .substr (class_name_start_index , class_name_end_index - class_name_start_index )
113
-
114
- return class_name_line
115
-
116
-
117
- static func handle_self_ref (global_name : String , text : String ) -> String :
118
- return text .replace ("self" , "self as %s " % global_name )
119
-
120
99
121
100
static func get_function_arg_name_string (args : Array ) -> String :
122
101
var arg_string := ""
@@ -194,6 +173,7 @@ static func prefix_method_name(method_name: String, is_static: bool, text: Strin
194
173
print ("WHAT?!" )
195
174
return text
196
175
176
+
197
177
static func get_mod_loader_hook (
198
178
method_name : String ,
199
179
method_arg_string_names_only : String ,
@@ -239,7 +219,7 @@ static func get_previous_line_to(text: String, index: int) -> String:
239
219
if index <= 0 or index >= text .length ():
240
220
return ""
241
221
242
- var start_index = index - 1
222
+ var start_index : = index - 1
243
223
# Find the end of the previous line
244
224
while start_index > 0 and text [start_index ] != "\n " :
245
225
start_index -= 1
@@ -250,22 +230,24 @@ static func get_previous_line_to(text: String, index: int) -> String:
250
230
start_index -= 1
251
231
252
232
# Find the start of the previous line
253
- var end_index = start_index
233
+ var end_index : = start_index
254
234
while start_index > 0 and text [start_index - 1 ] != "\n " :
255
235
start_index -= 1
256
236
257
237
return text .substr (start_index , end_index - start_index + 1 )
258
238
239
+
259
240
static func is_func_moddable (method_start_idx , text ) -> bool :
260
- var prevline = get_previous_line_to (text , method_start_idx )
261
-
241
+ var prevline : = get_previous_line_to (text , method_start_idx )
242
+
262
243
if prevline .contains ("@not-moddable" ):
263
244
return false
264
245
if not REQUIRE_EXPLICIT_ADDITION :
265
246
return true
266
-
247
+
267
248
return prevline .contains ("@moddable" )
268
249
250
+
269
251
static func get_index_at_method_start (method_name : String , text : String ) -> int :
270
252
# Regular expression to match the function definition with arbitrary whitespace
271
253
var pattern := "func\\ s+%s \\ s*\\ (" % method_name
@@ -296,13 +278,13 @@ static func is_top_level_func(text: String, result_start_index: int, is_static :
296
278
static func get_return_type_string (return_data : Dictionary ) -> String :
297
279
if return_data .type == 0 :
298
280
return ""
299
- var type_base
281
+ var type_base : String
300
282
if return_data .has ("class_name" ) and not str (return_data .class_name ).is_empty ():
301
283
type_base = str (return_data .class_name )
302
284
else :
303
285
type_base = type_string (return_data .type )
304
286
305
- var type_hint = "" if return_data .hint_string .is_empty () else ("[%s ]" % return_data .hint_string )
287
+ var type_hint : = "" if return_data .hint_string .is_empty () else ("[%s ]" % return_data .hint_string )
306
288
307
289
return "%s%s " % [type_base , type_hint ]
308
290
0 commit comments