-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput.lua
More file actions
44 lines (36 loc) · 859 Bytes
/
Copy pathinput.lua
File metadata and controls
44 lines (36 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--centralised input
local path = (...):gsub(".input", "")
local function relative_require(module)
return require(path .. "." .. module)
end
local input = {
keyboard = relative_require("keyboard")(),
mouse = relative_require("mouse")(),
gamepad = relative_require("gamepad")(1),
}
input.mode = "desktop"
function input:update(dt)
self.keyboard:update(dt)
self.mouse:update(dt)
self.gamepad:update(dt)
local old_mode = self.mode
if
self.keyboard:any_just_pressed()
or self.mouse:any_just_pressed()
or self.mouse.delta:length_squared() > 10
then
self.mode = "desktop"
elseif self.gamepad:any_just_pressed_even_axes() then
self.mode = "gamepad"
end
--clear on first press
if old_mode ~= self.mode then
self:clear()
end
end
function input:clear()
self.keyboard:clear()
self.mouse:clear()
self.gamepad:clear()
end
return input