1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Updated LUA Events (markdown)

Robert Beekman 2016-11-06 22:02:03 +01:00
parent 4fc54c01d0
commit f92d75d55a

@ -1,22 +1,24 @@
Within the LUA environment you can use events to react to certain things, such as the profile being updated or a key being pressed. Within the LUA environment you can use events to react to certain things, such as a device being updated or a key being pressed.
To use events you need to subscribe to them. You can subscribe to the same event more than once if you want. To use events you need to subscribe to them. You can subscribe to the same event more than once if you want.
The examples below show how subscribing works. The examples below show how subscribing works.
## Overview ## Overview
* [ProfileUpdating](https://github.com/SpoinkyNL/Artemis/wiki/LUA-Events#profileupdating) * [DeviceUpdating](https://github.com/SpoinkyNL/Artemis/wiki/LUA-Events#deviceupdating)
* [ProfileDrawing](https://github.com/SpoinkyNL/Artemis/wiki/LUA-Events#profiledrawing) * [ProfileDrawing](https://github.com/SpoinkyNL/Artemis/wiki/LUA-Events#profiledrawing)
* [KeyboardKeyPressed](https://github.com/SpoinkyNL/Artemis/wiki/LUA-Events#keyboardkeypressed) * [KeyboardKeyPressed](https://github.com/SpoinkyNL/Artemis/wiki/LUA-Events#keyboardkeypressed)
## Events ## Events
### ProfileUpdating ### DeviceUpdating
Triggers whenever the profile is being updated. Use this event to process your own changes **before** every frame. Triggers whenever a device is being updated. Use this event to process your own changes **before** every frame.
If you want to change the way a layer is drawn, this is a good place to do so. If you want to change the way a layer is drawn, this is a good place to do so.
**Note:** This event triggers for every device each frame. This means it can trigger 6 times, 25 times a second.
#### Parameters #### Parameters
```lua ```lua
profile profile, profileUpdatingEventArgs eventArgs profile profile, profileUpdatingEventArgs eventArgs
``` ```
#### Event Arguments #### Event Arguments
- **DeviceType:** An string describing the device type (keyboard, mouse, headset, generic or mousemat).
- **DataModel:** An object containing the current DataModel. *(TODO: DataModel explaination)* - **DataModel:** An object containing the current DataModel. *(TODO: DataModel explaination)*
- **Preview:** A boolean indicating whether the draw was done as a preview (for the editor). - **Preview:** A boolean indicating whether the draw was done as a preview (for the editor).
@ -24,24 +26,31 @@ profile profile, profileUpdatingEventArgs eventArgs
```lua ```lua
-- This function will be called after every profile update, before every profile draw. -- This function will be called after every profile update, before every profile draw.
function updateHandler(profile, eventArgs) function updateHandler(profile, eventArgs)
-- In this example we only want to update once per frame when the keyboard is updated
if eventArgs.DeviceType != "keyboard" then
return
end
-- The Event Arguments are inside the eventArgs parameter -- The Event Arguments are inside the eventArgs parameter
-- In a Windows Profile, you could do this: -- In a Windows Profile, you could do this:
local currentSong = eventArgs.DataModel.Spotify.SongName; local currentSong = eventArgs.DataModel.Spotify.SongName;
end end
-- Subscribe to the event AFTER defining the function which must be subscribed. -- Subscribe to the event AFTER defining the function which must be subscribed.
Events.ProfileDrawing.add(updateHandler); Events.DeviceDrawing.add(updateHandler);
``` ```
--- ---
### ProfileDrawing ### DeviceDrawing
Triggers whenever the profile is being drawn. Use this event to draw your own shapes **after** every frame. Triggers whenever there is being drawn to a device. Use this event to draw your own shapes **after** every frame.
For more info on drawing, see the [Drawing](https://github.com/SpoinkyNL/Artemis/wiki/Drawing) page. For more info on drawing, see the [Drawing](https://github.com/SpoinkyNL/Artemis/wiki/Drawing) page.
**Note:** This event triggers for every device each frame. This means it can trigger 6 times, 25 times a second.
#### Parameters #### Parameters
```lua ```lua
profile profile, profileDrawingEventArgs eventArgs profile profile, profileDrawingEventArgs eventArgs
``` ```
#### Event Arguments #### Event Arguments
- **DeviceType:** An string describing the device type (keyboard, mouse, headset, generic or mousemat).
- **DataModel:** An object containing the current DataModel. *(TODO: DataModel explaination)* - **DataModel:** An object containing the current DataModel. *(TODO: DataModel explaination)*
- **Preview:** A boolean indicating whether the draw was done as a preview (for the editor). - **Preview:** A boolean indicating whether the draw was done as a preview (for the editor).
- **Drawing:** The [Drawing](https://github.com/SpoinkyNL/Artemis/wiki/Drawing) object for this frame. Use this to draw your own shapes. - **Drawing:** The [Drawing](https://github.com/SpoinkyNL/Artemis/wiki/Drawing) object for this frame. Use this to draw your own shapes.
@ -50,13 +59,18 @@ profile profile, profileDrawingEventArgs eventArgs
```lua ```lua
-- This function will be called after every profile draw. -- This function will be called after every profile draw.
function drawHandler(profile, eventArgs) function drawHandler(profile, eventArgs)
-- In this example we only want to draw to the keyboard
if eventArgs.DeviceType != "keyboard" then
return
end
-- The Event Arguments are inside the eventArgs parameter -- The Event Arguments are inside the eventArgs parameter
-- In a Windows Profile, you could do this: -- In a Windows Profile, you could do this:
local currentSong = eventArgs.DataModel.Spotify.SongName; local currentSong = eventArgs.DataModel.Spotify.SongName;
end end
-- Subscribe to the event AFTER defining the function which must be subscribed. -- Subscribe to the event AFTER defining the function which must be subscribed.
Events.ProfileDrawing.add(drawHandler); Events.DeviceDrawing.add(drawHandler);
``` ```
--- ---