Merge text0

This commit is contained in:
Kartik K. Agaram 2023-09-04 14:17:04 -07:00
commit ce0b127296
1 changed files with 20 additions and 3 deletions

23
app.lua
View File

@ -1,9 +1,12 @@
nativefs = require 'nativefs'
local Keys_down = {}
-- main entrypoint for LÖVE
--
-- Most apps can just use the default shown in https://love2d.org/wiki/love.run,
-- but we need to override it to:
-- * recover from errors (by sending them to the driver and waiting for a command)
-- * run all tests (functions starting with 'test_') on startup, and
-- * save some state that makes it possible to switch between the main app
-- and a source editor, while giving each the illusion of complete
@ -14,7 +17,21 @@ function love.run()
-- have LÖVE delegate all handlers to App if they exist
for name in pairs(love.handlers) do
if App[name] then
love.handlers[name] = App[name]
-- love.keyboard.isDown doesn't work on Android, so emulate it using
-- keypressed and keyreleased events
if name == 'keypressed' then
love.handlers[name] = function(key, scancode, isrepeat)
Keys_down[key] = true
return App.keypressed(key, scancode, isrepeat)
end
elseif name == 'keyreleased' then
love.handlers[name] = function(key, scancode)
Keys_down[key] = nil
return App.keyreleased(key, scancode)
end
else
love.handlers[name] = App[name]
end
end
end
@ -46,7 +63,7 @@ function love.run()
App.fake_mouse_state = nil
App.fake_mouse_press = nil
App.fake_mouse_release = nil
-- dispatch some methods to real hardware
-- other methods dispatch to real hardware
App.screen.resize = love.window.setMode
App.screen.size = love.window.getMode
App.screen.move = love.window.setPosition
@ -79,7 +96,7 @@ function love.run()
App.get_time = love.timer.getTime
App.get_clipboard = love.system.getClipboardText
App.set_clipboard = love.system.setClipboardText
App.key_down = love.keyboard.isDown
App.key_down = function(key) return Keys_down[key] end
App.mouse_move = love.mouse.setPosition
App.mouse_down = love.mouse.isDown
App.mouse_x = love.mouse.getX