Skip to main content

ModSystem

See the code at autoload/mod_system.gd

Description

Inherits Node

The ModSystem class is a singleton that handles the management of mods within the game. It provides methods for installing, enabling, disabling, granting, and revoking mods. The ModSystem is responsible for maintaining the state of mods and their instances, as well as facilitating communication between mods and the game objects they affect.


Signals

mod_installed

signal mod_installed(mod: Mod)

This signal is emitted when a mod is installed with the Mod System.

Parameters

NameTypeDescription
modModThe installed mod.

mod_uninstalled

signal mod_uninstalled(mod: Mod)

This signal is emitted when a mod is uninstalled from the Mod System.

Parameters

NameTypeDescription
modModThe uninstalled mod.

mod_enabled

signal mod_enabled(mod: Mod)

This signal is emitted when a mod is enabled.

Parameters

NameTypeDescription
modModThe enabled mod.

mod_disabled

signal mod_disabled(mod: Mod)

This signal is emitted when a mod is disabled.

Parameters

NameTypeDescription
modModThe disabled mod.

mod_granted

signal mod_granted(instance: ModInstance)

This signal is emitted when a mod is granted to an object.

Parameters

NameTypeDescription
instanceModInstanceThe granted mod instance.

mod_revoked

signal mod_revoked(instance: ModInstance)

This signal is emitted when a mod is revoked from an object.

Parameters

NameTypeDescription
instanceModInstanceThe revoked mod instance.

Properties

installed_mods

var installed_mods: Array[Mod]

An array that holds the installed mods.

TypeArray[Mod]
Default[]

settings

var settings: ModSettings

An instance of the ModSettings class, stores the user's configuration settings for the Mod System.

Note: This is automatically loaded (or created, if none are found) on game start.

TypeModSettings
DefaultLoaded instance of ModSettings

Methods

initialize

func initialize(mod_owner: Object) -> void

Initializes the Mod System for accepting mods in the specified mod_owner object.

This method registers the mod_owner object with the ModClassDB and grants all possible mods to the object.

Parameters

NameTypeDescription
mod_ownerObjectThe object to initialize for mods.

Returns

void


install

func install(mod: Mod) -> void

Installs a mod to the Mod System.

This method adds the specified mod to the installed_mods array. The mod_installed signal is emitted after successful registration.

Parameters

NameTypeDescription
modModThe mod to install.

Returns

void


uninstall

func uninstall(mod: Mod) -> void

Uninstalls a mod from the Mod System.

This method removes the specified mod from the installed_mods array. The mod_uninstalled signal is emitted after successful unregistration.

Parameters

NameTypeDescription
modModThe mod to uninstall.

Returns

void


enable

func enable(mod: Mod) -> void

Enables a mod.

This method enables the specified mod and emits the mod_enabled signal.

Parameters

NameTypeDescription
modModThe mod to enable.

Returns

void


disable

func disable(mod: Mod) -> void

Disables a mod.

This method disables the specified mod and emits the mod_disabled signal.

Parameters

NameTypeDescription
modModThe mod to disable.

Returns

void


enable_all

func enable_all() -> void

Enables all installed mods.

This method enables all mods in the installed_mods array and emits the mod_enabled signal for each enabled mod.

Returns

void


disable_all

func disable_all() -> void

Disables all installed mods.

This method disables all mods in the installed_mods array and emits the mod_disabled signal for each disabled mod.

Returns

void


grant

func grant(mod: Mod, mod_owner: Object) -> void

Grants a mod to an object.

This method grants the specified mod to the specified mod_owner object and emits the mod_granted signal.

Parameters

NameTypeDescription
modModThe mod to grant.
mod_ownerObjectThe object in which to grant the mod.

Returns

void


grant_all

func grant_all(mod_owner: Object) -> void

Grants all possible mods to an object.

This method grants all possible mods to the specified mod_owner object and emits the mod_granted signal for each granted mod.

Parameters

NameTypeDescription
mod_ownerObjectThe object in which to grant the mods.

Returns

void


revoke

func revoke(mod: Mod, mod_owner: Object) -> void

Revokes a mod from an object.

This method revokes the specified mod from the specified mod_owner object and emits the mod_revoked signal.

Parameters

NameTypeDescription
modModThe mod to revoke.
mod_ownerObjectThe object from which to revoke the mod.

Returns

void


revoke_all

func revoke_all(mod_owner: Object) -> void

Revokes all possible mods from an object.

This method revokes all possible mods from the specified mod_owner object and emits the mod_revoked signal for each revoked mod.

Parameters

NameTypeDescription
mod_ownerObjectThe object from which to revoke the mods.

Returns

void


get_grantable_mods

func get_grantable_mods(mod_owner: Object) -> Array[Mod]

Returns an array of all mods that can be granted to the specified object.

This method searches the installed_mods array and returns all mods where the Mod.grantable_owners property contains the name of the registered class of the mod_owner object.

Parameters

NameTypeDescription
mod_ownerObjectThe object for which to retrieve grantable mods.

Returns

TypeArray[Mod]
DescriptionAn array of grantable mods.

get_mod_by_id

func get_mod_by_id(id: String) -> Mod

Retrieves a mod by its ID.

This method searches the installed_mods array and returns the mod with the matching ID (see Mod.get_identifier()).

Parameters

NameTypeDescription
idStringThe ID of the mod to retrieve.

Returns

TypeMod
DescriptionThe mod with the specified ID.