From a384f68f03933d2f6c245c59725c5a46c22dc98d Mon Sep 17 00:00:00 2001 From: Nawias Date: Fri, 18 Nov 2022 16:57:13 +0100 Subject: [PATCH] Add support for systems without mouse or keyboard Added nullchecks for love.keyboard and love.mouse for forks of LOVE like LOVEPotion, where keyboard and mouse aren't handled like normal --- baton.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/baton.lua b/baton.lua index 4cc1206..2b4b18d 100644 --- a/baton.lua +++ b/baton.lua @@ -66,19 +66,19 @@ local sourceFunction = {keyboardMouse = {}, joystick = {}} -- checks whether a keyboard key is down or not function sourceFunction.keyboardMouse.key(key) - return love.keyboard.isDown(key) and 1 or 0 + return love.keyboard ~= nil and love.keyboard.isDown ~= nil and love.keyboard.isDown(key) and 1 or 0 end -- checks whether a keyboard key is down or not, -- but it takes a scancode as an input function sourceFunction.keyboardMouse.sc(sc) - return love.keyboard.isScancodeDown(sc) and 1 or 0 + return love.keyboard ~= nil and love.keyboard.isScancodeDown ~= nil and love.keyboard.isScancodeDown(sc) and 1 or 0 end -- checks whether a mouse buttons is down or not. -- note that baton doesn't detect mouse movement, just the buttons function sourceFunction.keyboardMouse.mouse(button) - return love.mouse.isDown(tonumber(button)) and 1 or 0 + return love.mouse ~= nil and love.mouse.isDown ~= nil and love.mouse.isDown(tonumber(button)) and 1 or 0 end -- checks the position of a joystick axis