Debian Codegraph @

components/the_one_button.lua

raw symbols SCIP
1 require 'glfw'
2
3 local old_states = {}
4 local states = {}
5
6 local player_keys = {
7 string.byte('A'),
8 string.byte('F'),
9 string.byte('H'),
10 string.byte('L')
11 }
12
13 local player_joysticks = {
14 glfw.JOYSTICK_1,
15 glfw.JOYSTICK_2,
16 glfw.JOYSTICK_3,
17 glfw.JOYSTICK_4
18 }
19
20 function held(i)
21 assert(1 <= i and i <= 4)
22 return states[i]
23 end
24
25 function pressed(i)
26 assert(1 <= i and i <= 4)
27 return states[i] and not old_states[i]
28 end
29
30 function released(i)
31 assert(1 <= i and i <= 4)
32 return not states[i] and old_states[i]
33 end
34
35 game.actors.new_generic('the_one_button', function ()
36 function update_setup ()
37 old_states = states
38 states = {false, false, false, false}
39 for i = 1, 4 do
40 states[i] =
41 game.keyboard.key_held(player_keys[i]) or
42 glfw.GetJoystickButtons(player_joysticks[i], 1)[1] == glfw.PRESS
43 end
44 end
45 end)