From 3212f1a49a11bccc6e4997f9320c0efa5aef01ae Mon Sep 17 00:00:00 2001 From: KANAjetzt <41547570+KANAjetzt@users.noreply.github.com> Date: Fri, 24 May 2024 09:46:35 +0200 Subject: [PATCH] refactor: :recycle: doc comments for all function and class descriptions (#397) refactor: :recycle: updated all function and class descriptions to use doc comments --- addons/mod_loader/api/config.gd | 265 +++++++------- addons/mod_loader/api/deprecated.gd | 71 ++-- addons/mod_loader/api/log.gd | 334 +++++++++--------- addons/mod_loader/api/mod.gd | 163 ++++----- addons/mod_loader/api/profile.gd | 109 +++--- addons/mod_loader/mod_loader.gd | 11 +- addons/mod_loader/mod_loader_store.gd | 4 +- addons/mod_loader/resources/mod_config.gd | 24 +- addons/mod_loader/resources/mod_data.gd | 29 +- addons/mod_loader/resources/mod_manifest.gd | 25 +- .../mod_loader/resources/mod_user_profile.gd | 16 +- .../mod_loader/resources/options_profile.gd | 3 - 12 files changed, 541 insertions(+), 513 deletions(-) diff --git a/addons/mod_loader/api/config.gd b/addons/mod_loader/api/config.gd index 45a54334..38d81d94 100644 --- a/addons/mod_loader/api/config.gd +++ b/addons/mod_loader/api/config.gd @@ -1,23 +1,25 @@ -# This Class provides functionality for working with per-mod Configurations. class_name ModLoaderConfig extends Object - +## +## Class for managing per-mod configurations. +## +## @tutorial(Creating a Mod Config Schema with JSON-Schemas): https://github.com/GodotModding/godot-mod-loader/wiki/Mod-Configs +## @tutorial(Config Schema): https://github.com/GodotModding/godot-mod-loader/wiki/config-json const LOG_NAME := "ModLoader:Config" const DEFAULT_CONFIG_NAME := "default" -# Creates a new configuration for a mod. -# -# Parameters: -# - mod_id (String): The ID of the mod for which the configuration is being created. -# - config_name (String): The name of the configuration. -# - config_data (Dictionary): The configuration data to be stored in the new configuration. -# -# Returns: -# - ModConfig: The created ModConfig object if successful, or null otherwise. +## Creates a new configuration for a mod.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod.[br] +## - [code]config_name[/code] ([String]): The name of the configuration.[br] +## - [code]config_data[/code] ([Dictionary]): The configuration data to be stored.[br] +## [br] +## [b]Returns:[/b][br] +## - [ModConfig]: The created ModConfig object if successful, or null otherwise. static func create_config(mod_id: String, config_name: String, config_data: Dictionary) -> ModConfig: - # Check if the config schema exists by retrieving the default config var default_config: ModConfig = get_default_config(mod_id) if not default_config: ModLoaderLog.error( @@ -44,7 +46,6 @@ static func create_config(mod_id: String, config_name: String, config_data: Dict # Create the config save path based on the config_name var config_file_path := _ModLoaderPath.get_path_to_mod_configs_dir(mod_id).path_join("%s.json" % config_name) - # Initialize a new ModConfig object with the provided parameters var mod_config := ModConfig.new( mod_id, @@ -69,13 +70,13 @@ static func create_config(mod_id: String, config_name: String, config_data: Dict return mod_config -# Updates an existing ModConfig object with new data and save the config file. -# -# Parameters: -# - config (ModConfig): The ModConfig object to be updated. -# -# Returns: -# - ModConfig: The updated ModConfig object if successful, or null otherwise. +## Updates an existing [ModConfig] object with new data and saves the config file.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]config[/code] ([ModConfig]): The [ModConfig] object to be updated.[br] +## [br] +## [b]Returns:[/b][br] +## - [ModConfig]: The updated [ModConfig] object if successful, or null otherwise. static func update_config(config: ModConfig) -> ModConfig: # Validate the config and check for any validation errors var error_message := config.validate() @@ -101,13 +102,13 @@ static func update_config(config: ModConfig) -> ModConfig: return config -# Deletes a ModConfig object and performs cleanup operations. -# -# Parameters: -# - config (ModConfig): The ModConfig object to be deleted. -# -# Returns: -# - bool: True if the deletion was successful, False otherwise. +## Deletes a [ModConfig] object and performs cleanup operations.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]config[/code] ([ModConfig]): The [ModConfig] object to be deleted.[br] +## [br] +## [b]Returns:[/b][br] +## - [code]bool[/code]: True if the deletion was successful, False otherwise. static func delete_config(config: ModConfig) -> bool: # Check if the config is the "default" config, which cannot be deleted if config.name == DEFAULT_CONFIG_NAME: @@ -116,7 +117,6 @@ static func delete_config(config: ModConfig) -> bool: # Change the current config to the "default" config set_current_config(get_default_config(config.mod_id)) - # Remove the config file from the Mod Config directory var is_remove_success := config.remove_file() @@ -125,26 +125,25 @@ static func delete_config(config: ModConfig) -> bool: # Remove the config from ModData ModLoaderStore.mod_data[config.mod_id].configs.erase(config.name) - + return true -# Sets the current configuration of a mod to the specified configuration. -# -# Parameters: -# - config (ModConfig): The ModConfig object to be set as current config. +## Sets the current configuration of a mod to the specified configuration.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]config[/code] ([ModConfig]): The [ModConfig] object to be set as current config. static func set_current_config(config: ModConfig) -> void: ModLoaderStore.mod_data[config.mod_id].current_config = config -# Returns the schema for the specified mod id. -# If no configuration file exists for the mod, an empty dictionary is returned. -# -# Parameters: -# - mod_id (String): the ID of the mod to get the configuration schema for -# -# Returns: -# - A dictionary representing the schema for the mod's configuration file +## Returns the schema for the specified mod id.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] (String): the ID of the mod.[br] +## [br] +## [b]Returns:[/b][br] +## - A dictionary representing the schema for the mod's configuration file. static func get_config_schema(mod_id: String) -> Dictionary: # Get all config files for the specified mod var mod_configs := get_configs(mod_id) @@ -157,15 +156,14 @@ static func get_config_schema(mod_id: String) -> Dictionary: return mod_configs.default.schema -# Retrieves the schema for a specific property key. -# -# 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` -# -# Returns: -# - Dictionary: The schema dictionary for the specified property. +## Retrieves the schema for a specific property key.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]config[/code] ([ModConfig]): The [ModConfig] object from which to retrieve the schema.[br] +## - [code]prop[/code] ([String]): The property key for which to retrieve the schema.[br] +## [br] +## [b]Returns:[/b][br] +## - [Dictionary]: The schema dictionary for the specified property. static func get_schema_for_prop(config: ModConfig, prop: String) -> Dictionary: # Split the property string into an array of property keys var prop_array := prop.split(".") @@ -185,16 +183,16 @@ static func get_schema_for_prop(config: ModConfig, prop: String) -> Dictionary: return schema_for_prop -# Recursively traverses the schema dictionary based on the provided prop_key_array -# and returns the corresponding schema for the target property. -# -# Parameters: -# - schema_prop: The current schema dictionary to traverse. -# - prop_key_array: An array containing the property keys representing the path to the target property. -# -# Returns: -# The schema dictionary corresponding to the target property specified by the prop_key_array. -# If the target property is not found, an empty dictionary is returned. +## Recursively traverses the schema dictionary based on the provided [code]prop_key_array[/code] +## and returns the corresponding schema for the target property.[br] +##[br] +## [b]Parameters:[/b][br] +## - [code]schema_prop[/code]: The current schema dictionary to traverse.[br] +## - [code]prop_key_array[/code]: An array containing the property keys representing the path to the target property.[br] +##[br] +## [b]Returns:[/b][br] +## The schema dictionary corresponding to the target property specified by the [code]prop_key_array[/code].[br] +## If the target property is not found, an empty dictionary is returned. static func _traverse_schema(schema_prop: Dictionary, prop_key_array: Array) -> Dictionary: # Return the current schema_prop if the prop_key_array is empty (reached the destination property) if prop_key_array.is_empty(): @@ -215,14 +213,14 @@ static func _traverse_schema(schema_prop: Dictionary, prop_key_array: Array) -> schema_prop = schema_prop.properties schema_prop = _traverse_schema(schema_prop, prop_key_array) - + return schema_prop -# Retrieves an Array of mods that have configuration files. -# -# Returns: -# An Array containing the mod data of mods that have configuration files. +## Retrieves an Array of mods that have configuration files.[br] +## [br] +## [b]Returns:[/b][br] +## - An Array containing the mod data of mods that have configuration files. static func get_mods_with_config() -> Array: # Create an empty array to store mods with configuration files var mods_with_config := [] @@ -241,14 +239,14 @@ static func get_mods_with_config() -> Array: return mods_with_config -# Retrieves the configurations dictionary for a given mod ID. -# -# Parameters: -# - mod_id: The ID of the mod for which to retrieve the configurations. -# -# Returns: -# A dictionary containing the configurations for the specified mod. -# If the mod ID is invalid or no configurations are found, an empty dictionary is returned. +## Retrieves the configurations dictionary for a given mod ID.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code]: The ID of the mod.[br] +## [br] +## [b]Returns:[/b][br] +## - A dictionary containing the configurations for the specified mod. +## If the mod ID is invalid or no configurations are found, an empty dictionary is returned. static func get_configs(mod_id: String) -> Dictionary: # Check if the mod ID is invalid if not ModLoaderStore.mod_data.has(mod_id): @@ -265,15 +263,14 @@ static func get_configs(mod_id: String) -> Dictionary: return config_dictionary -# Retrieves the configuration for a specific mod and configuration name. -# Returns the configuration as a ModConfig object or null if not found. -# -# Parameters: -# - mod_id (String): The ID of the mod to retrieve the configuration for. -# - config_name (String): The name of the configuration to retrieve. -# -# Returns: -# The configuration as a ModConfig object or null if not found. +## Retrieves the configuration for a specific mod and configuration name.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod.[br] +## - [code]config_name[/code] ([String]): The name of the configuration.[br] +## [br] +## [b]Returns:[/b][br] +## - The configuration as a [ModConfig] object or null if not found. static func get_config(mod_id: String, config_name: String) -> ModConfig: var configs := get_configs(mod_id) @@ -284,53 +281,50 @@ static func get_config(mod_id: String, config_name: String) -> ModConfig: return configs[config_name] -# Checks whether a mod has a current configuration set. -# This function is useful for determining if a mod has any configuration. -# If a mod has no current configuration, it should not have any. -# -# Parameters: -# - mod_id (String): The ID of the mod to check. -# -# Returns: -# - bool: True if the mod has a current configuration, False otherwise. +## Checks whether a mod has a current configuration set.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod.[br] +## [br] +## [b]Returns:[/b][br] +## - [code]bool[/code]: True if the mod has a current configuration, False otherwise. static func has_current_config(mod_id: String) -> bool: var mod_data := ModLoaderMod.get_mod_data(mod_id) return not mod_data.current_config == null -# Checks whether a mod has a configuration with the specified name. -# -# Parameters: -# - mod_id (String): The ID of the mod to check. -# - config_name (String): The name of the configuration to check for. -# -# Returns: -# - bool: True if the mod has a configuration with the specified name, False otherwise. +## Checks whether a mod has a configuration with the specified name.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod.[br] +## - [code]config_name[/code] ([String]): The name of the configuration.[br] +## [br] +## [b]Returns:[/b][br] +## - [code]bool[/code]: True if the mod has a configuration with the specified name, False otherwise. static func has_config(mod_id: String, config_name: String) -> bool: var mod_data := ModLoaderMod.get_mod_data(mod_id) return mod_data.configs.has(config_name) -# Retrieves the default configuration for a specified mod ID. -# -# Parameters: -# - mod_id: The ID of the mod for which to retrieve the default configuration. -# -# Returns: -# The ModConfig object representing the default configuration for the specified mod. -# If the mod ID is invalid or no configuration is found, returns null. -# +## Retrieves the default configuration for a specified mod ID.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code]: The ID of the mod.[br] +## [br] +## [b]Returns:[/b][br] +## - The [ModConfig] object representing the default configuration for the specified mod. +## If the mod ID is invalid or no configuration is found, returns null. static func get_default_config(mod_id: String) -> ModConfig: return get_config(mod_id, DEFAULT_CONFIG_NAME) -# Retrieves the currently active configuration for a specific mod -# -# Parameters: -# mod_id (String): The ID of the mod to retrieve the configuration for. -# -# Returns: -# The configuration as a ModConfig object or null if not found. +## Retrieves the currently active configuration for a specific mod.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod.[br] +## [br] +## [b]Returns:[/b][br] +## - The configuration as a [ModConfig] object or [code]null[/code] if not found. static func get_current_config(mod_id: String) -> ModConfig: var current_config_name := get_current_config_name(mod_id) var current_config: ModConfig @@ -345,14 +339,13 @@ static func get_current_config(mod_id: String) -> ModConfig: return current_config -# Retrieves the name of the current configuration for a specific mod -# Returns an empty string if no configuration exists for the mod or the user profile has not been loaded -# -# Parameters: -# mod_id (String): The ID of the mod to retrieve the current configuration name for. -# -# Returns: -# The currently active configuration name for the given mod id or an empty string if not found. +## Retrieves the name of the current configuration for a specific mod.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod.[br] +## [br] +## [b]Returns:[/b][br] +## - The currently active configuration name for the given mod id or an empty string if not found. static func get_current_config_name(mod_id: String) -> String: # Check if user profile has been loaded if not ModLoaderStore.current_user_profile or not ModLoaderStore.user_profiles.has(ModLoaderStore.current_user_profile.name): @@ -374,27 +367,27 @@ static func get_current_config_name(mod_id: String) -> String: return current_user_profile.mod_list[mod_id].current_config -# Refreshes the data of the provided configuration by reloading it from the config file. -# -# Parameters: -# - config (ModConfig): The ModConfig object whose data needs to be refreshed. -# -# Returns: -# - ModConfig: The ModConfig object with refreshed data if successful, or the original object otherwise. +## Refreshes the data of the provided configuration by reloading it from the config file.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]config[/code] ([ModConfig]): The [ModConfig] object whose data needs to be refreshed.[br] +## [br] +## [b]Returns:[/b][br] +## - [ModConfig]: The [ModConfig] object with refreshed data if successful, or the original object otherwise. static func refresh_config_data(config: ModConfig) -> ModConfig: # Retrieve updated configuration data from the config file var new_config_data := _ModLoaderFile.get_json_as_dict(config.save_path) # Update the data property of the ModConfig object with the refreshed data config.data = new_config_data - + return config -# Iterates over all mods to refresh the data of their current configurations, if available. -# Compares the previous configuration data with the refreshed data and emits the `current_config_changed` signal if changes are detected. -# -# This function ensures that any changes made to the configuration files outside the application -# are reflected within the application's runtime, allowing for dynamic updates without the need for a restart. +## Iterates over all mods to refresh the data of their current configurations, if available.[br] +## Compares the previous configuration data with the refreshed data and emits the `current_config_changed` signal if changes are detected.[br] +## [br] +## This function ensures that any changes made to the configuration files outside the application +## are reflected within the application's runtime, allowing for dynamic updates without the need for a restart. static func refresh_current_configs() -> void: for mod_id in ModLoaderMod.get_mod_data_all().keys(): # Skip if the mod has no config diff --git a/addons/mod_loader/api/deprecated.gd b/addons/mod_loader/api/deprecated.gd index 1ca5313f..edc7c61d 100644 --- a/addons/mod_loader/api/deprecated.gd +++ b/addons/mod_loader/api/deprecated.gd @@ -1,20 +1,22 @@ -# API methods for deprecating funcs. Can be used by mods with public APIs. class_name ModLoaderDeprecated -extends Node +extends Object +## +## API methods for deprecating funcs. Can be used by mods with public APIs. const LOG_NAME := "ModLoader:Deprecated" -# 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 +## Marks a method that has changed its name or class.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]old_method[/code] ([String]): The name of the deprecated method.[br] +## - [code]new_method[/code] ([String]): The name of the new method to use.[br] +## - [code]since_version[/code] ([String]): The version number from which the method has been deprecated.[br] +## - [code]show_removal_note[/code] ([bool]): (optional) If true, includes a note about future removal of the old method. Default is true.[br] +## [br] +## [b]Returns:[/b][br] +## - [code]void[/code] static func deprecated_changed(old_method: String, new_method: String, since_version: String, show_removal_note: bool = true) -> void: _deprecated_log(str( "DEPRECATED: ", @@ -24,15 +26,16 @@ static func deprecated_changed(old_method: String, new_method: String, since_ver )) -# 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 +## Marks a method that has been entirely removed, with no replacement.[br] +## Note: This should rarely be needed but is included for completeness.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]old_method[/code] ([String]): The name of the removed method.[br] +## - [code]since_version[/code] ([String]): The version number from which the method has been deprecated.[br] +## - [code]show_removal_note[/code] ([bool]): (optional) If true, includes a note about future removal of the old method. Default is true.[br] +## [br] +## [b]Returns:[/b][br] +## - [code]void[/code] static func deprecated_removed(old_method: String, since_version: String, show_removal_note: bool = true) -> void: _deprecated_log(str( "DEPRECATED: ", @@ -42,24 +45,26 @@ static func deprecated_removed(old_method: String, since_version: String, show_r )) -# 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 +## Marks a method with a freeform deprecation message.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]msg[/code] ([String]): The deprecation message.[br] +## - [code]since_version[/code] ([String]): (optional) The version number from which the deprecation applies.[br] +## [br] +## [b]Returns:[/b][br] +## - [code]void[/code] 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 function for logging deprecation messages with support to trigger warnings instead of fatal errors. -# -# Parameters: -# - msg (String): The deprecation message. -# -# Returns: void +## Internal function for logging deprecation messages with support to trigger warnings instead of fatal errors.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]msg[/code] ([String]): The deprecation message.[br] +## [br] +## [b]Returns:[/b][br] +## - [code]void[/code] static func _deprecated_log(msg: String) -> void: if ModLoaderStore and 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 31a68baa..c62b9f72 100644 --- a/addons/mod_loader/api/log.gd +++ b/addons/mod_loader/api/log.gd @@ -1,6 +1,8 @@ -# This Class provides methods for logging, retrieving logged data, and internal methods for working with log files. class_name ModLoaderLog -extends Node +extends Object +## +## 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" @@ -14,41 +16,41 @@ enum VERBOSITY_LEVEL { DEBUG, } -# This Sub-Class represents a log entry in ModLoader. +## This Sub-Class represents a log entry in ModLoader. class ModLoaderLogEntry: extends Resource - # Name of the mod or ModLoader class this entry refers to. + ## Name of the mod or ModLoader class this entry refers to. var mod_name: String - # The message of the log entry. + ## The message of the log entry. var message: String - # The log type, which indicates the verbosity level of this entry. + ## 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. + ## 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. + ## 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. + ## 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 + ## Initialize a ModLoaderLogEntry object with provided values.[br] + ##[br] + ## [b]Parameters:[/b][br] + ## - [code]_mod_name[/code] ([String]): Name of the mod or ModLoader class this entry refers to.[br] + ## - [code]_message[/code] ([String]): The message of the log entry.[br] + ## - [code]_type[/code] ([String]): The log type, which indicates the verbosity level of this entry.[br] + ## - [code]_time[/code] ([String]): The readable format of the time when this log entry was created.[br] + ##[br] + ## [b]Returns:[/b] [code]void[/code] func _init(_mod_name: String, _message: String, _type: String, _time: String) -> void: mod_name = _mod_name message = _message @@ -57,30 +59,30 @@ class ModLoaderLogEntry: time_stamp = Time.get_ticks_msec() - # Get the log entry as a formatted string. - # - # Returns: String + ## Get the log entry as a formatted string.[br] + ## [br] + ## [b]Returns:[/b] [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 + ## Get the prefix string for the log entry, including the log type and mod name.[br] + ## [br] + ## [b]Returns:[/b] [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 + ## Generate an MD5 hash of the log entry (prefix + message).[br] + ## [br] + ## [b]Returns:[/b] [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 + ## Get all log entries, including the current entry and entries in the stack.[br] + ## [br] + ## [b]Returns:[/b] [Array] func get_all_entries() -> Array: var entries := [self] entries.append_array(stack) @@ -92,101 +94,101 @@ class ModLoaderLogEntry: # ============================================================================= -# 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 +## Logs the error in red and a stack trace. Prefixed FATAL-ERROR.[br] +## [br] +## [i]Note: Stops the execution in editor[/i][br] +## [br] +## [b]Parameters:[/b][br] +## - [code]message[/code] ([String]): The message to be logged as an error.[br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with this log entry.[br] +## - [code]only_once[/code] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br] +## [br] +## [b]Returns:[/b] [code]void[/code] static func fatal(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "fatal-error", only_once) -# 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 +## Logs the message and pushes an error. Prefixed ERROR.[br] +## [br] +## [i]Note: Always logged[/i][br] +## [br] +## [b]Parameters:[/b][br] +## - [code]message[/code] ([String]): The message to be logged as an error.[br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with this log entry.[br] +## - [code]only_once[/code] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br] +## [br] +## [b]Returns:[/b] [code]void[/code] 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. -# -# *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 +## Logs the message and pushes a warning. Prefixed WARNING.[br] +## [br] +## [i]Note: Logged with verbosity level at or above warning (-v).[/i][br] +## [br] +## [b]Parameters:[/b][br] +## - [code]message[/code] ([String]): The message to be logged as a warning.[br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with this log entry.[br] +## - [code]only_once[/code] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br] +## [br] +## [b]Returns:[/b] [code]void[/code] static func warning(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "warning", only_once) -# 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 +## Logs the message. Prefixed INFO.[br] +## [br] +## [i]Note: Logged with verbosity level at or above info (-vv).[/i][br] +## [br] +## [b]Parameters:[/b][br] +## - [code]message[/code] ([String]): The message to be logged as an information.[br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with this log entry.[br] +## - [code]only_once[/code] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br] +## [br] +## [b]Returns:[/b] [code]void[/code] static func info(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "info", only_once) -# 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 +## Logs the message. Prefixed SUCCESS.[br] +## [br] +## [i]Note: Logged with verbosity level at or above info (-vv).[/i][br] +## [br] +## [b]Parameters:[/b][br] +## - [code]message[/code] ([String]): The message to be logged as a success.[br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with this log entry.[br] +## - [code]only_once[/code] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br] +## [br] +## [b]Returns:[/b] [code]void[/code] static func success(message: String, mod_name: String, only_once := false) -> void: _log(message, mod_name, "success", only_once) -# 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 +## Logs the message. Prefixed DEBUG.[br] +## [br] +## [i]Note: Logged with verbosity level at or above debug (-vvv).[/i][br] +## [br] +## [b]Parameters:[/b][br] +## - [code]message[/code] ([String]): The message to be logged as a debug.[br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with this log entry.[br] +## - [code]only_once[/code] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br] +## [br] +## [b]Returns:[/b] [code]void[/code] 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. -# -# *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 +## Logs the message formatted with [method JSON.print]. Prefixed DEBUG.[br] +## [br] +## [i]Note: Logged with verbosity level at or above debug (-vvv).[/i] [br] +## [br] +## [b]Parameters:[/b][br] +## - [code]message[/code] ([String]): The message to be logged as a debug.[br] +## - [code]json_printable[/code] (Variant): The variable to be formatted and printed using [method JSON.print].[br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with this log entry.[br] +## - [code]only_once[/code] ([bool]): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.[br] +## +## [b]Returns:[/b] [code]void[/code] static func debug_json_print(message: String, json_printable, mod_name: String, only_once := false) -> void: message = "%s\n%s" % [message, JSON.stringify(json_printable, " ")] _log(message, mod_name, "debug", only_once) @@ -196,73 +198,73 @@ static func debug_json_print(message: String, json_printable, mod_name: String, # ============================================================================= -# Returns an array of log entries as a resource. -# -# Returns: -# - Array: An array of log entries represented as resource. +## Returns an array of log entries as a resource.[br] +## [br] +## [b]Returns:[/b][br] +## - [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 a string. -# -# Returns: -# - Array: An array of log entries represented as strings. +## Returns an array of log entries as a string.[br] +## [br] +## [b]Returns:[/b][br] +## - [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 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. +## Returns an array of log entries as a resource for a specific mod_name.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with the log entries.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of log entries represented as resource for the specified [code]mod_name[/code]. static func get_by_mod_as_resource(mod_name: String) -> Array: return get_by_mod(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. +## Returns an array of log entries as a string for a specific mod_name.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with the log entries.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of log entries represented as strings for the specified [code]mod_name[/code]. 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 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. +## Returns an array of log entries as a resource for a specific type.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]type[/code] ([String]): The log type associated with the log entries.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of log entries represented as resource for the specified [code]type[/code]. static func get_by_type_as_resource(type: String) -> Array: return get_by_type(type) -# 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. +## Returns an array of log entries as a string for a specific type.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]type[/code] ([String]): The log type associated with the log entries.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of log entries represented as strings for the specified [code]type[/code]. 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. +## Returns an array of all log entries.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of all log entries. static func get_all() -> Array: var log_entries := [] @@ -277,13 +279,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. +## Returns an array of log entries for a specific mod_name.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_name[/code] ([String]): The name of the mod or ModLoader class associated with the log entries.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of log entries for the specified [code]mod_name[/code]. static func get_by_mod(mod_name: String) -> Array: var log_entries := [] @@ -298,13 +300,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. +## Returns an array of log entries for a specific type.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]type[/code] ([String]): The log type associated with the log entries.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of log entries for the specified [code]type[/code]. static func get_by_type(type: String) -> Array: var log_entries := [] @@ -315,13 +317,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. +## Returns an array of log entries represented as strings.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]log_entries[/code] ([Array]): An array of ModLoaderLogEntry Objects.[br] +## [br] +## [b]Returns:[/b][br] +## - [Array]: An array of log entries represented as strings. static func get_all_entries_as_string(log_entries: Array) -> Array: var log_entry_strings := [] @@ -332,6 +334,8 @@ static func get_all_entries_as_string(log_entries: Array) -> Array: return log_entry_strings + + # Internal log functions # ============================================================================= diff --git a/addons/mod_loader/api/mod.gd b/addons/mod_loader/api/mod.gd index c198aec2..9d4e0011 100644 --- a/addons/mod_loader/api/mod.gd +++ b/addons/mod_loader/api/mod.gd @@ -1,27 +1,29 @@ -# This Class provides helper functions to build mods. class_name ModLoaderMod extends Object +## +## This Class provides helper functions to build mods. +## +## @tutorial(Script Extensions): https://github.com/GodotModding/godot-mod-loader/wiki/Script-Extensions +## @tutorial(Mod Structure): https://github.com/GodotModding/godot-mod-loader/wiki/Mod-Structure +## @tutorial(Mod Files): https://github.com/GodotModding/godot-mod-loader/wiki/Mod-Files const LOG_NAME := "ModLoader:Mod" -# 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 +## Installs a script extension that extends a vanilla script.[br] +## The [code]child_script_path[/code] should point to your mod's extender script.[br] +## Example: [code]"MOD/extensions/singletons/utils.gd"[/code][br] +## Inside the extender script, include [code]extends {target}[/code] where [code]{target}[/code] is the vanilla path.[br] +## Example: [code]extends "res://singletons/utils.gd"[/code].[br] +## +## [b]Note:[/b] Your extender script doesn't have to follow the same directory path as the vanilla file, +## but it's good practice to do so.[br] +## +## [br][b]Parameters:[/b][br] +## - [code]child_script_path[/code] (String): The path to the mod's extender script.[br] +## +## [br][b]Returns:[/b] [code]void[/code][br] static func install_script_extension(child_script_path: String) -> void: var mod_id: String = _ModLoaderPath.get_mod_dir(child_script_path) @@ -40,31 +42,31 @@ static func install_script_extension(child_script_path: String) -> void: _ModLoaderScriptExtension.apply_extension(child_script_path) -# 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 +## Registers an array of classes to the global scope since Godot only does that in the editor.[br] +## +## Format: [code]{ "base": "ParentClass", "class": "ClassName", "language": "GDScript", "path": "res://path/class_name.gd" }[/code][br] +## +## [b]Note:[/b] You can find these easily in the project.godot file under `_global_script_classes` +## (but you should only include classes belonging to your mod)[br] +## +## [br][b]Parameters:[/b][br] +## - [code]new_global_classes[/code] (Array): An array of class definitions to be registered.[br] +## +## [br][b]Returns:[/b] [code]void[/code][br] 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. -# -# *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 +## Adds a translation file.[br] +##[br] +## [i]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 [code]mytranslation.en.translation[/code].[/i][br] +## +## [br][b]Parameters:[/b][br] +## - [code]resource_path[/code] (String): The path to the translation resource file.[br] +## +## [br][b]Returns:[/b] [code]void[/code][br] static func add_translation(resource_path: String) -> void: if not _ModLoaderFile.file_exists(resource_path): ModLoaderLog.fatal("Tried to load a position resource from a file that doesn't exist. The invalid path was: %s" % [resource_path], LOG_NAME) @@ -74,19 +76,20 @@ static func add_translation(resource_path: String) -> void: TranslationServer.add_translation(translation_object) ModLoaderLog.info("Added Translation from Resource -> %s" % resource_path, LOG_NAME) - -# Refreshes a specific scene by marking it for refresh. -# -# This function is useful if a script extension is not automatically applied. -# This situation can occur when a script is attached to a preloaded scene. -# If you encounter issues where your script extension is not working as expected, -# try to identify the scene to which it is attached and use this method to refresh it. -# This will reload already loaded scenes and apply the script extension. -# -# Parameters: -# - scene_path (String): The path to the scene file to be refreshed. -# -# Returns: void +## [i]Note: This function requires Godot 4.3 or higher.[/i][br] +##[br] +## Refreshes a specific scene by marking it for refresh.[br] +##[br] +## This function is useful if a script extension is not automatically applied. +## This situation can occur when a script is attached to a preloaded scene. +## If you encounter issues where your script extension is not working as expected, +## try to identify the scene to which it is attached and use this method to refresh it. +## This will reload already loaded scenes and apply the script extension. +##[br] +## [br][b]Parameters:[/b][br] +## - [code]scene_path[/code] (String): The path to the scene file to be refreshed. +##[br] +## [br][b]Returns:[/b] [code]void[/code][br] static func refresh_scene(scene_path: String) -> void: if scene_path in ModLoaderStore.scenes_to_refresh: return @@ -95,14 +98,14 @@ static func refresh_scene(scene_path: String) -> void: ModLoaderLog.debug("Added \"%s\" to be refreshed." % scene_path, LOG_NAME) -# Extends a specific scene by providing a callable function to modify it. -# The callable receives an instance of the vanilla_scene as the first parameter. -# -# Parameters: -# - scene_vanilla_path (String): The path to the vanilla scene file. -# - edit_callable (Callable): The callable function to modify the scene. -# -# Returns: void +## Extends a specific scene by providing a callable function to modify it. +## The callable receives an instance of the "vanilla_scene" as the first parameter.[br] +## +## [br][b]Parameters:[/b][br] +## - [code]scene_vanilla_path[/code] (String): The path to the vanilla scene file.[br] +## - [code]edit_callable[/code] (Callable): The callable function to modify the scene.[br] +## +## [br][b]Returns:[/b] [code]void[/code][br] static func extend_scene(scene_vanilla_path: String, edit_callable: Callable) -> void: if not ModLoaderStore.scenes_to_modify.has(scene_vanilla_path): ModLoaderStore.scenes_to_modify[scene_vanilla_path] = [] @@ -110,13 +113,13 @@ static func extend_scene(scene_vanilla_path: String, edit_callable: Callable) -> ModLoaderStore.scenes_to_modify[scene_vanilla_path].push_back(edit_callable) -# 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. +## Gets the [ModData] from the provided namespace.[br] +## +## [br][b]Parameters:[/b][br] +## - [code]mod_id[/code] (String): The ID of the mod.[br] +## +## [br][b]Returns:[/b][br] +## - [ModData]: The [ModData] associated with the provided [code]mod_id[/code], or null if the [code]mod_id[/code] is invalid.[br] 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) @@ -125,29 +128,29 @@ static func get_mod_data(mod_id: String) -> ModData: return ModLoaderStore.mod_data[mod_id] -# Gets the ModData of all loaded Mods as Dictionary. -# -# Returns: -# - Dictionary: A dictionary containing the ModData of all loaded mods. +## Gets the [ModData] of all loaded Mods as [Dictionary].[br] +## +## [br][b]Returns:[/b][br] +## - [Dictionary]: A dictionary containing the [ModData] of all loaded mods.[br] static func get_mod_data_all() -> Dictionary: return ModLoaderStore.mod_data -# Returns the path to the directory where unpacked mods are stored. -# -# Returns: -# - String: The path to the unpacked mods directory. +## Returns the path to the directory where unpacked mods are stored.[br] +## +## [br][b]Returns:[/b][br] +## - [String]: The path to the unpacked mods directory.[br] static func get_unpacked_dir() -> String: return _ModLoaderPath.get_unpacked_mods_dir_path() -# 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. +## Returns true if the mod with the given [code]mod_id[/code] was successfully loaded.[br] +## +## [br][b]Parameters:[/b][br] +## - [code]mod_id[/code] (String): The ID of the mod.[br] +## +## [br][b]Returns:[/b][br] +## - [bool]: true if the mod is loaded, false otherwise.[br] static func is_mod_loaded(mod_id: String) -> bool: if ModLoaderStore.is_initializing: ModLoaderLog.warning( diff --git a/addons/mod_loader/api/profile.gd b/addons/mod_loader/api/profile.gd index b610ab42..5554565c 100644 --- a/addons/mod_loader/api/profile.gd +++ b/addons/mod_loader/api/profile.gd @@ -1,6 +1,7 @@ -# 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" @@ -13,36 +14,36 @@ const FILE_PATH_USER_PROFILES := "user://mod_user_profiles.json" # ============================================================================= -# 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: +## Enables a mod - it will be loaded on the next game start[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod to enable.[br] +## - [code]user_profile[/code] ([ModUserProfile]): (Optional) The user profile to enable the mod for. Default is the current user profile.[br] +## [br] +## [b]Returns:[/b] [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 +## Disables a mod - it will not be loaded on the next game start[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod to disable.[br] +## - [code]user_profile[/code] ([ModUserProfile]): (Optional) The user profile to disable the mod for. Default is the current user profile.[br] +## [br] +## [b]Returns:[/b] [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 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 +## Sets the current config for a mod in a user profile's mod_list.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]mod_id[/code] ([String]): The ID of the mod.[br] +## - [code]mod_config[/code] ([ModConfig]): The mod config to set as the current config.[br] +## - [code]user_profile[/code] ([ModUserProfile]): (Optional) The user profile to update. Default is the current user profile.[br] +## [br] +## [b]Returns:[/b] [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): @@ -60,12 +61,12 @@ static func set_mod_current_config(mod_id: String, mod_config: ModConfig, user_p return is_save_success -# 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 +## Creates a new user profile with the given name, using the currently loaded mods as the mod list.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]profile_name[/code] ([String]): The name of the new user profile (must be unique).[br] +## [br] +## [b]Returns:[/b] [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): @@ -95,12 +96,12 @@ static func create_profile(profile_name: String) -> bool: return is_save_success -# 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 +## Sets the current user profile to the given user profile.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]user_profile[/code] ([ModUserProfile]): The user profile to set as the current profile.[br] +## [br] +## [b]Returns:[/b] [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): @@ -119,12 +120,12 @@ static func set_profile(user_profile: ModUserProfile) -> bool: return is_save_success -# Deletes the given user profile. -# -# Parameters: -# - user_profile (ModUserProfile): The user profile to delete. -# -# Returns: bool +## Deletes the given user profile.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]user_profile[/code] ([ModUserProfile]): The user profile to delete.[br] +## [br] +## [b]Returns:[/b] [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: @@ -154,19 +155,19 @@ static func delete_profile(user_profile: ModUserProfile) -> bool: return is_save_success -# Returns the current user profile. -# -# Returns: ModUserProfile +## Returns the current user profile.[br] +## [br] +## [b]Returns:[/b] [ModUserProfile] static func get_current() -> ModUserProfile: return ModLoaderStore.current_user_profile -# 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 +## Returns the user profile with the given name.[br] +## [br] +## [b]Parameters:[/b][br] +## - [code]profile_name[/code] ([String]): The name of the user profile to retrieve.[br] +## [br] +## [b]Returns:[/b] [ModUserProfile] or [code]null[/code] 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) @@ -175,9 +176,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: Array of ModUserProfile Objects +## Returns an array containing all user profiles stored in ModLoaderStore.[br] +## [br] +## [b]Returns:[/b] [Array] of [ModUserProfile] Objects static func get_all_as_array() -> Array: var user_profiles := [] diff --git a/addons/mod_loader/mod_loader.gd b/addons/mod_loader/mod_loader.gd index 61b176c2..c64efa55 100644 --- a/addons/mod_loader/mod_loader.gd +++ b/addons/mod_loader/mod_loader.gd @@ -1,4 +1,4 @@ -# ModLoader - A mod loader for GDScript +## ModLoader - A mod loader for GDScript # # Written in 2021 by harrygiel , # in 2021 by Mariusz Chwalba , @@ -20,10 +20,13 @@ extends Node -signal logged(entry) -signal current_config_changed(config) +## Emitted if something is logged with [ModLoaderLog] +signal logged(entry: ModLoaderLog.ModLoaderLogEntry) +## Emitted if the [member ModData.current_config] of any mod changed. +## Use the [member ModConfig.mod_id] of the [ModConfig] to check if the config of your mod has changed. +signal current_config_changed(config: ModConfig) + -# Prefix for this file when using mod_log or dev_log const LOG_NAME := "ModLoader" diff --git a/addons/mod_loader/mod_loader_store.gd b/addons/mod_loader/mod_loader_store.gd index 2e107bf1..eed2c653 100644 --- a/addons/mod_loader/mod_loader_store.gd +++ b/addons/mod_loader/mod_loader_store.gd @@ -2,8 +2,8 @@ extends Node # ModLoaderStore -# Singleton (autoload) for storing data. Should be added before ModLoader, -# as an autoload called `ModLoaderStore` +## Singleton (autoload) for storing data. Should be added before ModLoader, +## as an autoload called `ModLoaderStore` # Constants diff --git a/addons/mod_loader/resources/mod_config.gd b/addons/mod_loader/resources/mod_config.gd index 1ee72d97..9039a018 100644 --- a/addons/mod_loader/resources/mod_config.gd +++ b/addons/mod_loader/resources/mod_config.gd @@ -1,22 +1,26 @@ class_name ModConfig extends Resource +## +## This Class is used to represent a configuration for a mod.[br] +## The Class provides functionality to initialize, validate, save, and remove a mod's configuration. +## +## @tutorial(Creating a Mod Config Schema with JSON-Schemas): https://github.com/GodotModding/godot-mod-loader/wiki/Mod-Configs +## @tutorial(Config Schema): https://github.com/GodotModding/godot-mod-loader/wiki/config-json -# This Class is used to represent a configuration for a mod. -# The Class provides functionality to initialize, validate, save, and remove a mod's configuration. const LOG_NAME := "ModLoader:ModConfig" -# Name of the config - must be unique +## Name of the config - must be unique var name: String -# The mod_id this config belongs to +## The mod_id this config belongs to var mod_id: String -# The JSON-Schema this config uses for validation +## The JSON-Schema this config uses for validation var schema: Dictionary -# The data this config holds +## The data this config holds var data: Dictionary -# The path where the JSON file for this config is stored +## The path where the JSON file for this config is stored var save_path: String -# False if any data is invalid +## False if any data is invalid var valid := false @@ -67,13 +71,13 @@ func is_valid() -> bool: return false -# Saves the config data to the config file +## Saves the config data to the config file func save_to_file() -> bool: var is_success := _ModLoaderFile.save_dictionary_to_json_file(data, save_path) return is_success -# Removes the config file +## Removes the config file func remove_file() -> bool: var is_success := _ModLoaderFile.remove_file(save_path) return is_success diff --git a/addons/mod_loader/resources/mod_data.gd b/addons/mod_loader/resources/mod_data.gd index c76be258..968e5f06 100644 --- a/addons/mod_loader/resources/mod_data.gd +++ b/addons/mod_loader/resources/mod_data.gd @@ -1,8 +1,9 @@ class_name ModData extends Resource +## +## Stores and validates all Data required to load a mod successfully +## If some of the data is invalid, [member is_loadable] will be false -# Stores and validates all Data required to load a mod successfully -# If some of the data is invalid, [member is_loadable] will be false const LOG_NAME := "ModLoader:ModData" @@ -33,31 +34,33 @@ enum sources { STEAM_WORKSHOP, } -# Name of the Mod's zip file +## Name of the Mod's zip file var zip_name := "" -# Path to the Mod's zip file +## Path to the Mod's zip file var zip_path := "" -# Directory of the mod. Has to be identical to [method ModManifest.get_mod_id] +## Directory of the mod. Has to be identical to [method ModManifest.get_mod_id] var dir_name := "" -# Path to the Mod's Directory +## Path to the Mod's Directory var dir_path := "" -# False if any data is invalid +## False if any data is invalid var is_loadable := true -# True if overwrites.gd exists +## True if overwrites.gd exists var is_overwrite := false -# True if mod can't be disabled or enabled in a user profile +## True if mod can't be disabled or enabled in a user profile var is_locked := false -# Flag indicating whether the mod should be loaded +## Flag indicating whether the mod should be loaded var is_active := true -# Is increased for every mod depending on this mod. Highest importance is loaded first +## Is increased for every mod depending on this mod. Highest importance is loaded first var importance := 0 -# Contents of the manifest +## Contents of the manifest var manifest: ModManifest # Updated in load_configs +## All mod configs var configs := {} +## The currently applied mod config var current_config: ModConfig: set = _set_current_config -# Specifies the source from which the mod has been loaded +## Specifies the source from which the mod has been loaded var source: int # only set if DEBUG_ENABLE_STORING_FILEPATHS is enabled diff --git a/addons/mod_loader/resources/mod_manifest.gd b/addons/mod_loader/resources/mod_manifest.gd index a1a2075a..cb155e6a 100644 --- a/addons/mod_loader/resources/mod_manifest.gd +++ b/addons/mod_loader/resources/mod_manifest.gd @@ -1,39 +1,44 @@ class_name ModManifest extends Resource +## +## Stores and validates contents of the manifest set by the user -# Stores and validates contents of the manifest set by the user const LOG_NAME := "ModLoader:ModManifest" -# Mod name. # Validated by [method is_name_or_namespace_valid] +## Mod name. var name := "" -# Mod namespace, most commonly the main author. # Validated by [method is_name_or_namespace_valid] +## Mod namespace, most commonly the main author. var mod_namespace := "" -# Semantic version. Not a number, but required to be named like this by Thunderstore # Validated by [method is_semver_valid] +## Semantic version. Not a number, but required to be named like this by Thunderstore var version_number := "0.0.0" var description := "" var website_url := "" -# Used to determine mod load order +## Used to determine mod load order var dependencies: PackedStringArray = [] -# Used to determine mod load order +## Used to determine mod load order var optional_dependencies: PackedStringArray = [] - +## only used for information var authors: PackedStringArray = [] -# only used for information +## only used for information var compatible_game_version: PackedStringArray = [] -# only used for information # Validated by [method _handle_compatible_mod_loader_version] +## only used for information var compatible_mod_loader_version: PackedStringArray = [] -# only used for information +## only used for information var incompatibilities: PackedStringArray = [] +## Used to determine mod load order var load_before: PackedStringArray = [] +## only used for information var tags : PackedStringArray = [] +## Schema for mod configs var config_schema := {} var description_rich := "" var image: CompressedTexture2D +## only used for information var steam_workshop_id := "" # Required keys in a mod's manifest.json file diff --git a/addons/mod_loader/resources/mod_user_profile.gd b/addons/mod_loader/resources/mod_user_profile.gd index de485d20..fe381d1e 100644 --- a/addons/mod_loader/resources/mod_user_profile.gd +++ b/addons/mod_loader/resources/mod_user_profile.gd @@ -1,10 +1,20 @@ -extends Resource class_name ModUserProfile +extends Resource +## +## This Class is used to represent a User Profile for the ModLoader. -# This Class is used to represent a User Profile for the ModLoader. - +## The name of the profile var name := "" +## A list of all installed mods +## [codeblock] +## "mod_list": { +## "Namespace-ModName": { +## "current_config": "default", +## "is_active": false, +## "zip_path": "", +## }, +## [/codeblock] var mod_list := {} diff --git a/addons/mod_loader/resources/options_profile.gd b/addons/mod_loader/resources/options_profile.gd index 10062150..7236a517 100644 --- a/addons/mod_loader/resources/options_profile.gd +++ b/addons/mod_loader/resources/options_profile.gd @@ -1,9 +1,6 @@ class_name ModLoaderOptionsProfile extends Resource -# export (String) var my_string := "" -# export (Resource) var upgrade_to_process_icon = null -# export (Array, Resource) var elites: = [] @export var enable_mods: bool = true @export var locked_mods: Array[String] = []