@@ -21,7 +21,8 @@ func process_script(path: String) -> String:
21
21
var current_script := load (path ) as GDScript
22
22
var source_code := current_script .source_code
23
23
var source_code_additions := ""
24
-
24
+ print (path )
25
+ print ("----------------------------" )
25
26
# We need to stop all vanilla methods from forming inheritance chains,
26
27
# since the generated methods will fulfill inheritance requirements
27
28
var class_prefix := str (hash (path ))
@@ -30,17 +31,10 @@ func process_script(path: String) -> String:
30
31
"\n # ModLoader Hooks - The following code has been automatically added by the Godot Mod Loader export plugin."
31
32
32
33
var getters_setters := collect_getters_and_setters (source_code )
33
-
34
34
var script_method_list := current_script .get_script_method_list ()
35
35
36
36
for i in script_method_list .size ():
37
37
var method : Dictionary = script_method_list [i ]
38
-
39
- if i > 0 :
40
- # get_script_method_list() returns the methods in order they are in the source_code
41
- # we can use that to get the code between two funcs.
42
- previous_method = script_method_list [i - 1 ]
43
-
44
38
var method_first_line_start := get_index_at_method_start (method .name , source_code )
45
39
46
40
if method_first_line_start == - 1 or method .name in method_store :
@@ -52,6 +46,44 @@ func process_script(path: String) -> String:
52
46
if not is_func_moddable (method_first_line_start , source_code ):
53
47
continue
54
48
49
+ if i > 0 :
50
+ # get_script_method_list() returns the methods in order they are in the source_code
51
+ # we can use that to get the code between two funcs.
52
+ previous_method = script_method_list [i - 1 ]
53
+ if not previous_method .name .begins_with ("@" ):
54
+ var method_name_start := "%s%s _%s " % [METHOD_PREFIX , class_prefix , previous_method .name ]
55
+ var method_start_match := match_func_with_whitespace (method_name_start , source_code )
56
+ var method_end_match := match_func_with_whitespace (method .name , source_code )
57
+ var code_between_funcs := ""
58
+
59
+ if not method_start_match :
60
+ print ("No match for \" %s \" " % previous_method .name )
61
+
62
+ if not method_end_match :
63
+ print ("No match for \" %s \" " % method .name )
64
+
65
+ # TODO: Add a better last method check
66
+ if source_code .find ("func " , method_end_match .get_end ()) == - 1 :
67
+ print ("last method! -> %s " % method .name )
68
+ code_between_funcs = source_code .substr (method_end_match .get_start ())
69
+ else :
70
+ code_between_funcs = source_code .substr (method_start_match .get_start (), method_end_match .get_start () - method_start_match .get_start ())
71
+
72
+ var supers := match_super_with_whitespace_all (code_between_funcs )
73
+ print (supers .size ())
74
+ for super_result in supers :
75
+ print ("super detected!" )
76
+ var super_arg_string := get_super_arg_string (code_between_funcs , super_result .get_end () - 1 )
77
+ print ("super_arg_string" )
78
+ print (super_arg_string )
79
+ code_between_funcs = code_between_funcs .replace ("super(%s )" % super_arg_string , "super.%s (%s )" % [previous_method .name , super_arg_string ])
80
+
81
+ print ("new_code: " )
82
+ print (code_between_funcs )
83
+ source_code = source_code .erase (method_start_match .get_start (), method_end_match .get_start () - method_start_match .get_start ())
84
+ source_code = source_code .insert (method_start_match .get_start (), code_between_funcs )
85
+
86
+
55
87
var type_string := get_return_type_string (method .return )
56
88
var is_static := true if method .flags == METHOD_FLAG_STATIC + METHOD_FLAG_NORMAL else false
57
89
var method_arg_string_with_defaults_and_types := get_function_parameters (method .name , source_code , is_static )
@@ -312,26 +344,24 @@ static func collect_getters_and_setters(text: String) -> Dictionary:
312
344
return result
313
345
314
346
315
- static func get_string_between_functions (method_name_start : String , method_name_end : String , text : String ) -> void :
347
+ static func get_string_between_functions (method_name_start : String , method_name_end : String , text : String ) -> String :
316
348
var method_start_match := match_func_with_whitespace (method_name_start , text )
317
349
var method_end_match := match_func_with_whitespace (method_name_end , text )
318
350
319
- return text .substr (method_start_match .get_start (), method_end_match .get_start ())
320
-
351
+ print ("method_name_start: %s - method_name_end: %s " % [method_name_start , method_name_end ])
321
352
322
- static func get_super_string (method_name : String , text : String , is_static : bool , offset := 0 ) -> String :
323
- var result := match_func_with_whitespace (method_name , text , offset )
324
- if result == null :
353
+ if not method_start_match :
354
+ print ("No match for \" %s \" " % method_name_start )
325
355
return ""
326
356
327
- # Find the index of the opening parenthesis
328
- var opening_paren_index := result .get_end () - 1
329
- if opening_paren_index == - 1 :
357
+ if not method_end_match :
358
+ print ("No match for \" %s \" " % method_end_match )
330
359
return ""
331
360
332
- if not is_top_level_func (text , result .get_start (), is_static ):
333
- return get_function_parameters (method_name , text , is_static , result .get_end ())
361
+ return text .substr (method_start_match .get_start (), method_end_match .get_start () - method_start_match .get_start ())
334
362
363
+
364
+ static func get_super_arg_string (text : String , opening_paren_index := 0 ) -> String :
335
365
# Use a stack to match parentheses
336
366
var stack := []
337
367
var closing_paren_index := opening_paren_index
@@ -350,14 +380,4 @@ static func get_super_string(method_name: String, text: String, is_static: bool,
350
380
return ""
351
381
352
382
# Extract the substring between the parentheses
353
- var param_string := text .substr (opening_paren_index + 1 , closing_paren_index - opening_paren_index - 1 )
354
-
355
- # Clean trailing characters and whitespace
356
- param_string = param_string .strip_edges ()\
357
- .replace (" " , "" )\
358
- .replace ("\n " , "" )\
359
- .replace ("\t " , "" )\
360
- .replace ("," , ", " )\
361
- .replace (":" , ": " )
362
-
363
- return param_string
383
+ return text .substr (opening_paren_index + 1 , closing_paren_index - opening_paren_index - 1 )
0 commit comments