Skip to content

API Methods

Darkly77 edited this page Jan 16, 2023 · 28 revisions

Use these when creating your mods. See the docs for Delta-V Modding for more details.

Overview

Method Description
mod_log Log data to godot.log.
dev_log Log verbose data to godot.log. Only shows if dev logging is enabled
install_script_extension Extend a vanilla script
add_translation_from_resource Import a translation file (eg mod_text.en.translation)
append_node_in_scene Create and add a node to a instanced scene
save_scene Save the scene as a PackedScene, overwriting Godot's cache if needed
get_mod_config Get data from a mod's config JSON file

Logging

mod_log

func mod_log(text:String, mod_name:String = "Unknown-Mod", pretty:bool = false)->void

Log data to godot.log.. The mod ID should be provided as the 2nd arg.

dev_log

func dev_log(text:String, mod_name:String = "Unknown-Mod", pretty:bool = false)

Logs verbose info to godot.log, but only if developer logging is enabled, either via the CLI arg --log-dev or by temporarily changing the DEBUG_ENABLE_DEV_LOG to true.

Setup

install_script_extension

func install_script_extension(child_script_path:String)

Add a script that extends a vanilla script. This allows you to overwrite funcs, extend them, and add your own. See Script Inheritance in the Delta-V modding readme for more info on usage.

child_script_path is the path to your mod's extender script path, 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".

Your extender scripts don't have to follow the same directory path as the vanilla file, but it's good practice to do so.

One approach to organising your extender scripts is to put them in a dedicated folder named "extensions", eg:

yourmod.zip
├───.import
└───mods-unpacked
    └───Author-ModName
        ├───mod_main.gd
        ├───manifest.json
        └───extensions
            └───Any files that extend vanilla code can go here, eg:
            ├───main.gd
            └───singletons
                ├───item_service.gd
                └───debug_service.gd

add_translation_from_resource

add_translation_from_resource(resource_path: String)

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.

Note that this function is exclusive to ModLoader, and departs from Delta-V's two functions addTranslationsFromCSV and addTranslationsFromJSON, which aren't available in ModLoader.

append_node_in_scene

append_node_in_scene(modified_scene, node_name:String = "", node_parent = null, instance_path:String = "", is_visible:bool = true)

Create and add a node to a instanced scene.

save_scene

save_scene(modified_scene, scenePath:String)

Save the scene as a PackedScene, overwriting Godot's cache if needed.

General

get_mod_config

get_mod_config(mod_id:String = "", key:String = "", default_value = null)->Dictionary:

Get data from a mod's config JSON file. Does not return the data directly.

Returns a dictionary with three keys: data, error, and error_msg. These are explained below.

Example

# Note the use of .data here
var do_thing = ModLoader.get_mod_config("AuthorName-ModName", "my_setting").data

Data

Data (data) is either the full config, or data from a specific key if one was specified.

If no user config JSON exists, data uses the defaults set in the mod's manifest.json (see Config JSON below). Returns an empty dictionary ({}) if either a) the mod's manifest.json has no defaults, or b) the specified key doesn't exist.

Error

Error (error) is 0 if there were no errors, or > 0 if the setting could not be retrieved:

# Description Data
0 No errors As requested
1 Invalid mod_id {}
2 No custom JSON exists Defaults from manifest.json
3 Invalid key. Custom JSON does not exist {}
4 Invalid key. Custom JSON does exist {}

Error Msg

Text representation of the error that occurred, intended to make debugging easier.

Clone this wiki locally