Views
Common Organization of Controls Kit Setup data
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:
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.