local live = require 'live' -- love.keyboard.isDown doesn't work on Android, so emulate it using -- keypressed and keyreleased events local Keys_down = {} function key_down(key) return Keys_down[key] end -- 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. function love.run() love.handlers.keypressed = function(key, scancode, is_repeat) Keys_down[key] = true if love.keypressed then return love.keypressed(key, scancode, is_repeat) end end love.handlers.keyreleased = function(key, scancode) Keys_down[key] = nil if love.keyreleased then return love.keyreleased(key, scancode) end end if love.load then xpcall(function() love.load(love.arg.parseGameArguments(arg), arg) end, live.handle_initialization_error) end if love.timer then love.timer.step() end -- protect against runtime errors return function() local status, result = xpcall(run_frame, live.handle_error) return result end end -- one iteration of the event loop -- return nil to continue the event loop, non-nil to quit function run_frame() if love.event then love.event.pump() for name, a,b,c,d,e,f in love.event.poll() do if name == 'quit' then if not love.quit or not love.quit() then return a or 0 end end love.handlers[name](a,b,c,d,e,f) end end local dt = 0 if love.timer then dt = love.timer.step() end if love.update then love.update(dt) end if love.graphics and love.graphics.isActive() then love.graphics.origin() love.graphics.clear(love.graphics.getBackgroundColor()) if love.draw then love.draw() end love.graphics.present() end if love.timer then love.timer.sleep(0.001) end end -- Some helpers for Carousel programs. -- -- I feel ambivalent about these in Dec 2024. -- -- My apps originally included a harness for automated tests. -- This harness depended on apps using shims for a few things I wanted to -- test. -- That way my app could call say App.screen.print, and tests would not -- actually draw to the real screen. -- -- However, tests aren't really a focus of Lua Carousel, and they were not a -- priority for Carousel2's upstreams. -- I still ended up using some of the App.* names in older example programs on -- the Lua Carousel devlog. -- -- I guess I'll continue to support the bare minimum of App.* names for now -- just because adding corrections to the devlog seems like a lot of clutter. -- -- I do care very much that someone can go to any older program on the devlog -- and it continue to run on newer versions of Carousel. -- -- But for now I don't care about these App.* names beyond making those older -- devlog posts work. I'm not going to actually use them going forward. For -- now.. App = {} function App.width(text) return love.graphics.getFont():getWidth(text) end local function solo_touch() local touches = love.touch.getTouches() return #touches == 1 end function App.mouse_down(mouse_button) return love.mouse.isDown(mouse_button) or solo_touch() end local function solo_touchX() local touches = love.touch.getTouches() if #touches ~= 1 then return end local x,y = love.touch.getPosition(touches[1]) return x end function App.mouse_x() return love.mouse.getX() or solo_touchX() end local function solo_touchY() local touches = love.touch.getTouches() if #touches ~= 1 then return end local x,y = love.touch.getPosition(touches[1]) return y end function App.mouse_y() return love.mouse.getY() or solo_touchY() end -- Some useful helpers for programs. local major_version, _ = love.getVersion() major_version = tonumber(major_version) if major_version < 12 then nativefs = require 'nativefs' end json = require 'json' utf8 = require 'utf8' array = require 'array' my_utf8 = require 'my_utf8' utils = require 'utils' Foreground_color = {0, 0, 0} -- available to app; indexed by position rather than r/g/b to work with select_rgb colorize = require 'colorize' -- must come after Foreground_color is defined require 'button' require 'wav'