1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-06 18:25:21 +01:00

Refactor menu_lua_api.md

This commit is contained in:
Bradley Pierce
2024-01-20 08:26:52 -05:00
parent a64af4e914
commit db317d5446

View File

@@ -1,15 +1,12 @@
Minetest Lua Mainmenu API Reference 5.9.0 # Minetest Lua Mainmenu API Reference 5.8.0
========================================= ## Introduction
Introduction
-------------
The main menu is defined as a formspec by Lua in `builtin/mainmenu/` The main menu is defined as a formspec by Lua in `builtin/mainmenu/`
Description of formspec language to show your menu is in `lua_api.md` Description of formspec language to show your menu is in `lua_api.md`
Callbacks
--------- # Callbacks
* `core.button_handler(fields)`: called when a button is pressed. * `core.button_handler(fields)`: called when a button is pressed.
* `fields` = `{name1 = value1, name2 = value2, ...}` * `fields` = `{name1 = value1, name2 = value2, ...}`
@@ -17,8 +14,8 @@ Callbacks
* `event`: `"MenuQuit"`, `"KeyEnter"`, `"ExitButton"` or `"EditBoxEnter"` * `event`: `"MenuQuit"`, `"KeyEnter"`, `"ExitButton"` or `"EditBoxEnter"`
Gamedata
-------- # Gamedata
The "gamedata" table is read when calling `core.start()`. It should contain: The "gamedata" table is read when calling `core.start()`. It should contain:
@@ -34,8 +31,8 @@ The "gamedata" table is read when calling `core.start()`. It should contain:
``` ```
Functions
--------- # Functions
* `core.start()` * `core.start()`
* start game session * start game session
@@ -62,8 +59,7 @@ Functions
Filesystem # Filesystem
----------
* `core.get_builtin_path()` * `core.get_builtin_path()`
* returns path to builtin root * returns path to builtin root
@@ -91,7 +87,7 @@ Filesystem
* `core.get_video_drivers()` * `core.get_video_drivers()`
* get list of video drivers supported by engine (not all modes are guaranteed to work) * get list of video drivers supported by engine (not all modes are guaranteed to work)
* returns list of available video drivers' settings name and 'friendly' display name * returns list of available video drivers' settings name and 'friendly' display name
e.g. `{ {name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"} }` e.g. `{{name="opengl", friendly_name="OpenGL"}, {name="software", friendly_name="Software Renderer"}}`
* first element of returned list is guaranteed to be the NULL driver * first element of returned list is guaranteed to be the NULL driver
* `core.get_mapgen_names([include_hidden=false])` -> table of map generator algorithms * `core.get_mapgen_names([include_hidden=false])` -> table of map generator algorithms
registered in the core (possible in async calls) registered in the core (possible in async calls)
@@ -101,8 +97,8 @@ Filesystem
otherwise: returns path to the temporary folder otherwise: returns path to the temporary folder
HTTP Requests
------------- # HTTP Requests
* `core.download_file(url, target)` (possible in async calls) * `core.download_file(url, target)` (possible in async calls)
* `url` to download, and `target` to store to * `url` to download, and `target` to store to
@@ -120,7 +116,7 @@ HTTP Requests
* `HTTPApiTable.fetch_async_get(handle)`: returns `HTTPRequestResult` * `HTTPApiTable.fetch_async_get(handle)`: returns `HTTPRequestResult`
* Return response data for given asynchronous HTTP request * Return response data for given asynchronous HTTP request
### `HTTPRequest` definition ## `HTTPRequest` Definition
Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`. Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
@@ -141,7 +137,7 @@ Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
-- Optional, if specified replaces the default minetest user agent with -- Optional, if specified replaces the default minetest user agent with
-- given string -- given string
extra_headers = { "Accept-Language: en-us", "Accept-Charset: utf-8" }, extra_headers = {"Accept-Language: en-us", "Accept-Charset: utf-8"},
-- Optional, if specified adds additional headers to the HTTP request. -- Optional, if specified adds additional headers to the HTTP request.
-- You must make sure that the header strings follow HTTP specification -- You must make sure that the header strings follow HTTP specification
-- ("Key: Value"). -- ("Key: Value").
@@ -152,7 +148,7 @@ Used by `HTTPApiTable.fetch` and `HTTPApiTable.fetch_async`.
} }
``` ```
### `HTTPRequestResult` definition ## `HTTPRequestResult` Definition
Passed to `HTTPApiTable.fetch` callback. Returned by Passed to `HTTPApiTable.fetch` callback. Returned by
`HTTPApiTable.fetch_async_get`. `HTTPApiTable.fetch_async_get`.
@@ -177,8 +173,8 @@ Passed to `HTTPApiTable.fetch` callback. Returned by
``` ```
Formspec
-------- # Formspec
* `core.update_formspec(formspec)` * `core.update_formspec(formspec)`
* `core.get_table_index(tablename)` -> index * `core.get_table_index(tablename)` -> index
@@ -195,8 +191,8 @@ Formspec
* `formspec`: string to be added to every mainmenu formspec, to be used for theming. * `formspec`: string to be added to every mainmenu formspec, to be used for theming.
GUI
--- # GUI
* `core.set_background(type,texturepath,[tile],[minsize])` * `core.set_background(type,texturepath,[tile],[minsize])`
* `type`: "background", "overlay", "header" or "footer" * `type`: "background", "overlay", "header" or "footer"
@@ -222,7 +218,6 @@ GUI
* `core.get_active_irrlicht_device()`: * `core.get_active_irrlicht_device()`:
* name of current irrlicht device, e.g. "SDL" * name of current irrlicht device, e.g. "SDL"
* `core.get_window_info()`: Same as server-side `get_player_window_information` API. * `core.get_window_info()`: Same as server-side `get_player_window_information` API.
```lua ```lua
-- Note that none of these things are constant, they are likely to change -- Note that none of these things are constant, they are likely to change
-- as the player resizes the window and moves it between monitors -- as the player resizes the window and moves it between monitors
@@ -264,8 +259,7 @@ GUI
Content and Packages # Content and Packages
--------------------
Content - an installed mod, modpack, game, or texture pack (txt) Content - an installed mod, modpack, game, or texture pack (txt)
Package - content which is downloadable from the content db, may or may not be installed. Package - content which is downloadable from the content db, may or may not be installed.
@@ -341,8 +335,9 @@ Package - content which is downloadable from the content db, may or may not be i
} }
``` ```
Logging
-------
# Logging
* `core.debug(line)` (possible in async calls) * `core.debug(line)` (possible in async calls)
* Always printed to `stderr` and logfile (`print()` is redirected here) * Always printed to `stderr` and logfile (`print()` is redirected here)
@@ -351,8 +346,8 @@ Logging
* `loglevel` one of "error", "action", "info", "verbose" * `loglevel` one of "error", "action", "info", "verbose"
Settings
-------- # Settings
* `core.settings:set(name, value)` * `core.settings:set(name, value)`
* `core.settings:get(name)` -> string or nil (possible in async calls) * `core.settings:get(name)` -> string or nil (possible in async calls)
@@ -361,11 +356,11 @@ Settings
* `core.settings:save()` -> nil, save all settings to config file * `core.settings:save()` -> nil, save all settings to config file
For a complete list of methods of the `Settings` object see For a complete list of methods of the `Settings` object see
[lua_api.md](https://github.com/minetest/minetest/blob/master/doc/lua_api.md) [lua_api.md](lua_api.md#methods-18)
Worlds
------ # Worlds
* `core.get_worlds()` -> list of worlds (possible in async calls) * `core.get_worlds()` -> list of worlds (possible in async calls)
* returns * returns
@@ -382,8 +377,8 @@ Worlds
* `core.delete_world(index)` * `core.delete_world(index)`
Helpers
------- # Helpers
* `core.get_us_time()` * `core.get_us_time()`
* returns time with microsecond precision * returns time with microsecond precision
@@ -413,8 +408,8 @@ Helpers
[RFC 3986, section 2.3](https://datatracker.ietf.org/doc/html/rfc3986#section-2.3). [RFC 3986, section 2.3](https://datatracker.ietf.org/doc/html/rfc3986#section-2.3).
Async
----- # Async
* `core.handle_async(async_job,parameters,finished)` * `core.handle_async(async_job,parameters,finished)`
* execute a function asynchronously * execute a function asynchronously
@@ -423,18 +418,18 @@ Async
* `finished` function to be called once `async_job` has finished * `finished` function to be called once `async_job` has finished
the result of `async_job` is passed to this function the result of `async_job` is passed to this function
### Limitations of Async operations ## Limitations of Async Operations
* No access to global lua variables, don't even try * No access to global lua variables, don't even try
* Limited set of available functions * Limited set of available functions
e.g. No access to functions modifying menu like `core.start`, `core.close`, e.g. No access to functions modifying menu like `core.start`, `core.close`,
`core.show_path_select_dialog` `core.show_path_select_dialog`
Background music
---------------- # Background Music
The main menu supports background music. The main menu supports background music.
It looks for a `main_menu` sound in `$USER_PATH/sounds`. The same naming It looks for a `main_menu` sound in `$USER_PATH/sounds`. The same naming
conventions as for normal sounds apply. conventions as for normal sounds apply.
This means the player can add a custom sound. This means the player can add a custom sound.
It will be played in the main menu (gain = 1.0), looped. It will be played in the main menu (gain = 1.0), looped.