1 --this handles the events
5 --create the resource managers
6 EventManager
.keyboard
= {}
7 EventManager
.keyboard
.pressed
= {}
8 EventManager
.keyboard
.released
= {}
11 EventManager
.mouse
= {}
12 EventManager
.mouse
.motion
= nil
13 EventManager
.mouse
.pressed
= {}
14 EventManager
.mouse
.released
= {}
17 --joystick handling is inherently difficult because there can be multiple joysticks
18 --thus, instead of having it be that the axis/button/etc... is the index for each,
19 -- the index is the joystick that the event originates from.
20 EventManager
.joystick
= {}
21 EventManager
.joystick
.axis_motion
= {}
22 EventManager
.joystick
.ball_motion
= {}
23 EventManager
.joystick
.hat_motion
= {}
24 EventManager
.joystick
.pressed
= {}
25 EventManager
.joystick
.released
= {}
28 EventManager
.quit
= nil
33 EventManager
.state
= 0
41 function EventManager
:new(o
)
49 --gets and evaluates events
50 function EventManager
:gather_events()
52 self
.type, self
.state
, self
.arg1
, self
.arg2
, self
.arg3
, self
.arg4
= get_event()
54 while (self
.type ~= 0) do
57 if self
.type == "keyboard" then
58 if self
.keyboard
[self
.state
][self
.arg1
] then self
.keyboard
[self
.state
][self
.arg1
]() end
61 elseif self
.type == "mouse" then
62 if self
.state
== "motion" then
63 if self
.mouse
.motion
then self
.mouse
.motion(self
.arg1
, self
.arg2
, self
.arg3
, self
.arg4
) end
65 if self
.mouse
[self
.state
][self
.arg1
] then self
.mouse
[self
.state
][self
.arg1
](self
.arg2
, self
.arg3
) end
69 elseif self
.type == "joystick" then
70 if self
.state
== "axis_motion" then
71 if self
.joystick
.axis_motion
[self
.arg1
] then self
.joystick
.axis_motion
[self
.arg1
](self
.arg2
, self
.arg3
) end
72 elseif self
.state
== "ball_motion" then
73 if self
.joystick
.ball_motion
[self
.arg1
] then self
.joystick
.ball_motion
[self
.arg1
](self
.arg2
, self
.arg3
, self
.arg4
) end
74 elseif self
.state
== "hat_motion" then
75 if self
.joystick
.hat_motion
[self
.arg1
] then self
.joystick
.hat_motion
[self
.arg1
](self
.arg2
, self
.arg3
) end
77 if self
.joystick
[self
.state
][self
.arg1
] then self
.joystick
[self
.state
][self
.arg1
](self
.arg2
) end
81 elseif self
.type == "quit" then
82 if self
.quit
then self
.quit() end
85 self
.type, self
.state
, self
.arg1
, self
.arg2
, self
.arg3
, self
.arg4
= get_event()