Skip to content

Profile Scripting

Anton Pupkov edited this page Aug 11, 2016 · 1 revision

This page aims to explain how to create new effects for profiles via scripting with Aurora.

Aurora supports scripting with C# and Python. You can add scripts to any profile, you can create script files in the profile's directory, in %appdata%\Aurora\Profiles\*profile folder*\Scripts\. Sample scripts for C# and Python can be viewed here: Script Examples. Scripts are registered at Aurora's load time. As it stands right now, if your script errors and is automatically disabled. You would have to restart Aurora for it to be reloaded (This may change in the future).

Script requirements

Device scripts must include the following variables and function to be properly loaded by Aurora.

Script format

For scripting, C# follows the same format as any other C# class. For Python, you have to define a main class with your variables and function definitions in there. Like so:

Python

class main():
    ID = "ExamplePyEffect"
    def UpdateLights(self, settings, state):
        layer = EffectLayer(self.ID)
        #Apply effects on the layer
        return layer

Variables

The following set of variables is always required to exist in the script for Aurora to load the profile script.

  • Include an ID for your script, called ID. This will be used as a unique identifier for the script.
  • Include a DefaultKeys KeySequence for later support for script settings.

C#

public string ID = "ExampleCSScript";
public KeySequence DefaultKeys = new KeySequence();

Python

class main():
    ID = "ExamplePyEffect"
    DefaultKeys = KeySequence()

Functions

Profile scripts require only the UpdateLights method. Please note that this method will be called each frame for the profile. The purpose of this method is to create additional layers with custom lit keys/effects, and return either EffectLayer class or an array of EffectLayer. Information about EffectLayer class can be found here, EffectLayer Class. Here is a template for C# and Python:

C#

using Aurora;
using Aurora.EffectsEngine;
using Aurora.Profiles;
using Aurora.Devices;
using Aurora.Settings;
using System;
using System.Drawing;
using System.Collections.Generic;

public class ExampleEffect
{
    public string ID = "ExampleCSScript (Multi-Layer)";

    public KeySequence DefaultKeys = new KeySequence();
    
    public EffectLayer[] UpdateLights(ScriptSettings settings, GameState state = null)
    {
        //Queue of layers to be later returned as an array
        Queue<EffectLayer> layers = new Queue<EffectLayer>();
        
        EffectLayer layer = new EffectLayer(this.ID);
        //Perform effects on the layer, for EffectLayer methods look at https://github.com/antonpup/Aurora/wiki/Methods_T_Aurora_EffectsEngine_EffectLayer
        layers.Enqueue(layer);
        
        EffectLayer layer_swirl = new EffectLayer(this.ID + " - Swirl");
        //Example percent effect
        layer_swirl.PercentEffect(Color.Blue, Color.Black, new KeySequence(new[] { DeviceKeys.NUM_ONE, DeviceKeys.NUM_FOUR,  DeviceKeys.NUM_SEVEN, DeviceKeys.NUM_EIGHT, DeviceKeys.NUM_NINE, DeviceKeys.NUM_SIX, DeviceKeys.NUM_THREE, DeviceKeys.NUM_TWO }), DateTime.Now.Millisecond % 500D, 500D, PercentEffectType.Progressive_Gradual);
        layers.Enqueue(layer_swirl);
        
        EffectLayer layer_blinking = new EffectLayer(this.ID + " - Blinking Light");
        //Example blinking effect
        ColorSpectrum blink_spec = new ColorSpectrum(Color.Red, Color.Black, Color.Red);
        Color blink_color = blink_spec.GetColorAt(DateTime.Now.Millisecond / 1000.0f);
        layer_blinking.Set(DeviceKeys.NUM_FIVE, blink_color);
        layers.Enqueue(layer_blinking);
        
        //Return queue of layers as an array
        return layers.ToArray();
    }
}

Python

import clr

clr.AddReference("Aurora")
clr.AddReference("System.Drawing")

from Aurora import Global
from Aurora.Settings import KeySequence
from Aurora.Devices import DeviceKeys
from Aurora.EffectsEngine import EffectLayer
from System.Drawing import Color
import System

class main():
    ID = "ExamplePyEffect"
    DefaultKeys = KeySequence()
    def UpdateLights(self, settings, state):
        layer = EffectLayer(self.ID)
        #Perform effects on the layer, for EffectLayer methods look at https://github.com/antonpup/Aurora/wiki/Methods_T_Aurora_EffectsEngine_EffectLayer
        return layer

Optimization

It is rather important that your script is very optimal, as it will be called each frame. Please try to optimize your scripts to be as quick as possible.

Clone this wiki locally