System

The System module contains functions and constants that don't fit in many other places.

  • data_directory returns the assigned directory for saving data. This will be either AppData, Application Support or .local/share depending on platform.

  • window_title and window_title=(str) get and set the window's title to str respectively.

  • raw_key_states returns a byte string containing all of MKXP's key states.

  • launch(cmd[, args]) opens the path or link address with the user's default program. For instance, System.launch("https://www.google.com") would open Google in the default web browser, System.launch(System.data_directory) would open the game's save folder in the file explorer, and System.launch("log.txt") would open a plaintext file using whatever the user has assigned to open plaintext files with. Raises an MKXPError if it fails for whatever reason.

  • user_language returns the user's locale (e.g. "en_US")

  • game_title returns the game's title.

  • power_state returns a hash containing three entries, all of them able to be nil:

    • :discharging: whether the machine is connected to sufficient power

    • :percent: the remaining percentage of the battery

    • :seconds: the estimated remaining time for the battery in seconds

  • show_settings raises the keybinding menu

  • nproc returns the number of processor threads

  • memory returns the total amount of memory available in the machine

  • uptime returns the amount of time passed since the application was started (in microseconds). Also aliased as delta.

  • System::VERSION is a constant that returns mkxp-z build version. It's defined in either the root meson.build, or from within the build settings of the Xcode targets.

  • System::CONFIG is a hash containing the parsed JSON data of the configuration file. If the JSON couldn't be read or never existed, this hash is empty.

Platform Detection

  • platform returns a string describing the platform MKXP is currently running on.

  • is_windows?/is_mac?/is_linux? return true if MKXP was built for the respective operating system.

  • is_rosetta? returns true if MKXP is being run over Rosetta 2 -- in other words, if it is being run as Intel code on an ARM Mac.

  • is_wine? returns true if MKXP is being run on Linux or macOS through Wine.

  • is_really_windows?/is_really_mac?/is_really_linux? are similar to the functions above, but unlike those, are not tricked by Wine.

The Path Cache

MKXP's classes do not directly use the native filesystem. Instead, by default, the game's directory is mounted to appear as the current directory, along with the game's archive if it has one, and any locations specified as RTPs in the configuration file.

If you wish to create Bitmaps, play audio, use load_data, etc. on files or archives not initially indicated to MKXP, or on files or archives that were not pre-existing at the time MKXP was started, these are for you.

  • desensitize(path) uses MKXP's internal path cache to find the correct case for a filename. Useful for scripting filesystem operations on platforms with case-sensitive filesystems, like macOS and Linux.

  • reload_cache causes MKXP to regenerate its path cache, reflecting changes made in the mounted filesystem since it was last called.

  • mount(path[, mountpoint[, reload]]) will mount path to mountpoint. Multiple locations can be mounted to the same mount point, and any archive formats you can use with the RTPs option in mkxp's json configuration can also be mounted as directories (e.g. zip, rgssad, iso). If mountpoint is not provided, it will default to the game's root, not the same path specified in path. Automatically reloads the path cache if reload is not specifically set false.

  • unmount(path[, reload]) removes path from MKXP's search path. This is the same path given to the first argument of mount, not the mount point. Automatically reloads the path cache if reload is not specifically set false.

Last updated