Made keybind editing "backend"

This commit is contained in:
bizcochito
2022-01-18 20:47:55 +01:00
parent 58b4e16251
commit da8b9004b4
2 changed files with 45 additions and 18 deletions

View File

@@ -1,7 +1,9 @@
keybind = {}
Keybind = {}
Keybind.move = {}
Keybind.menu = {}
function keybind:Check(key)
for _, keyname in pairs(key) do
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
@@ -11,11 +13,36 @@ function keybind:Check(key)
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
keybind.moveLeft = {"left", "a"}
keybind.moveRight = {"right", "d"}
keybind.moveUp = {"up", "w"}
keybind.moveDown = {"down", "s"}
keybind.moveJump = {"z", "space"}
keybind.moveAttack = {"x", 1}
keybind.moveDash = {"c", 2}
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()