Skip to content

Commit f90f798

Browse files
authored
refactor: Remove self argument on *mod_main.gd* _init (#324)
* feat: Remove self argument * refactor: Deprecated message and script typing
1 parent 4856aae commit f90f798

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

addons/mod_loader/mod_loader.gd

+13-2
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,21 @@ func _init_mod(mod: ModData) -> void:
333333
ModLoaderLog.debug("Initialized overwrite script -> %s" % mod_overwrites_path, LOG_NAME)
334334

335335
ModLoaderLog.debug("Loading script from -> %s" % mod_main_path, LOG_NAME)
336-
var mod_main_script := ResourceLoader.load(mod_main_path)
336+
var mod_main_script: GDScript = ResourceLoader.load(mod_main_path)
337337
ModLoaderLog.debug("Loaded script -> %s" % mod_main_script, LOG_NAME)
338338

339-
var mod_main_instance: Node = mod_main_script.new(self)
339+
var argument_found: bool = false
340+
for method in mod_main_script.get_script_method_list():
341+
if method.name == "_init":
342+
if method.args.size() > 0:
343+
argument_found = true
344+
345+
var mod_main_instance: Node
346+
if argument_found:
347+
mod_main_instance = mod_main_script.new(self)
348+
ModLoaderDeprecated.deprecated_message("The mod_main.gd _init argument (modLoader = ModLoader) is deprecated. Remove it from your _init to avoid crashes in the next major version.", "6.1.0")
349+
else:
350+
mod_main_instance = mod_main_script.new()
340351
mod_main_instance.name = mod.manifest.get_mod_id()
341352

342353
ModLoaderStore.saved_mod_mains[mod_main_path] = mod_main_instance

0 commit comments

Comments
 (0)