Mothback/code/keybind.lua

84 lines
1.9 KiB
Lua
Raw Normal View History

2022-01-18 19:47:55 +00:00
Keybind = {}
Keybind.move = {}
Keybind.menu = {}
2022-01-19 12:54:33 +00:00
Keybind.debug = {}
Keybind.editor = {}
Keybind.generic = {}
function Keybind:CheckDown(action)
for _, keyname in pairs(action.keys) do
if type(keyname) == "string" then
if love.keyboard.isDown(keyname) then return true end
else
if love.mouse.isDown(keyname) then return true end
end
end
return false
end
function Keybind:HasPressed(action)
if Keybind:CheckDown(action) then
if not action.pressed then
action.pressed = true
return true
end
else
2022-01-19 13:58:49 +00:00
action.pressed = nil
end
return false
end
function Keybind:CheckCollision(cat, key)
2022-01-18 19:47:55 +00:00
for _, action in pairs(cat) do
for _, keyname in pairs(action.keys) do
2022-01-18 19:47:55 +00:00
if key == keyname then return true end
end
end
return false
end
function Keybind:AddKey(action, key)
table.insert(action.keys, key)
2022-01-18 19:47:55 +00:00
end
function Keybind:ChangeKey(action, position, key)
action.keys[position] = key
2022-01-18 19:47:55 +00:00
end
function Keybind:RemoveKeys(action)
action.keys = {}
2022-01-18 19:47:55 +00:00
end
function Keybind:Default()
--Menu
Keybind.menu.pause= { keys = {"escape"}}
2022-02-01 14:05:36 +00:00
Keybind.menu.confirm= { keys = {"z", "space", 1}}
--Move
Keybind.move.left = { keys = {"left", "a"}}
Keybind.move.right = { keys = {"right", "d"}}
Keybind.move.up = { keys = {"up", "w"}}
Keybind.move.down = { keys = {"down", "s"}}
Keybind.move.jump = { keys = {"z", "space"}}
Keybind.move.hook = { keys = {"x", 1}}
Keybind.move.dash = { keys = {"c", 2}}
--Debug
Keybind.debug.debug = { keys = {"f1"}}
Keybind.debug.reposition = { keys = {"f2"}}
Keybind.debug.reload = { keys = {"f3"}}
Keybind.debug.editor = { keys = {"f4"}}
-- Editor
Keybind.editor.palette = { keys = {"tab"}}
-- Generic
Keybind.generic.lclick = { keys = {1}}
Keybind.generic.rclick = { keys = {2}}
Keybind.generic.lshift = { keys = {"lshift"}}
Keybind.generic.lctrl = { keys = {"lctrl"}}
2022-01-18 19:47:55 +00:00
end
2022-01-18 19:47:55 +00:00
-- Set default values at start
Keybind:Default()