Methods


Kristal.bordersEnabled()

@return enabled — Whether borders are enabled.

Returns:

enabled: boolean

Whether borders are enabled.



Kristal.callEvent(f: string, : any)

Calls a function from all libraries, and then the current mod.

@param f — The function name to call.

@param ... — The arguments to pass to the function.

@return result — The result of the function calls or'd together.

Arguments:

f: string

The function name to call.

: any

The arguments to pass to the function.

Returns:

result: any

The result of the function calls or'd together.



Kristal.clearAssets(include_mods: boolean)

Clears all currently loaded assets. Called internally in the Loading state.

@param include_mods — Whether to clear loaded mods.

Arguments:

include_mods: boolean

Whether to clear loaded mods.



Kristal.clearModHooks()

Clears all mod-defined hooks from Utils.hook, and restores the original functions.
Called internally when a mod is unloaded.



Kristal.clearModState()

Clears all state expected to be changed by mods.
Called internally when exiting or reloading a mod.



Kristal.clearModSubclasses()

Removes all mod-defined classes from base classes' __includers table. Called internally when a mod is unloaded.



Kristal.eraseData(file: string, path: string?)

Erases a file from the save folder.

@param file — The file name to erase.

@param path — The save folder to erase from. (Defaults to the current mod's save folder)

Arguments:

file: string

The file name to erase.

path: string?

The save folder to erase from. (Defaults to the current mod's save folder)



Kristal.errorHandler(msg: string|table)

Kristal alternative to the default love.errorhandler.
Called when an error occurs.

@param msg — The error message.

@return handler — The error handler, called every frame instead of the main loop.

Arguments:

msg: string|table

The error message.

Returns:

handler: function|nil

The error handler, called every frame instead of the main loop.



Kristal.executeLibScript(lib: string|nil, path: string, : any)

Executes a .lua script inside the specified library folder.
If id is not specified, the first script found from any library will be executed.

@param lib — The library ID to execute the script from, or nil to execute from any library.

@param path — The script name to execute.

@param ... — The arguments to pass to the script.

@return success — Whether the script was executed successfully.

@return ... — The returned values from the script.

Arguments:

lib: string|nil

The library ID to execute the script from, or nil to execute from any library.

path: string

The script name to execute.

: any

The arguments to pass to the script.

Returns:

success: boolean

Whether the script was executed successfully.

...: any

The returned values from the script.



Kristal.executeModScript(path: string, : any)

Executes a .lua script inside the mod folder.

@param path — The script name to execute.

@param ... — The arguments to pass to the script.

@return success — Whether the script was executed successfully.

@return ... — The returned values from the script.

Arguments:

path: string

The script name to execute.

: any

The arguments to pass to the script.

Returns:

success: boolean

Whether the script was executed successfully.

...: any

The returned values from the script.



Kristal.fetch(url: any, options: any)

Arguments:

url: any
options: any

Returns:

1: boolean


Kristal.getBorder()

@return border — The currently displayed border, or nil if borders are disabled.

Returns:

border: Border|nil

The currently displayed border, or nil if borders are disabled.



Kristal.getBorderData(id: string)

Returns the border data table for the given border config id.

@param id — The id of the border to get.

@return data — The border data.

Arguments:

id: string

The id of the border to get.

Returns:

data: table

The border data.



Kristal.getBorderName()

@return name — The name of the current border config option.

Returns:

name: string

The name of the current border config option.



Kristal.getBorderSize()

Returns the dimensions of the screen border, or (0, 0) if borders are disabled.

@return width — The width of the border.

@return height — The height of the border.

Returns:

width: number

The width of the border.

height: number

The height of the border.



Kristal.getBorderTypes()

@return types — The available border types, or nil if borders are disabled.

Returns:

types: table

The available border types, or nil if borders are disabled.



Kristal.getDesiredWindowTitle()

Called internally. Returns the current running/target mod's name if it wants us to, or the default.
Also see Kristal.setDesiredWindowTitleAndIcon().

Returns:

1: unknown


Kristal.getGameScale()

@return scale — The current game scale, based on the window dimensions.

Returns:

scale: number

The current game scale, based on the window dimensions.



Kristal.getLibConfig(lib_id: string, key: string, merge: boolean?, deep_merge: boolean?)

Gets a library config option, defined in either lib.json or modified by the mod.json.
Default values can be defined inside your library's lib.json:

"config": {
   "option": "value"
}

These can then be overridden inside a mod.json like so:

"config": {
   "your_library_id": {
       "option": "new value"
   }
}

@param lib_id — The library ID to get the config option from.

@param key — The key of the config option to get.

@param merge — If the option is a table, whether to merge it with the default value. (Defaults to false)

@param deep_merge — If merge is enabled, whether to merge the tables deeply. (Defaults to false)

@return value — The value of the config option, or nil if it doesn't exist.

Arguments:

lib_id: string

The library ID to get the config option from.

key: string

The key of the config option to get.

merge: boolean?

If the option is a table, whether to merge it with the default value. (Defaults to false)

deep_merge: boolean?

If merge is enabled, whether to merge the tables deeply. (Defaults to false)

Returns:

value: any

The value of the config option, or nil if it doesn't exist.



Kristal.getModOption(key: string)

Gets a value from the current mod's mod.json.

@param key — The key of the value to get.

@return value — The value at the key, or nil if it doesn't exist.

Arguments:

key: string

The key of the value to get.

Returns:

value: any

The value at the key, or nil if it doesn't exist.



Kristal.getPresence()

@return presence — Get the current presence information.

Returns:

presence: table

Get the current presence information.



Kristal.getRelativeBorderSize()

Returns the dimensions of the screen border relative to the game's size.

@return width — The width of the border.

@return height — The height of the border.

Returns:

width: number

The width of the border.

height: number

The height of the border.



Kristal.getSaveFile(id: number?, path: string?)

Returns the data from the specified save file.

@param id — The save file index to load. (Defaults to the currently loaded save index)

@param path — The save folder to load from. (Defaults to the current mod's save folder)

@return data — The data loaded from the save file, or nil if the file doesn't exist.

Arguments:

id: number?

The save file index to load. (Defaults to the currently loaded save index)

path: string?

The save folder to load from. (Defaults to the current mod's save folder)

Returns:

data: table|nil

The data loaded from the save file, or nil if the file doesn't exist.



Kristal.getSideOffsets()

Returns the offsets of the game display, for calculating screen position.

@return x — The x offset.

@return y — The y offset.

Returns:

x: number

The x offset.

y: number

The y offset.



Kristal.getSoulColor()

Returns the soul color which should be used.

@return r — The red value of the color.

@return g — The green value of the color.

@return b — The blue value of the color.

@return a — The alpha value of the color.

Returns:

r: number

The red value of the color.

g: number

The green value of the color.

b: number

The blue value of the color.

a: number

The alpha value of the color.



Kristal.getState()

@return state — The current Gamestate.

Returns:

state: table

The current Gamestate.



Kristal.getTime()

@return runtime — The current runtime (RUNTIME), affected by timescale / fast-forward.

Returns:

runtime: number

The current runtime (RUNTIME), affected by timescale / fast-forward.



Kristal.getVolume()

Returns the current master volume from the config.

@return volume — The current master volume.

Returns:

volume: number

The current master volume.



Kristal.hasAnySaves(path: string?)

Returns whether the specified save folder has any save files.

@param path — The save folder to check. (Defaults to the current mod's save folder)

@return exists — Whether the save folder has any save files.

Arguments:

path: string?

The save folder to check. (Defaults to the current mod's save folder)

Returns:

exists: boolean

Whether the save folder has any save files.



Kristal.hasSaveFile(id: number?, path: string?)

Returns whether the specified save file exists.

@param id — The save file index to check. (Defaults to the currently loaded save index)

@param path — The save folder to check. (Defaults to the current mod's save folder)

@return exists — Whether the save file exists.

Arguments:

id: number?

The save file index to check. (Defaults to the currently loaded save index)

path: string?

The save folder to check. (Defaults to the current mod's save folder)

Returns:

exists: boolean

Whether the save file exists.



Kristal.hideBorder(time: number?, keep_old: boolean?)

Fades out the screen border.

@param time — The time it takes to fade out the border. Defaults to 0.5.

@param keep_old — Whether the old border stays during fadeout. Defaults to false.

Arguments:

time: number?

The time it takes to fade out the border. Defaults to 0.5.

keep_old: boolean?

Whether the old border stays during fadeout. Defaults to false.



Kristal.hideCursor()

Hides the mouse cursor.



Kristal.isConsole()

@return console — Whether Kristal is in console mode.

Returns:

console: boolean

Whether Kristal is in console mode.





Kristal.libCall(id: string|nil, f: string, : any)

Calls a function from the specified library, if it exists.
If id is not specified, the function will be called in all libraries, and the return value
will be or'd between libraries.

@param id — The library ID to call the function from, or nil to call in all libraries.

@param f — The function name to call.

@param ... — The arguments to pass to the function.

@return ... — The returned values from the function call, if it exists.

Arguments:

id: string|nil

The library ID to call the function from, or nil to call in all libraries.

f: string

The function name to call.

: any

The arguments to pass to the function.

Returns:

...: unknown

The returned values from the function call, if it exists.



Kristal.loadAssets(dir: string, loader: string, paths: (string|table)?, after: function?)

Loads assets of the specified type from the given directory, and calls the given callback when done.

@param dir — The directory to load assets from.

@param loader — The type of assets to load.

@param paths — The specific asset paths to load.

@param after — The function to call when done.

Arguments:

dir: string

The directory to load assets from.

loader: string

The type of assets to load.

paths: (string|table)?

The specific asset paths to load.

after: function?

The function to call when done.



Kristal.loadConfig()

Called internally. Loads the saved user config, with default values.

@return config — The user config.

Returns:

config: table

The user config.



Kristal.loadData(file: string, path: string?)

Loads and returns the data from a file in the save folder.

@param file — The file name to load.

@param path — The save folder to load from. (Defaults to the current mod's save folder)

@return data — The data loaded from the file, or nil if the file doesn't exist.

Arguments:

file: string

The file name to load.

path: string?

The save folder to load from. (Defaults to the current mod's save folder)

Returns:

data: table|nil

The data loaded from the file, or nil if the file doesn't exist.



Kristal.loadGame(id: number?, fade: boolean?)

Loads the game from a save file.

@param id — The save file index to load. (Defaults to the currently loaded save index)

@param fade — Whether the game should fade in after loading. (Defaults to false)

Arguments:

id: number?

The save file index to load. (Defaults to the currently loaded save index)

fade: boolean?

Whether the game should fade in after loading. (Defaults to false)



Kristal.loadMod(id: string, save_id: number?, save_name: string?, after: function?)

Initializes the specified mod and loads its assets.
If an after callback is not provided, enters the mod, including dark transition if enabled.

@param id — The id of the mod to load.

@param save_id — The id of the save to load the mod from. (1-3)

@param save_name — The name to use for the save file.

@param after — The function to call after assets have been loaded.

@return success — Whether the mod was loaded successfully.

Arguments:

id: string

The id of the mod to load.

save_id: number?

The id of the save to load the mod from. (1-3)

save_name: string?

The name to use for the save file.

after: function?

The function to call after assets have been loaded.

Returns:

success: boolean

Whether the mod was loaded successfully.



Kristal.loadModAssets(id: string, asset_type: string?, asset_paths: (string|table)?, after: function)

Loads assets from a mod and its libraries. Called internally by Kristal.loadMod.

@param id — The id of the mod to load assets from.

@param asset_type — The type of assets to load. (Defaults to "all")

@param asset_paths — The specific asset paths to load.

@param after — The function to call after assets have been loaded.

Arguments:

id: string

The id of the mod to load assets from.

asset_type: string?

The type of assets to load. (Defaults to "all")

asset_paths: (string|table)?

The specific asset paths to load.

after: function

The function to call after assets have been loaded.



Kristal.modCall(f: string, : any)

Calls a function from the current Mod, if it exists.

@param f — The function name to call.

@param ... — The arguments to pass to the function.

@return ... — The returned values from the function call, if it exists.

Arguments:

f: string

The function name to call.

: any

The arguments to pass to the function.

Returns:

...: unknown

The returned values from the function call, if it exists.



Kristal.modGet(key: string)

Gets a value from the current Mod.

@param key — The key of the value to get.

@return value — The value at the key, or nil if it doesn't exist.

Arguments:

key: string

The key of the value to get.

Returns:

value: any

The value at the key, or nil if it doesn't exist.



Kristal.onKeyPressed(key: any, is_repeat: any)

Arguments:

key: any
is_repeat: any


Kristal.onKeyReleased(key: any)

Arguments:

key: any


Kristal.onWheelMoved(x: any, y: any)

Arguments:

x: any
y: any


Kristal.preInitMod(id: string)

Called internally. Calls the preInit event on the mod and initializes the registry.

@param id — The id of the mod to pre-initialize.

@return success — Whether the mod should use default handling to enter the game.

Arguments:

id: string

The id of the mod to pre-initialize.

Returns:

success: boolean

Whether the mod should use default handling to enter the game.



Kristal.processDynamicBorder()

@return border — The currently displayed border if dynamic borders are enabled.

Returns:

border: Border|nil

The currently displayed border if dynamic borders are enabled.



Kristal.quickReload(mode: string|"none"|"save"|"temp")

Reloads the current mod.

@param mode — The mode to reload the mod in.

mode:
    | "temp" -- Creates a temp-save and reloads the mod from there.
    | "save" -- Reloads the mod from the last save.
    | "none" -- Fully reloads the mod from the start of the game.

Arguments:

mode: string|"none"|"save"|"temp"

The mode to reload the mod in.



Kristal.resetWindow()

Called internally. Resets the window properties to the user config.



Kristal.returnToMenu()

Exits the current mod and returns to the Kristal menu.



Kristal.saveConfig()

Saves the current config table to the settings.json.



Kristal.saveData(file: string, data: table, path: string?)

Saves the given data to a file in the save folder.

@param file — The file name to save to.

@param data — The data to save.

@param path — The save folder to save to. (Defaults to the current mod's save folder)

Arguments:

file: string

The file name to save to.

data: table

The data to save.

path: string?

The save folder to save to. (Defaults to the current mod's save folder)



Kristal.saveGame(id: number?, data: table?)

Saves the game.

@param id — The save file index to save to. (Defaults to the currently loaded save index)

@param data — The data to save to the file. (Defaults to the output of Game:save())

Arguments:

id: number?

The save file index to save to. (Defaults to the currently loaded save index)

data: table?

The data to save to the file. (Defaults to the output of Game:save())



Kristal.setDesiredWindowTitleAndIcon()

Called internally. Sets the title and icon of the game window to either what mod requests to be or the defaults.



Kristal.setPresence(presence: table)

Helper function to set the current RPC information, and update the presence if enabled.

@param presence — The presence information to set.

Arguments:

presence: table

The presence information to set.



Kristal.setState(state: string|table|"Game"|"Loading"|"Menu"...(+1), : any)

Switches the Gamestate to the given one.

@param state — The gamestate to switch to.

@param ... — Arguments passed to the gamestate.

state:
    | "Loading" -- The loading state, before entering the main menu.
    | "Menu" -- The main menu state.
    | "Game" -- The game state, entered when loading a mod.
    | "Testing" -- The testing state, used in development.

Arguments:

state: string|table|"Game"|"Loading"|"Menu"...(+1)

The gamestate to switch to.

: any

Arguments passed to the gamestate.



Kristal.setVolume(volume: number)

Sets the master volume to the given value and saves it to the config.

@param volume — The volume to set.

Arguments:

volume: number

The volume to set.



Kristal.showBorder(time: number?)

Fades in the screen border.

@param time — The time it takes to fade in the border. Defaults to 0.5.

Arguments:

time: number?

The time it takes to fade in the border. Defaults to 0.5.



Kristal.showCursor()

Shows the mouse cursor.



Kristal.transitionBorder(time: number?)

Transitions the screen border, fading it out and then back in to the current border.

@param time — The total time it takes to fade in and out. Defaults to 1.

Arguments:

time: number?

The total time it takes to fade in and out. Defaults to 1.



Kristal.updateCursor()

Called internally to make sure the correct cursor is displayed.




Fields



Undocumented





Kristal.ChapterConfigs: table

Chapter defaults





Kristal.Config: table

load the settings.json













Kristal.Stage: unknown

global stage





Kristal.Version: unknown

load the version





Kristal.icon: unknown

Save the defaults so if we do setWindowTitle for a mod we're able to revert it Unfortunate variable names