diff --git a/addons/mod_loader/api/config.gd b/addons/mod_loader/api/config.gd index 196e5bf2..83e59304 100644 --- a/addons/mod_loader/api/config.gd +++ b/addons/mod_loader/api/config.gd @@ -1,9 +1,8 @@ +# This Class provides functionality for working with per-mod Configurations. class_name ModLoaderConfig extends Object -# This Class provides functionality for working with per-mod Configurations. - const LOG_NAME := "ModLoader:Config" const DEFAULT_CONFIG_NAME := "default" @@ -163,7 +162,7 @@ static func get_config_schema(mod_id: String) -> Dictionary: # Parameters: # - config (ModConfig): The ModConfig object from which to retrieve the schema. # - prop (String): The property key for which to retrieve the schema. -# e.g. "parentProp.childProp.nthChildProp" || "propKey" +# e.g. `parentProp.childProp.nthChildProp` || `propKey` # # Returns: # - Dictionary: The schema dictionary for the specified property. diff --git a/addons/mod_loader/api/deprecated.gd b/addons/mod_loader/api/deprecated.gd index 7de5f750..d2cfca31 100644 --- a/addons/mod_loader/api/deprecated.gd +++ b/addons/mod_loader/api/deprecated.gd @@ -1,12 +1,20 @@ +# API methods for deprecating funcs. Can be used by mods with public APIs. class_name ModLoaderDeprecated extends Node -# API methods for deprecating funcs. Can be used by mods with public APIs. const LOG_NAME := "ModLoader:Deprecated" -# A method has changed its name/class +# Marks a method that has changed its name or class. +# +# Parameters: +# - old_method (String): The name of the deprecated method. +# - new_method (String): The name of the new method to use. +# - since_version (String): The version number from which the method has been deprecated. +# - show_removal_note (bool): (optional) If true, includes a note about future removal of the old method. Default is true. +# +# Returns: void static func deprecated_changed(old_method: String, new_method: String, since_version: String, show_removal_note: bool = true) -> void: _deprecated_log(str( "DEPRECATED: ", @@ -16,8 +24,15 @@ static func deprecated_changed(old_method: String, new_method: String, since_ver )) -# A method has been entirely removed, with no replacement -# (should never be needed but good to have just in case) +# Marks a method that has been entirely removed, with no replacement. +# Note: This should rarely be needed but is included for completeness. +# +# Parameters: +# - old_method (String): The name of the removed method. +# - since_version (String): The version number from which the method has been deprecated. +# - show_removal_note (bool): (optional) If true, includes a note about future removal of the old method. Default is true. +# +# Returns: void static func deprecated_removed(old_method: String, since_version: String, show_removal_note: bool = true) -> void: _deprecated_log(str( "DEPRECATED: ", @@ -27,15 +42,24 @@ static func deprecated_removed(old_method: String, since_version: String, show_r )) -# Freeform deprecation message. -# Allows you to add a deprecation comment without specifying the old/new method +# Marks a method with a freeform deprecation message. +# +# Parameters: +# - msg (String): The deprecation message. +# - since_version (String): (optional) The version number from which the deprecation applies. +# +# Returns: void static func deprecated_message(msg: String, since_version: String = "") -> void: var since_text := " (since version %s)" % since_version if since_version else "" _deprecated_log(str("DEPRECATED: ", msg, since_text)) -# Internal func for logging with support to trigger warnings instead of fatal -# errors +# Internal function for logging deprecation messages with support to trigger warnings instead of fatal errors. +# +# Parameters: +# - msg (String): The deprecation message. +# +# Returns: void static func _deprecated_log(msg: String) -> void: if ModLoaderStore.ml_options.ignore_deprecated_errors or OS.has_feature("standalone"): ModLoaderLog.warning(msg, LOG_NAME) diff --git a/addons/mod_loader/api/log.gd b/addons/mod_loader/api/log.gd index 0b405e82..9752d4db 100644 --- a/addons/mod_loader/api/log.gd +++ b/addons/mod_loader/api/log.gd @@ -1,10 +1,10 @@ +# This Class provides methods for logging, retrieving logged data, and internal methods for working with log files. class_name ModLoaderLog extends Node - -# This Class provides methods for logging, retrieving logged data, and internal methods for working with log files. - +# Path to the latest log file. const MOD_LOG_PATH := "user://logs/modloader.log" + const LOG_NAME := "ModLoader:Log" enum VERBOSITY_LEVEL { @@ -14,17 +14,41 @@ enum VERBOSITY_LEVEL { DEBUG, } +# This Sub-Class represents a log entry in ModLoader. class ModLoaderLogEntry: extends Resource + # Name of the mod or ModLoader class this entry refers to. var mod_name: String + + # The message of the log entry. var message: String + + # The log type, which indicates the verbosity level of this entry. var type: String + + # The readable format of the time when this log entry was created. + # Used for printing in the log file and output. var time: String + + # The timestamp when this log entry was created. + # Used for comparing and sorting log entries by time. var time_stamp: int + + # An array of ModLoaderLogEntry objects. + # If the message has been logged before, it is added to the stack. var stack := [] + # Initialize a ModLoaderLogEntry object with provided values. + # + # Parameters: + # - _mod_name (String): Name of the mod or ModLoader class this entry refers to. + # - _message (String): The message of the log entry. + # - _type (String): The log type, which indicates the verbosity level of this entry. + # - _time (String): The readable format of the time when this log entry was created. + # + # Returns: void func _init(_mod_name: String, _message: String, _type: String, _time: String) -> void: mod_name = _mod_name message = _message @@ -33,18 +57,30 @@ class ModLoaderLogEntry: time_stamp = Time.get_ticks_msec() + # Get the log entry as a formatted string. + # + # Returns: String func get_entry() -> String: return str(time, get_prefix(), message) + # Get the prefix string for the log entry, including the log type and mod name. + # + # Returns: String func get_prefix() -> String: return "%s %s: " % [type.to_upper(), mod_name] + # Generate an MD5 hash of the log entry (prefix + message). + # + # Returns: String func get_md5() -> String: return str(get_prefix(), message).md5_text() + # Get all log entries, including the current entry and entries in the stack. + # + # Returns: Array func get_all_entries() -> Array: var entries := [self] entries.append_array(stack) @@ -55,45 +91,102 @@ class ModLoaderLogEntry: # API log functions - logging # ============================================================================= -# Logs the error in red and a stack trace. Prefixed FATAL-ERROR -# Stops the execution in editor -# Always logged + +# Logs the error in red and a stack trace. Prefixed FATAL-ERROR. +# +# *Note: Stops the execution in editor* +# +# Parameters: +# - message (String): The message to be logged as an error. +# - mod_name (String): The name of the mod or ModLoader class associated with this log entry. +# - only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false. +# +# Returns: void static func fatal(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "fatal-error", only_once) -# Logs the message and pushed an error. Prefixed ERROR -# Always logged +# Logs the message and pushes an error. Prefixed ERROR. +# +# *Note: Always logged* +# +# Parameters: +# - message (String): The message to be logged as an error. +# - mod_name (String): The name of the mod or ModLoader class associated with this log entry. +# - only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false. +# +# Returns: void static func error(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "error", only_once) -# Logs the message and pushes a warning. Prefixed WARNING -# Logged with verbosity level at or above warning (-v) +# Logs the message and pushes a warning. Prefixed WARNING. +# +# *Note: Logged with verbosity level at or above warning (-v).* +# +# Parameters: +# - message (String): The message to be logged as a warning. +# - mod_name (String): The name of the mod or ModLoader class associated with this log entry. +# - only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false. +# +# Returns: void static func warning(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "warning", only_once) -# Logs the message. Prefixed INFO -# Logged with verbosity level at or above info (-vv) +# Logs the message. Prefixed INFO. +# +# *Note: Logged with verbosity level at or above info (-vv).* +# +# Parameters: +# - message (String): The message to be logged as an information. +# - mod_name (String): The name of the mod or ModLoader class associated with this log entry. +# - only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false. +# +# Returns: void static func info(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "info", only_once) -# Logs the message. Prefixed SUCCESS -# Logged with verbosity level at or above info (-vv) +# Logs the message. Prefixed SUCCESS. +# +# *Note: Logged with verbosity level at or above info (-vv).* +# +# Parameters: +# - message (String): The message to be logged as a success. +# - mod_name (String): The name of the mod or ModLoader class associated with this log entry. +# - only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false. +# +# Returns: void static func success(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "success", only_once) -# Logs the message. Prefixed DEBUG -# Logged with verbosity level at or above debug (-vvv) +# Logs the message. Prefixed DEBUG. +# +# *Note: Logged with verbosity level at or above debug (-vvv).* +# +# Parameters: +# - message (String): The message to be logged as a debug. +# - mod_name (String): The name of the mod or ModLoader class associated with this log entry. +# - only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false. +# +# Returns: void static func debug(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "debug", only_once) -# Logs the message formatted with [method JSON.print]. Prefixed DEBUG -# Logged with verbosity level at or above debug (-vvv) +# Logs the message formatted with [method JSON.print]. Prefixed DEBUG. +# +# *Note: Logged with verbosity level at or above debug (-vvv).* +# +# Parameters: +# - message (String): The message to be logged as a debug. +# - json_printable (Variant): The variable to be formatted and printed using [method JSON.print]. +# - mod_name (String): The name of the mod or ModLoader class associated with this log entry. +# - only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false. +# +# Returns: void static func debug_json_print(message: String, json_printable, mod_name: String, only_once := false) -> void: message = "%s\n%s" % [message, JSON.print(json_printable, " ")] _log(message, mod_name, "debug", only_once) @@ -102,39 +195,74 @@ static func debug_json_print(message: String, json_printable, mod_name: String, # API log functions - stored logs # ============================================================================= -# Returns an array of log entries as resource + +# Returns an array of log entries as a resource. +# +# Returns: +# - Array: An array of log entries represented as resource. static func get_all_as_resource() -> Array: return get_all() -# Returns an array of log entries as string +# Returns an array of log entries as a string. +# +# Returns: +# - Array: An array of log entries represented as strings. static func get_all_as_string() -> Array: var log_entries := get_all() return get_all_entries_as_string(log_entries) -# Returns an array of log entries as resource for a specific mod_name +# Returns an array of log entries as a resource for a specific mod_name. +# +# Parameters: +# - mod_name (String): The name of the mod or ModLoader class associated with the log entries. +# +# Returns: +# - Array: An array of log entries represented as resource for the specified mod_name. static func get_by_mod_as_resource(mod_name: String) -> Array: return get_by_mod(mod_name) -# Returns an array of log entries as string for a specific mod_name +# Returns an array of log entries as a string for a specific mod_name. +# +# Parameters: +# - mod_name (String): The name of the mod or ModLoader class associated with the log entries. +# +# Returns: +# - Array: An array of log entries represented as strings for the specified mod_name. static func get_by_mod_as_string(mod_name: String) -> Array: var log_entries := get_by_mod(mod_name) return get_all_entries_as_string(log_entries) -# Returns an array of log entries as resource for a specific mod_name +# Returns an array of log entries as a resource for a specific type. +# +# Parameters: +# - type (String): The log type associated with the log entries. +# +# Returns: +# - Array: An array of log entries represented as resource for the specified type. static func get_by_type_as_resource(type: String) -> Array: return get_by_type(type) -# Returns an array of log entries as string for a specific mod_name +# Returns an array of log entries as a string for a specific type. +# +# Parameters: +# - type (String): The log type associated with the log entries. +# +# Returns: +# - Array: An array of log entries represented as strings for the specified type. static func get_by_type_as_string(type: String) -> Array: var log_entries := get_by_type(type) return get_all_entries_as_string(log_entries) +# Returns an array of all log entries. +# +# Returns: +# - Array: An array of all log entries. static func get_all() -> Array: var log_entries := [] @@ -149,6 +277,13 @@ static func get_all() -> Array: return log_entries +# Returns an array of log entries for a specific mod_name. +# +# Parameters: +# - mod_name (String): The name of the mod or ModLoader class associated with the log entries. +# +# Returns: +# - Array: An array of log entries for the specified mod_name. static func get_by_mod(mod_name: String) -> Array: var log_entries := [] @@ -163,6 +298,13 @@ static func get_by_mod(mod_name: String) -> Array: return log_entries +# Returns an array of log entries for a specific type. +# +# Parameters: +# - type (String): The log type associated with the log entries. +# +# Returns: +# - Array: An array of log entries for the specified type. static func get_by_type(type: String) -> Array: var log_entries := [] @@ -173,6 +315,13 @@ static func get_by_type(type: String) -> Array: return log_entries +# Returns an array of log entries represented as strings. +# +# Parameters: +# - log_entries (Array): An array of ModLoaderLogEntry Objects. +# +# Returns: +# - Array: An array of log entries represented as strings. static func get_all_entries_as_string(log_entries: Array) -> Array: var log_entry_strings := [] diff --git a/addons/mod_loader/api/mod.gd b/addons/mod_loader/api/mod.gd index e3818273..72cc36de 100644 --- a/addons/mod_loader/api/mod.gd +++ b/addons/mod_loader/api/mod.gd @@ -1,17 +1,27 @@ +# This Class provides helper functions to build mods. class_name ModLoaderMod extends Object -# Helper functions to build mods const LOG_NAME := "ModLoader:Mod" -# Add a script that extends a vanilla script. `child_script_path` should point -# to your mod's extender script, eg "MOD/extensions/singletons/utils.gd". -# Inside that extender script, it should include "extends {target}", where -# {target} is the vanilla path, eg: `extends "res://singletons/utils.gd"`. -# Note that your extender script doesn't have to follow the same directory path -# as the vanilla file, but it's good practice to do so. +# Install a script extension that extends a vanilla script. +# The child_script_path should point to your mod's extender script. +# +# Example: `"MOD/extensions/singletons/utils.gd"` +# +# Inside the extender script, include `extends {target}` where `{target}` is the vanilla path. +# +# Example: `extends "res://singletons/utils.gd"`. +# +# *Note: Your extender script doesn't have to follow the same directory path as the vanilla file, +# but it's good practice to do so.* +# +# Parameters: +# - child_script_path (String): The path to the mod's extender script. +# +# Returns: void static func install_script_extension(child_script_path: String) -> void: var mod_id: String = ModLoaderUtils.get_string_in_between(child_script_path, "res://mods-unpacked/", "/") @@ -30,20 +40,30 @@ static func install_script_extension(child_script_path: String) -> void: _ModLoaderScriptExtension.apply_extension(child_script_path) +# Uninstall a script extension. +# +# Parameters: +# - extension_script_path (String): The path to the extension script to be uninstalled. +# +# Returns: void static func uninstall_script_extension(extension_script_path: String) -> void: # Currently this is the only thing we do, but it is better to expose # this function like this for further changes _ModLoaderScriptExtension.remove_specific_extension_from_script(extension_script_path) -# This function should be called only when actually necessary +# Reload all mods. +# +# *Note: This function should be called only when actually necessary # as it can break the game and require a restart for mods # that do not fully use the systems put in place by the mod loader, # so anything that just uses add_node, move_node ecc... # To not have your mod break on reload please use provided functions # like ModLoader::save_scene, ModLoader::append_node_in_scene and # all the functions that will be added in the next versions -# Used to reload already present mods and load new ones +# Used to reload already present mods and load new ones* +# +# Returns: void func reload_mods() -> void: # Currently this is the only thing we do, but it is better to expose @@ -51,13 +71,17 @@ func reload_mods() -> void: ModLoader._reload_mods() -# This function should be called only when actually necessary +# Disable all mods. +# +# *Note: This function should be called only when actually necessary # as it can break the game and require a restart for mods # that do not fully use the systems put in place by the mod loader, # so anything that just uses add_node, move_node ecc... # To not have your mod break on disable please use provided functions # and implement a _disable function in your mod_main.gd that will -# handle removing all the changes that were not done through the Mod Loader +# handle removing all the changes that were not done through the Mod Loader* +# +# Returns: void func disable_mods() -> void: # Currently this is the only thing we do, but it is better to expose @@ -65,13 +89,20 @@ func disable_mods() -> void: ModLoader._disable_mods() -# This function should be called only when actually necessary +# Disable a mod. +# +# *Note: This function should be called only when actually necessary # as it can break the game and require a restart for mods # that do not fully use the systems put in place by the mod loader, # so anything that just uses add_node, move_node ecc... # To not have your mod break on disable please use provided functions # and implement a _disable function in your mod_main.gd that will -# handle removing all the changes that were not done through the Mod Loader +# handle removing all the changes that were not done through the Mod Loader* +# +# Parameters: +# - mod_data (ModData): The ModData object representing the mod to be disabled. +# +# Returns: void func disable_mod(mod_data: ModData) -> void: # Currently this is the only thing we do, but it is better to expose @@ -79,18 +110,31 @@ func disable_mod(mod_data: ModData) -> void: ModLoader._disable_mod(mod_data) -# Register an array of classes to the global scope, since Godot only does that in the editor. -# Format: { "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" } -# You can find these easily in the project.godot file under "_global_script_classes" -# (but you should only include classes belonging to your mod) +# Register an array of classes to the global scope since Godot only does that in the editor. +# +# Format: `{ "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" }` +# +# *Note: You can find these easily in the project.godot file under `_global_script_classes` +# (but you should only include classes belonging to your mod)* +# +# Parameters: +# - new_global_classes (Array): An array of class definitions to be registered. +# +# Returns: void static func register_global_classes_from_array(new_global_classes: Array) -> void: ModLoaderUtils.register_global_classes_from_array(new_global_classes) var _savecustom_error: int = ProjectSettings.save_custom(_ModLoaderPath.get_override_path()) -# Add a translation file, eg "mytranslation.en.translation". The translation -# file should have been created in Godot already: When you import a CSV, such -# a file will be created for you. +# Add a translation file. +# +# *Note: The translation file should have been created in Godot already, +# such as when importing a CSV file. The translation file should be in the format `mytranslation.en.translation`.* +# +# Parameters: +# - resource_path (String): The path to the translation resource file. +# +# Returns: void static func add_translation(resource_path: String) -> void: if not _ModLoaderFile.file_exists(resource_path): ModLoaderLog.fatal("Tried to load a translation resource from a file that doesn't exist. The invalid path was: %s" % [resource_path], LOG_NAME) @@ -102,6 +146,12 @@ static func add_translation(resource_path: String) -> void: # Gets the ModData from the provided namespace +# +# Parameters: +# - mod_id (String): The ID of the mod. +# +# Returns: +# - ModData: The ModData associated with the provided mod_id, or null if the mod_id is invalid. static func get_mod_data(mod_id: String) -> ModData: if not ModLoaderStore.mod_data.has(mod_id): ModLoaderLog.error("%s is an invalid mod_id" % mod_id, LOG_NAME) @@ -111,11 +161,20 @@ static func get_mod_data(mod_id: String) -> ModData: # Gets the ModData of all loaded Mods as Dictionary. +# +# Returns: +# - Dictionary: A dictionary containing the ModData of all loaded mods. static func get_mod_data_all() -> Dictionary: return ModLoaderStore.mod_data # Returns true if the mod with the given mod_id was successfully loaded. +# +# Parameters: +# - mod_id (String): The ID of the mod. +# +# Returns: +# - bool: true if the mod is loaded, false otherwise. static func is_mod_loaded(mod_id: String) -> bool: if ModLoaderStore.is_initializing: ModLoaderLog.warning( @@ -131,6 +190,17 @@ static func is_mod_loaded(mod_id: String) -> bool: return true +# Appends a new node to a modified scene. +# +# Parameters: +# - modified_scene (Node): The modified scene where the node will be appended. +# - node_name (String): (Optional) The name of the new node. Default is an empty string. +# - node_parent (Node): (Optional) The parent node where the new node will be added. Default is null (direct child of modified_scene). +# - instance_path (String): (Optional) The path to a scene resource that will be instantiated as the new node. +# Default is an empty string resulting in a `Node` instance. +# - is_visible (bool): (Optional) If true, the new node will be visible. Default is true. +# +# Returns: void static func append_node_in_scene(modified_scene: Node, node_name: String = "", node_parent = null, instance_path: String = "", is_visible: bool = true) -> void: var new_node: Node if not instance_path == "": @@ -150,6 +220,13 @@ static func append_node_in_scene(modified_scene: Node, node_name: String = "", n new_node.set_owner(modified_scene) +# Saves a modified scene to a file. +# +# Parameters: +# - modified_scene (Node): The modified scene instance to be saved. +# - scene_path (String): The path to the scene file that will be replaced. +# +# Returns: void static func save_scene(modified_scene: Node, scene_path: String) -> void: var packed_scene := PackedScene.new() var _pack_error := packed_scene.pack(modified_scene) @@ -159,5 +236,9 @@ static func save_scene(modified_scene: Node, scene_path: String) -> void: ModLoaderStore.saved_objects.append(packed_scene) +# Returns the path to the directory where unpacked mods are stored. +# +# Returns: +# - String: The path to the unpacked mods directory. static func get_unpacked_dir() -> String: return _ModLoaderPath.get_unpacked_mods_dir_path() diff --git a/addons/mod_loader/api/profile.gd b/addons/mod_loader/api/profile.gd index 7d51c746..da715d76 100644 --- a/addons/mod_loader/api/profile.gd +++ b/addons/mod_loader/api/profile.gd @@ -1,27 +1,48 @@ +# This Class provides methods for working with user profiles. class_name ModLoaderUserProfile extends Object -# This Class provides methods for working with user profiles. - const LOG_NAME := "ModLoader:UserProfile" -const FILE_PATH_USER_PROFILES = "user://mod_user_profiles.json" + +# The path where the Mod User Profiles data is stored. +const FILE_PATH_USER_PROFILES := "user://mod_user_profiles.json" # API profile functions # ============================================================================= + # Enables a mod - it will be loaded on the next game start +# +# Parameters: +# - mod_id (String): The ID of the mod to enable. +# - user_profile (ModUserProfile): (Optional) The user profile to enable the mod for. Default is the current user profile. +# +# Returns: bool static func enable_mod(mod_id: String, user_profile := ModLoaderStore.current_user_profile) -> bool: return _set_mod_state(mod_id, user_profile.name, true) # Disables a mod - it will not be loaded on the next game start +# +# Parameters: +# - mod_id (String): The ID of the mod to disable. +# - user_profile (ModUserProfile): (Optional) The user profile to disable the mod for. Default is the current user profile. +# +# Returns: bool static func disable_mod(mod_id: String, user_profile := ModLoaderStore.current_user_profile) -> bool: return _set_mod_state(mod_id, user_profile.name, false) -# Sets the current config for a mod in a user profiles mod_list. +# Sets the current config for a mod in a user profile's mod_list. +# +# Parameters: +# - mod_id (String): The ID of the mod. +# - mod_config (ModConfig): The mod config to set as the current config. +# - user_profile (ModUserProfile): (Optional) The user profile to update. Default is the current user profile. +# +# Returns: bool static func set_mod_current_config(mod_id: String, mod_config: ModConfig, user_profile := ModLoaderStore.current_user_profile) -> bool: # Verify whether the mod_id is present in the profile's mod_list. if not _is_mod_id_in_mod_list(mod_id, user_profile.name): @@ -40,6 +61,11 @@ static func set_mod_current_config(mod_id: String, mod_config: ModConfig, user_p # Creates a new user profile with the given name, using the currently loaded mods as the mod list. +# +# Parameters: +# - profile_name (String): The name of the new user profile (must be unique). +# +# Returns: bool static func create_profile(profile_name: String) -> bool: # Verify that the profile name is not already in use if ModLoaderStore.user_profiles.has(profile_name): @@ -69,7 +95,12 @@ static func create_profile(profile_name: String) -> bool: return is_save_success -# Sets the current user profile to the profile with the specified profile_name. +# Sets the current user profile to the given user profile. +# +# Parameters: +# - user_profile (ModUserProfile): The user profile to set as the current profile. +# +# Returns: bool static func set_profile(user_profile: ModUserProfile) -> bool: # Check if the profile name is unique if not ModLoaderStore.user_profiles.has(user_profile.name): @@ -88,7 +119,12 @@ static func set_profile(user_profile: ModUserProfile) -> bool: return is_save_success -# Deletes a user profile with the given profile_name. +# Deletes the given user profile. +# +# Parameters: +# - user_profile (ModUserProfile): The user profile to delete. +# +# Returns: bool static func delete_profile(user_profile: ModUserProfile) -> bool: # If the current_profile is about to get deleted log an error if ModLoaderStore.current_user_profile.name == user_profile.name: @@ -118,12 +154,19 @@ static func delete_profile(user_profile: ModUserProfile) -> bool: return is_save_success -# Returns the current user profile +# Returns the current user profile. +# +# Returns: ModUserProfile static func get_current() -> ModUserProfile: return ModLoaderStore.current_user_profile -# Return the user profile with the given name +# Returns the user profile with the given name. +# +# Parameters: +# - profile_name (String): The name of the user profile to retrieve. +# +# Returns: ModUserProfile or null if not found static func get_profile(profile_name: String) -> ModUserProfile: if not ModLoaderStore.user_profiles.has(profile_name): ModLoaderLog.error("User profile with name \"%s\" not found." % profile_name, LOG_NAME) @@ -132,7 +175,9 @@ static func get_profile(profile_name: String) -> ModUserProfile: return ModLoaderStore.user_profiles[profile_name] -# Returns an array containing all user profiles stored in ModLoaderStore +# Returns an array containing all user profiles stored in ModLoaderStore. +# +# Returns: Array of ModUserProfile Objects static func get_all_as_array() -> Array: var user_profiles := [] @@ -145,6 +190,7 @@ static func get_all_as_array() -> Array: # Internal profile functions # ============================================================================= + # Update the global list of disabled mods based on the current user profile # The user profile will override the disabled_mods property that can be set via the options resource in the editor. # Example: If "Mod-TestMod" is set in disabled_mods via the editor, the mod will appear disabled in the user profile.