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

m
m (Reformatting.)
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
Functions [[cock.new]] and [[cock.setControls]] would accept specifically formatted table to build layouts from. It follows a simple pattern:
 
Functions [[cock.new]] and [[cock.setControls]] would accept specifically formatted table to build layouts from. It follows a simple pattern:
  
<code>
+
<source lang="Lua">
 
  default
 
  default
 
   key
 
   key
 
     option
 
     option
       data</code>
+
       data</source>
 
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>
+
<source lang="Lua">device, key, inverse, delta</source>
  
Last two parameters are optional and set by default if not specified.
+
Last two parameters are optional and set by default ("positive cutoff" and "bypass" respectively) if not specified.
  
 
Example:
 
Example:
Line 16: Line 16:
 
local data = {  
 
local data = {  
 
   default_keyboard = {  
 
   default_keyboard = {  
     up = { optionA = { "keyboard", "up" }, optionB = { "mouse axis", "y", "-", "++" } },
+
     up = { optionA = { "keyboard", "up" }, optionB = { "mouse axis", "y", "negative", "positive cutoff" } },
     down = { optionA = { "keyboard", "down" }, optionB = { "mouse axis", "y", "+", "++" } }  
+
     down = { optionA = { "keyboard", "down" }, optionB = { "mouse axis", "y", "positive", "positive cutoff" } }  
 
     }
 
     }
 
   default_joystick = {
 
   default_joystick = {
     up = { optionA = { "joystick hat", "u" }, optionB = { "joystick axis", "y", "--" } },
+
     up = { optionA = { "joystick hat", "u" }, optionB = { "joystick axis", "y", "negative cutoff" } },
     down = { optionA = { "joystick hat", "d" }, optionB = { "joystick axis", "y", "++" } }  
+
     down = { optionA = { "joystick hat", "d" }, optionB = { "joystick axis", "y", "positive cutoff" } }  
 
     }  
 
     }  
 
   }
 
   }
Line 30: Line 30:
  
 
'''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.
 
'''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.
 +
 +
'''NOTE:''' if you setting up joystick controls, make sure there's at least one joystick defined. Even if there's no joystick is hooked up, you can create a dummy joystick with [[cock.addJoystick]](1). If there won't be any attached joysticks, many joystick-related functions will result in bluescreening the game.
  
 
== See also ==
 
== See also ==
 +
* [[Common Organization of Controls Kit Input devices]]
 +
* [[Common Organization of Controls Kit Input keys]]
 +
* [[Common Organization of Controls Kit Modes]]
 
* [[Common Organization of Controls Kit Manual]]
 
* [[Common Organization of Controls Kit Manual]]
 
* [[cock.setControls]]
 
* [[cock.setControls]]
 
* [[cock.setDefault]]
 
* [[cock.setDefault]]
 
* [[cock.new]]
 
* [[cock.new]]

Latest revision as of 04:44, 3 November 2016

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 ("positive cutoff" and "bypass" respectively) if not specified.

Example:

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

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.

NOTE: if you setting up joystick controls, make sure there's at least one joystick defined. Even if there's no joystick is hooked up, you can create a dummy joystick with cock.addJoystick(1). If there won't be any attached joysticks, many joystick-related functions will result in bluescreening the game.

See also