Skip to content

Commit 22e9169

Browse files
authored
fix: 🐛 moved default profile creation to _init() (#530)
Added `ModLoaderUserProfile.is_initialized()` and a fallback to the default config in `ModData.load_configs()`. Moved default user profile creation and user profile `mod_list` updates to the mod loader `_init()`. With these changes, all config and user profile data is available on the first run. closes #465 #468
1 parent 6ee18c1 commit 22e9169

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

addons/mod_loader/api/profile.gd

+7
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ static func get_all_as_array() -> Array:
199199
return user_profiles
200200

201201

202+
# Returns true if the Mod User Profiles are initialized.
203+
# On the first execution of the game, user profiles might not yet be created.
204+
# Use this method to check if everything is ready to interact with the ModLoaderUserProfile API.
205+
static func is_initialized() -> bool:
206+
return _ModLoaderFile.file_exists(FILE_PATH_USER_PROFILES)
207+
208+
202209
# Internal profile functions
203210
# =============================================================================
204211

addons/mod_loader/mod_loader.gd

+10-9
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ func _init() -> void:
6161
ModLoaderLog.info("game_install_directory: %s" % _ModLoaderPath.get_local_folder_dir(), LOG_NAME)
6262

6363
# Load user profiles into ModLoaderStore
64-
var _success_user_profile_load := ModLoaderUserProfile._load()
64+
if ModLoaderUserProfile.is_initialized():
65+
var _success_user_profile_load := ModLoaderUserProfile._load()
66+
67+
# Create the default user profile if it does not already exist.
68+
# This should only occur on the first run or if the JSON file was manually edited.
69+
if not ModLoaderStore.user_profiles.has("default"):
70+
var _success_user_profile_create := ModLoaderUserProfile.create_profile("default")
6571

6672
# --- Start loading mods ---
6773
var loaded_count := 0
@@ -125,6 +131,9 @@ func _init() -> void:
125131

126132
ModLoaderLog.success("DONE: Loaded %s mod files into the virtual filesystem" % loaded_count, LOG_NAME)
127133

134+
# Update the mod_list for each user profile
135+
var _success_update_mod_lists := ModLoaderUserProfile._update_mod_lists()
136+
128137
# Update active state of mods based on the current user profile
129138
ModLoaderUserProfile._update_disabled_mods()
130139

@@ -203,14 +212,6 @@ func _init() -> void:
203212

204213

205214
func _ready():
206-
# Create the default user profile if it doesn't exist already
207-
# This should always be present unless the JSON file was manually edited
208-
if not ModLoaderStore.user_profiles.has("default"):
209-
var _success_user_profile_create := ModLoaderUserProfile.create_profile("default")
210-
211-
# Update the mod_list for each user profile
212-
var _success_update_mod_lists := ModLoaderUserProfile._update_mod_lists()
213-
214215
# Hooks must be generated after all autoloads are available.
215216
# Variables initialized with an autoload property cause errors otherwise.
216217
if ModLoaderStore.any_mod_hooked:

addons/mod_loader/resources/mod_data.gd

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ func load_configs() -> void:
107107
_load_config(config_file_path)
108108

109109
# Set the current_config based on the user profile
110-
current_config = ModLoaderConfig.get_current_config(dir_name)
110+
if ModLoaderUserProfile.is_initialized() and ModLoaderConfig.has_current_config(dir_name):
111+
current_config = ModLoaderConfig.get_current_config(dir_name)
112+
else:
113+
current_config = ModLoaderConfig.get_config(dir_name, ModLoaderConfig.DEFAULT_CONFIG_NAME)
111114

112115

113116
# Create a new ModConfig instance for each Config JSON and add it to the configs dictionary.

0 commit comments

Comments
 (0)