Mothback/data/scripts/keybind.lua

49 lines
1022 B
Lua

Keybind = {}
Keybind.move = {}
Keybind.menu = {}
function Keybind:Check(action)
for _, keyname in pairs(action) 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:Colision(cat, key)
for _, action in pairs(cat) do
for _, keyname in pairs(action) do
if key == keyname then return true end
end
end
return false
end
function Keybind:Add(action, key)
table.insert(action, key)
end
function Keybind:Change(action, position, key)
action[position] = key
end
function Keybind:Remove(action)
action = {}
end
function Keybind:Default()
Keybind.move.left = {"left", "a"}
Keybind.move.right = {"right", "d"}
Keybind.move.up = {"up", "w"}
Keybind.move.down = {"down", "s"}
Keybind.move.jump = {"z", "space"}
Keybind.move.attack = {"x", 1}
Keybind.move.dash = {"c", 2}
end
-- Set default values at start
Keybind:Default()