heroes-of-nerevelon/lib/controls.lua
Neckrat d07d26680c implemented character movement & initial selector
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
2025-08-09 02:32:15 +03:00

37 lines
901 B
Lua

--- @alias Device "mouse" | "key" | "pad"
--- @param device Device
--- @param key string
local function control(device, key)
--- @type {type: Device, key: string}
local t = { type = device, key = key }
return t
end
local keymap = {
cameraMoveUp = control("key", "w"),
cameraMoveLeft = control("key", "a"),
cameraMoveRight = control("key", "d"),
cameraMoveDown = control("key", "s"),
cameraMoveScroll = control("mouse", "3"),
select = control("mouse", "1")
}
function keymap:isDown(key)
if not keymap[key] then return false end
local type = keymap[key].type
local idx = keymap[key].key
if type == "key" then
return love.keyboard.isDown(idx)
end
if type == "mouse" then
if not tonumber(idx) then return false end
return love.mouse.isDown(tonumber(idx) --[[@as number]])
end
return false
end
return keymap