Skip to content

Commit 2b1c2b9

Browse files
committed
✔ run setup based on position in autoloads (GodotModding#105)
1 parent 3b2257c commit 2b1c2b9

File tree

1 file changed

+30
-47
lines changed

1 file changed

+30
-47
lines changed

addons/mod_loader/mod_loader_setup.gd

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,34 @@ var is_setup_create_override_cfg : bool = modloaderutils.is_running_with_command
3939

4040

4141
func _init() -> void:
42-
try_setup_modloader()
43-
var _changescene_error: int = change_scene(ProjectSettings.get_setting("application/run/main_scene"))
42+
modloaderutils.log_debug("ModLoader setup initialized", LOG_NAME)
4443

45-
46-
# Set up the ModLoader, if it hasn't been set up yet
47-
func try_setup_modloader() -> void:
4844
# Avoid doubling the setup work
49-
if is_loader_setup_applied():
50-
modloaderutils.log_info("ModLoader is available, mods can be loaded!", LOG_NAME)
51-
OS.set_window_title("%s (Modded)" % ProjectSettings.get_setting("application/config/name"))
45+
# Checks if the ModLoader Node is in the root of the scene tree
46+
# and if the IS_LOADER_SETUP_APPLIED project setting is there
47+
if modloaderutils.get_autoload_index("ModLoader") == 0:
48+
modded_start()
5249
return
5350

54-
setup_file_data()
5551
setup_modloader()
5652

57-
# If the loader is set up, but the override is not applied yet,
58-
# prompt the user to quit and restart the game.
59-
if is_loader_set_up() and not is_loader_setup_applied():
60-
modloaderutils.log_info("ModLoader is set up, but the game needs to be restarted", LOG_NAME)
61-
ProjectSettings.set_setting(settings.IS_LOADER_SETUP_APPLIED, true)
6253

63-
if is_setup_create_override_cfg:
64-
handle_override_cfg()
65-
else:
66-
handle_project_binary()
54+
# ModLoader already setup - switch to the main scene
55+
func modded_start() -> void:
56+
modloaderutils.log_info("ModLoader is available, mods can be loaded!", LOG_NAME)
57+
58+
OS.set_window_title("%s (Modded)" % ProjectSettings.get_setting("application/config/name"))
6759

68-
match true:
69-
# If the --only-setup cli argument is passed, quit with exit code 0
70-
is_only_setup:
71-
quit(0)
72-
# If no cli argument is passed, show message with OS.alert() and user has to restart the game
73-
_:
74-
OS.alert("The Godot ModLoader has been set up. Restart the game to apply the changes. Confirm to quit.")
75-
quit(0)
60+
var _error_change_scene_main := change_scene(ProjectSettings.get_setting("application/run/main_scene"))
7661

7762

7863
# Set up the ModLoader as an autoload and register the other global classes.
79-
# Saved as override.cfg besides the game executable to extend the existing project settings
8064
func setup_modloader() -> void:
8165
modloaderutils.log_info("Setting up ModLoader", LOG_NAME)
8266

67+
# Setup path and file_name dict with all required paths and file names.
68+
setup_file_data()
69+
8370
# Register all new helper classes as global
8471
modloaderutils.register_global_classes_from_array(new_global_classes)
8572

@@ -98,8 +85,22 @@ func setup_modloader() -> void:
9885
<<<<<<< HEAD
9986
=======
10087

88+
<<<<<<< HEAD
10189
modloaderutils.log_info("ModLoader setup complete", LOG_NAME)
10290
>>>>>>> 32150e0 (✔ added --setup-create-override-cfg cli arg)
91+
=======
92+
# ModLoader is set up. A game restart is required to apply the ProjectSettings.
93+
modloaderutils.log_info("ModLoader is set up, a game restart is required.", LOG_NAME)
94+
95+
match true:
96+
# If the --only-setup cli argument is passed, quit with exit code 0
97+
is_only_setup:
98+
quit(0)
99+
# If no cli argument is passed, show message with OS.alert() and user has to restart the game
100+
_:
101+
OS.alert("The Godot ModLoader has been set up. Restart the game to apply the changes. Confirm to quit.")
102+
quit(0)
103+
>>>>>>> 903cbeb (✔ run setup based on position in autoloads (#105))
103104

104105

105106
# Reorders the autoloads in the project settings, to get the ModLoader on top.
@@ -125,11 +126,13 @@ func reorder_autoloads() -> void:
125126

126127
# Saves the ProjectSettings to a override.cfg file in the base game directory.
127128
func handle_override_cfg() -> void:
129+
modloaderutils.log_debug("using the override.cfg file", LOG_NAME)
128130
var _save_custom_error: int = ProjectSettings.save_custom(modloaderutils.get_override_path())
129131

130132

131133
# Creates the project.binary file, adds it to the pck and removes the no longer needed project.binary file.
132134
func handle_project_binary() -> void:
135+
modloaderutils.log_debug("injecting the project.binary file", LOG_NAME)
133136
create_project_binary()
134137
inject_project_binary()
135138
clean_up_project_binary_file()
@@ -182,23 +185,3 @@ func setup_file_data() -> void:
182185

183186
modloaderutils.log_debug_json_print("path: ", path, LOG_NAME)
184187
modloaderutils.log_debug_json_print("file_name: ", file_name, LOG_NAME)
185-
186-
187-
func is_loader_set_up() -> bool:
188-
return is_project_setting_true(settings.IS_LOADER_SET_UP)
189-
190-
191-
func is_loader_setup_applied() -> bool:
192-
if not root.get_node_or_null("/root/ModLoader") == null:
193-
if not is_project_setting_true(settings.IS_LOADER_SETUP_APPLIED):
194-
modloaderutils.log_info("ModLoader is already set up. No self setup required.", LOG_NAME)
195-
return true
196-
return false
197-
198-
199-
static func is_project_setting_true(project_setting: String) -> bool:
200-
return ProjectSettings.has_setting(project_setting) and\
201-
ProjectSettings.get_setting(project_setting)
202-
203-
204-

0 commit comments

Comments
 (0)