ModContentLoader
See the code atutils/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.
Type | Mode |
---|---|
Default | Mode.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
.
Type | ModZipReader |
---|---|
Default | null |
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
Name | Type | Description |
---|---|---|
reader | ModZipReader | The ZIP reader to use when loading files. |
Returns
Type | ModContentLoader |
---|---|
Description | The new content loader. |
exists
func exists(path: String) -> bool
Checks if a file exists at the given path.
Parameters
Name | Type | Description |
---|---|---|
path | String | The path to check. |
Returns
Type | bool |
---|---|
Description | true 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
Name | Type | Description |
---|---|---|
path | String | The path to load from. |
Returns
Type | String |
---|---|
Description | The 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
Name | Type | Description |
---|---|---|
path | String | The path to load from. |
Returns
Type | Dictionary |
---|---|
Description | The 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
Name | Type | Description |
---|---|---|
path | String | The path to load from. |
Returns
Type | Resource |
---|---|
Description | The 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
Name | Type | Description |
---|---|---|
path | String | The path to load from. |
Returns
Type | GDScript |
---|---|
Description | The 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
Name | Type | Description |
---|---|---|
path | String | The path to load from. |
Returns
Type | Texture2D |
---|---|
Description | The 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
Name | Type | Description |
---|---|---|
path | String | The path to load from. |
Returns
Type | Mod |
---|---|
Description | The mod at the given path, if it exists. Otherwise, null . |