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 project.

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.

Arguments:

include_mods: boolean

Whether to clear loaded projects.



Kristal.clearModHooks()

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



Kristal.clearModState()

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



Kristal.clearModSubclasses()

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





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

Erases a file from the save folder.

Arguments:

file: string

The file name to erase.

path: string?

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



Kristal.errorHandler(msg: string|table, trace_level: integer?)

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

Arguments:

msg: string|table

The error message.

trace_level: integer?

Returns:

handler: function?

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



Kristal.executeLibScript(lib: string?, 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.

Arguments:

lib: string?

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 project folder.

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?

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.

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.

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 project's name if it wants us to, or the default.
Also see Kristal.setDesiredWindowTitleAndIcon().

Returns:

1: string


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"
   }
}

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 project's mod.json.

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.

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.

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 project's save folder)

Returns:

data: table?

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.

Returns:

x: number

The x offset.

y: number

The y offset.



Kristal.getSoulColor()

Returns the soul color which should be used.

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.

Returns:

volume: number

The current master volume.



Kristal.hasAnySaves(path: string?)

Returns whether the specified save folder has any save files.

Arguments:

path: string?

The save folder to check. (Defaults to the current project'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.

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 project's save folder)

Returns:

exists: boolean

Whether the save file exists.



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

Fades out the screen border.

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.isDevMode()

Whether or not developer mode is enabled.

Returns:

1: boolean


Kristal.isLoading()

Returns whether Kristal is currently loading something.

Returns:

loading: boolean

Whether Kristal is loading something or not.





Kristal.libCall(id: string?, 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.

Arguments:

id: string?

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.

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.

Returns:

config: table

The user config.



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

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

Arguments:

file: string

The file name to load.

path: string?

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

Returns:

data: table?

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.

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 project and loads its assets.
If an after callback is not provided, enters the project, including dark transition if enabled.

Arguments:

id: string

The id of the project to load.

save_id: number?

The id of the save to load the project 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 project was loaded successfully.



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

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

Arguments:

id: string

The id of the project 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.

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.

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.popState()

Pops the current Gamestate off the stack, returning to the previous one.



Kristal.preInitMod(id: string)

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

Arguments:

id: string

The id of the project to pre-initialize.

Returns:

success: boolean

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



Kristal.processDynamicBorder()

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

Returns:

border: Border?

The currently displayed border if dynamic borders are enabled.



Kristal.pushState(state: string|table|"Empty"|"Game"|"Loading"...(+2), ...: any)

Pushes a new Gamestate onto the stack.

state:
    | "Loading" -- The loading state, before entering the main menu.
    | "Menu" -- The main menu state.
    | "Game" -- The game state, entered when loading a project.
    | "Testing" -- The testing state, used in development.
    | "Empty" -- An empty state, which does nothing.

Arguments:

state: string|table|"Empty"|"Game"|"Loading"...(+2)

The gamestate to switch to.

...: any

Arguments passed to the gamestate.



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

Reloads the current project.

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

Arguments:

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

The mode to reload the project in.





Kristal.resetWindow()

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



Kristal.returnToMenu()

Exits the current project 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.

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 project's save folder)



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

Saves the game.

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 project requests to be or the defaults.



Kristal.setPresence(presence: table)

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

Arguments:

presence: table

The presence information to set.



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

Switches the Gamestate to the given one.

state:
    | "Loading" -- The loading state, before entering the main menu.
    | "Menu" -- The main menu state.
    | "Game" -- The game state, entered when loading a project.
    | "Testing" -- The testing state, used in development.
    | "Empty" -- An empty state, which does nothing.

Arguments:

state: string|table|"Empty"|"Game"|"Loading"...(+2)

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.

Arguments:

volume: number

The volume to set.



Kristal.shouldDisplayDevWarning()

Whether or not to show the "dev mode enabled" warning.

Returns:

1: boolean


Kristal.showBorder(time: number?)

Fades in the screen border.

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.

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.CurrentState: nil

The heart of Kristal - this class stores serves as the global that almost everything during gameplay is stored under in some way or another.
Game itself is mainly responsible for changing between states, handling player control, and accessing overarching features across gameplay such as the inventory or party members.

















Kristal.Stage: Stage

global stage







Kristal.Version: unknown

load the version





Kristal.icon: love.ImageData

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