Skip to content

Commit 0f907e6

Browse files
committed
refactor: ♻️ removed no longer used functions
and a first style and type pass
1 parent ffaf025 commit 0f907e6

File tree

1 file changed

+16
-34
lines changed

1 file changed

+16
-34
lines changed

addons/mod_loader/_export_plugin/export_plugin.gd

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var hashmap := {}
1212
func _get_name() -> String:
1313
return "Godot Mod Loader Export Plugin"
1414

15+
1516
func _export_begin(features: PackedStringArray, is_debug: bool, path: String, flags: int) -> void:
1617
hashmap.clear()
1718
regex_getter_setter = RegEx.new()
@@ -31,20 +32,12 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
3132

3233
#we need to stop all vanilla methods from forming inheritance chains
3334
#since the generated methods will fulfill inheritance requirements
34-
var class_prefix = str(hash(path))
35+
var class_prefix := str(hash(path))
3536
var method_store: Array[String] = []
3637
var mod_loader_hooks_start_string := """
3738
# ModLoader Hooks - The following code has been automatically added by the Godot Mod Loader export plugin.
3839
"""
3940

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())
4841
var getters_setters := collect_getters_and_setters(source_code)
4942

5043
for method in current_script.get_script_method_list():
@@ -58,16 +51,15 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
5851
if not is_func_moddable(method_first_line_start, source_code):
5952
continue
6053

61-
#print(method.flags)
6254
var type_string := get_return_type_string(method.return)
6355
var is_static := true if method.flags == METHOD_FLAG_STATIC + METHOD_FLAG_NORMAL else false
6456
var method_arg_string_with_defaults_and_types := get_function_parameters(method.name, source_code, is_static)
6557
var method_arg_string_names_only := get_function_arg_name_string(method.args)
6658

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]
7163
if hashmap.has(hash_before):
7264
push_error(HASH_COLLISION_ERROR%[hashmap[hash_before], hash_before_data])
7365
if hashmap.has(hash_after):
@@ -104,19 +96,6 @@ func _export_file(path: String, type: String, features: PackedStringArray) -> vo
10496
skip()
10597
add_file(path, source_code.to_utf8_buffer(), false)
10698

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-
12099

121100
static func get_function_arg_name_string(args: Array) -> String:
122101
var arg_string := ""
@@ -194,6 +173,7 @@ static func prefix_method_name(method_name: String, is_static: bool, text: Strin
194173
print("WHAT?!")
195174
return text
196175

176+
197177
static func get_mod_loader_hook(
198178
method_name: String,
199179
method_arg_string_names_only: String,
@@ -239,7 +219,7 @@ static func get_previous_line_to(text: String, index: int) -> String:
239219
if index <= 0 or index >= text.length():
240220
return ""
241221

242-
var start_index = index - 1
222+
var start_index := index - 1
243223
# Find the end of the previous line
244224
while start_index > 0 and text[start_index] != "\n":
245225
start_index -= 1
@@ -250,22 +230,24 @@ static func get_previous_line_to(text: String, index: int) -> String:
250230
start_index -= 1
251231

252232
# Find the start of the previous line
253-
var end_index = start_index
233+
var end_index := start_index
254234
while start_index > 0 and text[start_index - 1] != "\n":
255235
start_index -= 1
256236

257237
return text.substr(start_index, end_index - start_index + 1)
258238

239+
259240
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+
262243
if prevline.contains("@not-moddable"):
263244
return false
264245
if not REQUIRE_EXPLICIT_ADDITION:
265246
return true
266-
247+
267248
return prevline.contains("@moddable")
268249

250+
269251
static func get_index_at_method_start(method_name: String, text: String) -> int:
270252
# Regular expression to match the function definition with arbitrary whitespace
271253
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 :
296278
static func get_return_type_string(return_data: Dictionary) -> String:
297279
if return_data.type == 0:
298280
return ""
299-
var type_base
281+
var type_base: String
300282
if return_data.has("class_name") and not str(return_data.class_name).is_empty():
301283
type_base = str(return_data.class_name)
302284
else:
303285
type_base = type_string(return_data.type)
304286

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)
306288

307289
return "%s%s" % [type_base, type_hint]
308290

0 commit comments

Comments
 (0)