@@ -9,6 +9,7 @@ static var regex_getter_setter: RegEx
9
9
10
10
var hashmap := {}
11
11
var previous_method := {}
12
+ var last_valid_method := {}
12
13
13
14
14
15
func process_begin () -> void :
@@ -37,6 +38,21 @@ func process_script(path: String) -> String:
37
38
var method : Dictionary = script_method_list [i ]
38
39
var method_first_line_start := get_index_at_method_start (method .name , source_code )
39
40
41
+ if i == script_method_list .size () - 1 :
42
+ # Check for super in last func
43
+ # TODO: Add a better last method check
44
+ var last_func_index := source_code .rfind ("func " )
45
+ if not last_func_index == - 1 :
46
+ var code_between_end_and_last_func := source_code .substr (last_func_index )
47
+ var supers := match_super_with_whitespace_all (code_between_end_and_last_func )
48
+ for super_result in supers :
49
+ print ("super detected at end of SCRIPT!!!" )
50
+ var super_arg_string := get_super_arg_string (code_between_end_and_last_func , super_result .get_end () - 1 )
51
+ print ("replace super(%s ) with super.%s (%s )" % [super_arg_string , last_valid_method .name , super_arg_string ])
52
+ code_between_end_and_last_func = code_between_end_and_last_func .replace ("super(%s )" % super_arg_string , "super.%s (%s )" % [last_valid_method .name , super_arg_string ])
53
+ source_code = source_code .erase (last_func_index , source_code .length () - last_func_index )
54
+ source_code = source_code .insert (last_func_index , code_between_end_and_last_func )
55
+
40
56
if method_first_line_start == - 1 or method .name in method_store :
41
57
continue
42
58
@@ -46,6 +62,8 @@ func process_script(path: String) -> String:
46
62
if not is_func_moddable (method_first_line_start , source_code ):
47
63
continue
48
64
65
+ last_valid_method = method
66
+
49
67
if i > 0 :
50
68
# get_script_method_list() returns the methods in order they are in the source_code
51
69
# we can use that to get the code between two funcs.
@@ -62,28 +80,21 @@ func process_script(path: String) -> String:
62
80
if not method_end_match :
63
81
print ("No match for \" %s \" " % method .name )
64
82
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 ())
83
+ code_between_funcs = source_code .substr (method_start_match .get_start (), method_end_match .get_start () - method_start_match .get_start ())
71
84
72
85
var supers := match_super_with_whitespace_all (code_between_funcs )
73
- print (supers . size () )
86
+ print (supers )
74
87
for super_result in supers :
75
88
print ("super detected!" )
76
89
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 )
90
+ print ("replace super(%s ) with super.%s (%s )" % [super_arg_string , previous_method .name , super_arg_string ])
79
91
code_between_funcs = code_between_funcs .replace ("super(%s )" % super_arg_string , "super.%s (%s )" % [previous_method .name , super_arg_string ])
80
92
81
- print ("new_code: " )
93
+ print ("new_code: \n " )
82
94
print (code_between_funcs )
83
95
source_code = source_code .erase (method_start_match .get_start (), method_end_match .get_start () - method_start_match .get_start ())
84
96
source_code = source_code .insert (method_start_match .get_start (), code_between_funcs )
85
97
86
-
87
98
var type_string := get_return_type_string (method .return )
88
99
var is_static := true if method .flags == METHOD_FLAG_STATIC + METHOD_FLAG_NORMAL else false
89
100
var method_arg_string_with_defaults_and_types := get_function_parameters (method .name , source_code , is_static )
0 commit comments