Difference between revisions of "Common Organization of Controls Kit Setup data"

m (Created page with "Functions cock.new and cock.setControls would accept specifically formatted table to build layouts from. It follows a simple pattern: <code> default key option ...")
 
m
Line 7: Line 7:
 
       data</code>
 
       data</code>
 
Defaults, keys and options are unordered and can go in arbitrary fashion. But the "data" table is ordered list, and must follow this pattern:
 
Defaults, keys and options are unordered and can go in arbitrary fashion. But the "data" table is ordered list, and must follow this pattern:
 +
 
<code>device, key, inverse, delta</code>
 
<code>device, key, inverse, delta</code>
 +
 
Last two parameters are optional and set by default if not specified.
 
Last two parameters are optional and set by default if not specified.
  
Line 15: Line 17:
 
   default_keyboard = {  
 
   default_keyboard = {  
 
     up = { optionA = { "keyboard", "up" }, optionB = { "mouse axis", "y", "-", "++" } },
 
     up = { optionA = { "keyboard", "up" }, optionB = { "mouse axis", "y", "-", "++" } },
     down = { optionA = { "keyboard", "down" }, optionB = { "mouse axis", "y", "+", "++" } } }
+
     down = { optionA = { "keyboard", "down" }, optionB = { "mouse axis", "y", "+", "++" } }  
 +
    }
 
   default_joystick = {
 
   default_joystick = {
 
     up = { optionA = { "joystick hat", "u" }, optionB = { "joystick axis", "y", "--" } },
 
     up = { optionA = { "joystick hat", "u" }, optionB = { "joystick axis", "y", "--" } },
     down = { optionA = { "joystick hat", "d" }, optionB = { "joystick axis", "y", "++" } } } }
+
     down = { optionA = { "joystick hat", "d" }, optionB = { "joystick axis", "y", "++" } }  
 +
    }  
 +
  }
  
 
control:setControls ( data )
 
control:setControls ( data )

Revision as of 20:40, 31 August 2013

Functions cock.new and cock.setControls would accept specifically formatted table to build layouts from. It follows a simple pattern:

default
  key
    option
      data

Defaults, keys and options are unordered and can go in arbitrary fashion. But the "data" table is ordered list, and must follow this pattern:

device, key, inverse, delta

Last two parameters are optional and set by default if not specified.

Example:

local data = { 
  default_keyboard = { 
    up = { optionA = { "keyboard", "up" }, optionB = { "mouse axis", "y", "-", "++" } },
    down = { optionA = { "keyboard", "down" }, optionB = { "mouse axis", "y", "+", "++" } } 
    }
  default_joystick = {
    up = { optionA = { "joystick hat", "u" }, optionB = { "joystick axis", "y", "--" } },
    down = { optionA = { "joystick hat", "d" }, optionB = { "joystick axis", "y", "++" } } 
    } 
  }

control:setControls ( data )
control:setDefault ( "default_keyboard" )

This creates two default configurations: default_keyboard and default_joystick. Each of them has "optionA" and "optionB", just two different keys would trigger the same action. Then, there's two controls: "up" and "down". Note that there should not necessairly be mathing options across all defaults and controls: if you don't specify an option for certain control, missing option simply won't trigger it. Moreover, different defaults don't even have to have similar sets of controls. It just there won't happen anything if something is missing.

NOTE: if you only have one option per control, then it will be set to whatever value the binded device have. If there's more than one, then the biggest value will be selected, which effectively makes any of the bindings trigger the control. For analog devices, the biggest value is selected. In case two options have different signs of reading values, then they would cancel each other out. If there's more than two options and bingings are simultaneously giving different signs, then outcome is pretty much undefined due to arbitrary nature of data traversal. It could be an exact value of some of the binded devices, or could be cancelled out value. This is not normally a concern since one wouldn't normally bind two different axis to the same control.