Skip to content

ModLoaderMod

Darkly77 edited this page Jun 30, 2023 · 10 revisions

ModLoaderMod

Extends: Object

Description

This Class provides helper functions to build mods.

Methods Overview

Method Description
install_script_extension Install a script extension that extends a vanilla script. The child_script_path should point to your mod's extender script.
uninstall_script_extension Uninstall a script extension.
register_global_classes_from_array Register an array of classes to the global scope, since Godot only does that in the editor.
add_translation Add a translation file.
get_mod_data Gets the ModData from the provided namespace
get_mod_data_all Gets the ModData of all loaded Mods as Dictionary.
is_mod_loaded Returns true if the mod with the given mod_id was successfully loaded.
append_node_in_scene Appends a new node to a modified scene.
save_scene Saves a modified scene to a file.
get_unpacked_dir Returns the path to the directory where unpacked mods are stored.

Mod Manager

Note: This section does not belong here, and needs to be moved.

Methods Overview

Method Description
reload_mods Reload all mods.
disable_mods Disable all mods.
disable_mod Disable a mod.

Method Descriptions

reload_mods

func reload_mods() -> void

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

Returns: void

disable_mods

func disable_mods() -> void

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

Returns: void

disable_mod

func disable_mod(mod_data: ModData) -> void

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

Parameters:

  • mod_data (ModData): The ModData object representing the mod to be disabled.

Returns: void

install_script_extension (static)

func install_script_extension(child_script_path: String) -> void

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

uninstall_script_extension (static)

func uninstall_script_extension(extension_script_path: String) -> void

Uninstall a script extension.

Parameters:

  • extension_script_path (String): The path to the extension script to be uninstalled.

Returns: void

register_global_classes_from_array (static)

func register_global_classes_from_array(new_global_classes: Array) -> void

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

add_translation (static)

func add_translation(resource_path: String) -> void

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

get_mod_data (static)

func get_mod_data(mod_id: String) -> ModData

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.

get_mod_data_all (static)

func get_mod_data_all() -> Dictionary

Gets the ModData of all loaded Mods as Dictionary.

Returns:

  • Dictionary: A dictionary containing the ModData of all loaded mods.

is_mod_loaded (static)

func is_mod_loaded(mod_id: String) -> bool

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.

append_node_in_scene (static)

func append_node_in_scene(modified_scene: Node, node_name: String = "", node_parent = null, instance_path: String = "", is_visible: bool = true) -> void

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

save_scene (static)

func save_scene(modified_scene: Node, scene_path: String) -> void

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

get_unpacked_dir (static)

func get_unpacked_dir() -> String

Returns the path to the directory where unpacked mods are stored.

Returns:

  • String: The path to the unpacked mods directory.

Constants Descriptions

LOG_NAME

const LOG_NAME: String = "ModLoader:Mod"
Clone this wiki locally