Skip to main content

ModContentLoader

See the code at utils/content_loader.gd

Description

Inherits Resource

This class is sort of like a combination of FileAccess, ResourceLoader, and ZipReader. It handles loading resources, images, scripts, JSON, etc with a unified API. This helps to abstract file system stuff, as it can get overly complex accounting for all different loading methods.


Constants

enum Mode

enum Mode {
FILE,
ZIP,
}

Mode.FILE

The files to be loaded exist in the file system. All loading will be done with FileAccess and ResourceLoader.

Mode.ZIP

The files to be loaded exist in a zip file. All loading will be done with ZIPreader (see ModZipReader).


Properties

mode

var mode: Mode = Mode.FILE

Defines the mode that files will be loaded.

TypeMode
DefaultMode.FILE

zip_reader

var zip_reader: ModZipReader

If not null, will be used to load files inside a ZIP.

Note: Only applicable is mode is Mode.ZIP.

TypeModZipReader
Defaultnull

Methods

new_zip

static func new_zip(reader: ModZipReader) -> ModContentLoader

Instantiates a new ModContentLoader with the given ModZipReader and a mode of Mode.ZIP.

Note: This is a static method, intended to be called directly on the ModContentLoader class.

Parameters

NameTypeDescription
readerModZipReaderThe ZIP reader to use when loading files.

Returns

TypeModContentLoader
DescriptionThe new content loader.

exists

func exists(path: String) -> bool

Checks if a file exists at the given path.

Parameters

NameTypeDescription
pathStringThe path to check.

Returns

Typebool
Descriptiontrue if there is a non-empty file at the given path.

load_bytes

func load_bytes(path: String) -> PackedByteArray

Loads the contents of the file as a PackedByteArray.


load_string

func load_string(path: String) -> String

Loads the contents of the file as a String.

Parameters

NameTypeDescription
pathStringThe path to load from.

Returns

TypeString
DescriptionThe contents of the file, if it exists. Otherwise, an empty string.

load_json

func load_json(path: String) -> Dictionary

Loads the contents of the file as a JSON Dictionary.

Parameters

NameTypeDescription
pathStringThe path to load from.

Returns

TypeDictionary
DescriptionThe JSON at the given path, if it exists. Otherwise, an empty dictionary.

load_resource

func load_resource(path: String) -> Resource

Loads the file as a Resource.

Parameters

NameTypeDescription
pathStringThe path to load from.

Returns

TypeResource
DescriptionThe resource at the given path, if it exists. Otherwise, null.

load_script

func load_script(path: String) -> GDScript

Loads the file as a GDScript.

Parameters

NameTypeDescription
pathStringThe path to load from.

Returns

TypeGDScript
DescriptionThe script at the given path, if it exists. Otherwise, null.

load_image

func load_image(path: String) -> Texture2D

Loads the contents of the file as a Texture2D.

Parameters

NameTypeDescription
pathStringThe path to load from.

Returns

TypeTexture2D
DescriptionThe image at the given path, if it exists. Otherwise, null.

load_mod

func load_mod(path: String) -> Mod

Loads the file as a Mod.

Parameters

NameTypeDescription
pathStringThe path to load from.

Returns

TypeMod
DescriptionThe mod at the given path, if it exists. Otherwise, null.