This commit is contained in:
NoryiE
2025-09-13 20:28:52 +00:00
parent 9e1112f3bd
commit 4ccefcac9f
48 changed files with 3036 additions and 1565 deletions

View File

@@ -1,50 +1,35 @@
# basalt
This is the UI Manager and the starting point for your project. The following functions allow you to influence the default behavior of Basalt.
_This is the UI Manager and the starting point for your project. The following functions allow you to influence the default behavior of Basalt.
Before you can access Basalt, you need to add the following code on top of your file:
### Usage
```lua
local basalt = require("basalt")
```
What this code does is it loads basalt into the project, and you can access it by using the variable defined as "basalt".
## Fields
|Field|Type|Description|
|---|---|---|
|traceback|`boolean`|Whether to show a traceback on errors|
|_events|`table`|A table of events and their callbacks|
|_schedule|`function[]`|A table of scheduled functions|
|_plugins|`table`|A table of plugins|
|isRunning|`boolean`|Whether the Basalt runtime is active|
|LOGGER|`Log`|The logger instance|
|path|`string`|The path to the Basalt library|
What this code does is it loads basalt into the project, and you can access it by using the variable defined as "basalt"._
## Functions
|Method|Returns|Description|
|---|---|---|
|[basalt.create](#basalt-create)|table|Creates a new UI element
|[basalt.createFrame](#basalt-createframe)|BaseFrame|Creates a new BaseFrame
|[basalt.getAPI](#basalt-getapi)|table|Returns a Plugin API
|[basalt.getActiveFrame](#basalt-getactiveframe)|BaseFrame?|Returns the active frame
|[basalt.getElementClass](#basalt-getelementclass)|table|Returns an element class
|[basalt.getElementManager](#basalt-getelementmanager)|table|Returns the element manager
|[basalt.getErrorManager](#basalt-geterrormanager)|table|Returns the error manager
|[basalt.getFocus](#basalt-getfocus)|BaseFrame?|Returns the focused frame
|[basalt.getMainFrame](#basalt-getmainframe)|BaseFrame|Gets or creates the main frame
|[basalt.removeSchedule](#basalt-removeschedule)|boolean|Removes a scheduled update
|[basalt.run](#basalt-run)|-|Starts the Basalt runtime
|[basalt.schedule](#basalt-schedule)|thread|Schedules a function to run in a coroutine
|[basalt.setActiveFrame](#basalt-setactiveframe)|-|Sets the active frame
|[basalt.setFocus](#basalt-setfocus)|-|Sets a frame as focused
|[basalt.stop](#basalt-stop)|-|Stops the Basalt runtime
|[basalt.update](#basalt-update)|-|Runs basalt once
|[basalt.create](#basalt-create-type-properties)|table|Creates a new UI element|
|[basalt.createFrame](#basalt-createframe)|BaseFrame|Creates a new BaseFrame|
|[basalt.getElementManager](#basalt-getelementmanager)|table|Returns the element manager|
|[basalt.getErrorManager](#basalt-geterrormanager)|table|Returns the error manager|
|[basalt.getMainFrame](#basalt-getmainframe)|BaseFrame|Gets or creates the main frame|
|[basalt.setActiveFrame](#basalt-setactiveframe-frame-setactive)|-|Sets the active frame|
|[basalt.getActiveFrame](#basalt-getactiveframe-t)|BaseFrame|Returns the active frame|
|[basalt.setFocus](#basalt-setfocus-frame)|-|Sets a frame as focused|
|[basalt.getFocus](#basalt-getfocus)|BaseFrame|Returns the focused frame|
|[basalt.schedule](#basalt-schedule-func)|thread|Schedules a function to run in a coroutine|
|[basalt.removeSchedule](#basalt-removeschedule-func)|boolean|Removes a scheduled update|
|[basalt.update](#basalt-update)|-|Runs basalt once|
|[basalt.stop](#basalt-stop)|-|Stops the Basalt runtime|
|[basalt.run](#basalt-run-isactive)|-|Starts the Basalt runtime|
|[basalt.getElementClass](#basalt-getelementclass-name)|table|Returns an element class|
|[basalt.getAPI](#basalt-getapi-name)|table|Returns a Plugin API|
|[basalt.onEvent](#basalt-onevent-eventname-callback)|-|Registers an event callback|
|[basalt.removeEvent](#basalt-removeevent-eventname-callback)|boolean|Removes an event callback|
|[basalt.triggerEvent](#basalt-triggerevent-eventname)|-|Triggers a custom event|
## basalt.create(type, properties?)
Creates and returns a new UI element of the specified type.
### Parameters
@@ -55,83 +40,72 @@ Creates and returns a new UI element of the specified type.
* `table` `element` The created element instance
### Usage
```lua
```lua
local button = basalt.create("Button")
```
## basalt.createFrame()
Creates and returns a new BaseFrame
### Returns
* `BaseFrame` `BaseFrame` The created frame instance
## basalt.getAPI(name)
Returns a Plugin API
### Parameters
* `name` `string` The name of the plugin
### Returns
* `table` `Plugin` The plugin API
## basalt.getActiveFrame(t?)
Returns the active frame
### Parameters
* `t` *(optional)* `term` The term to get the active frame for (default: current term)
### Returns
* `BaseFrame?` `BaseFrame` The frame to set as active
## basalt.getElementClass(name)
Returns an element's class without creating a instance
### Parameters
* `name` `string` The name of the element
### Returns
* `table` `Element` The element class
## basalt.getElementManager()
Returns the element manager instance
### Returns
* `table` `ElementManager` The element manager
## basalt.getErrorManager()
Returns the error manager instance
### Returns
* `table` `ErrorManager` The error manager
## basalt.getFocus()
Returns the focused frame
### Returns
* `BaseFrame?` `BaseFrame` The focused frame
## basalt.getMainFrame()
Gets or creates the main frame
### Returns
* `BaseFrame` `BaseFrame` The main frame instance
## basalt.removeSchedule(func)
Removes a scheduled update
## basalt.setActiveFrame(frame, setActive?)
Sets the active frame
### Parameters
* `func` `thread` The scheduled function to remove
* `frame` `BaseFrame` The frame to set as active
* `setActive` *(optional)* `boolean` Whether to set the frame as active (default: true)
## basalt.getActiveFrame(t?)
Returns the active frame
### Parameters
* `t` *(optional)* `term` The term to get the active frame for (default: current term)
### Returns
* `boolean` `success` Whether the scheduled function was removed
* `BaseFrame` `The` frame to set as active
## basalt.run(isActive?)
Starts the Basalt runtime
## basalt.setFocus(frame)
Sets a frame as focused
### Parameters
* `isActive` *(optional)* `boolean` Whether to start active (default: true)
* `frame` `BaseFrame` The frame to set as focused
## basalt.getFocus()
Returns the focused frame
### Returns
* `BaseFrame` `The` focused frame
## basalt.schedule(func)
Schedules a function to run in a coroutine
### Parameters
@@ -140,26 +114,83 @@ Schedules a function to run in a coroutine
### Returns
* `thread` `func` The scheduled function
## basalt.setActiveFrame(frame, setActive?)
Sets the active frame
## basalt.removeSchedule(func)
Removes a scheduled update
### Parameters
* `frame` `BaseFrame` The frame to set as active
* `setActive` *(optional)* `boolean` Whether to set the frame as active (default: true)
* `func` `thread` The scheduled function to remove
## basalt.setFocus(frame)
Sets a frame as focused
### Returns
* `boolean` `success` Whether the scheduled function was removed
### Parameters
* `frame` `BaseFrame` The frame to set as focused
## basalt.update()
## basalt.stop()
Stops the Basalt runtime
## basalt.update(...)
Runs basalt once, can be used to update the UI manually, but you have to feed it the events
## basalt.stop()
Stops the Basalt runtime
## basalt.run(isActive?)
Starts the Basalt runtime
### Parameters
* `...` *(vararg)* `any` The event to run with
* `isActive` *(optional)* `boolean` Whether to start active (default: true)
## basalt.getElementClass(name)
Returns an element's class without creating a instance
### Parameters
* `name` `string` The name of the element
### Returns
* `table` `Element` The element class
## basalt.getAPI(name)
Returns a Plugin API
### Parameters
* `name` `string` The name of the plugin
### Returns
* `table` `Plugin` The plugin API
## basalt.onEvent(eventName, callback)
Registers a callback function for a specific event
### Parameters
* `eventName` `string` The name of the event to listen for (e.g. "mouse_click", "key", "timer")
* `callback` `function` The callback function to execute when the event occurs
### Usage
```lua
basalt.onEvent("mouse_click", function(button, x, y) basalt.debug("Clicked at", x, y) end)
```
## basalt.removeEvent(eventName, callback)
Removes a callback function for a specific event
### Parameters
* `eventName` `string` The name of the event
* `callback` `function` The callback function to remove
### Returns
* `boolean` `success` Whether the callback was found and removed
## basalt.triggerEvent(eventName)
Triggers a custom event and calls all registered callbacks
### Parameters
* `eventName` `string` The name of the event to trigger
### Usage
```lua
basalt.triggerEvent("custom_event", "data1", "data2")
```