Merge template-live-editor

This commit is contained in:
Kartik K. Agaram 2023-04-19 20:01:10 -07:00
commit 2f6d8f4bd6
4 changed files with 30 additions and 5 deletions

View File

@ -11,6 +11,7 @@
--
-- Scroll below this function for more details.
function love.run()
App.version_check()
App.snapshot_love()
-- have LÖVE delegate all handlers to App if they exist
for name in pairs(love.handlers) do

View File

@ -1,3 +0,0 @@
function love.conf(t)
t.version = '11.4'
end

View File

@ -296,14 +296,13 @@ end
-- return nil to continue the event loop, non-nil to quit
function live.handle_error(err)
local msg = tostring(err)
-- draw a pause indicator on screen
love.graphics.setColor(1,0,0)
love.graphics.rectangle('fill', 10,10, 3,10)
love.graphics.rectangle('fill', 16,10, 3,10)
love.graphics.present()
-- print stack trace here just in case we ran the app through a terminal
local stack_trace = debug.traceback('Error: '..msg, --[[stack frame]]2):gsub('\n[^\n]+$', '')
local stack_trace = debug.traceback('Error: '..tostring(err), --[[stack frame]]2):gsub('\n[^\n]+$', '')
print(stack_trace)
print('Look in the driver for options to investigate further.')
print("(You probably can't close the app window at this point. If you don't have the driver set up, you might need to force-quit.)")

View File

@ -12,6 +12,16 @@ require 'button'
require 'edit'
Editor_state = {}
function App.version_check()
Mode = 'version_check'
Supported_versions = {'11.4', '11.3', '11.2', '11.1', '11.0'} -- keep these sorted in descending order
local major, minor = love.getVersion()
Version = major..'.'..minor
if array.find(Supported_versions, Version) then
Mode = 'run'
end
end
-- called both in tests and real run
function App.initialize_globals()
-- tests currently mostly clear their own state
@ -128,10 +138,18 @@ function App.filedropped(file)
end
function App.draw()
if Mode == 'version_check' then
love.graphics.setColor(1,1,0)
love.graphics.rectangle('fill', 30,30, 400,400)
love.graphics.setColor(0,0,0)
love.graphics.printf(("This app doesn't support version %s; please use version %s. Press any key to try it with this version anyway."):format(Version, Supported_versions[1]), 40,40, 400)
return
end
if on.draw then on.draw() end
end
function App.update(dt)
if Mode == 'version_check' then return end
Current_time = Current_time + dt
-- some hysteresis while resizing
if Current_time < Last_resize_time + 0.1 then
@ -143,21 +161,25 @@ function App.update(dt)
end
function App.mousepressed(x,y, mouse_button)
if Mode == 'version_check' then return end
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
if on.mouse_press then on.mouse_press(x,y, mouse_button) end
end
function App.mousereleased(x,y, mouse_button)
if Mode == 'version_check' then return end
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
if on.mouse_release then on.mouse_release(x,y, mouse_button) end
end
function App.wheelmoved(dx,dy)
if Mode == 'version_check' then return end
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
if on.mouse_wheel_move then on.mouse_wheel_move(dx,dy) end
end
function App.focus(in_focus)
if Mode == 'version_check' then return end
if in_focus then
Last_focus_time = Current_time
end
@ -172,6 +194,7 @@ end
-- App.keypressed is defined in keychord.lua
function App.keychord_press(chord, key)
if Mode == 'version_check' then return end
-- ignore events for some time after window in focus (mostly alt-tab)
if Current_time < Last_focus_time + 0.01 then
return
@ -181,6 +204,7 @@ function App.keychord_press(chord, key)
end
function App.textinput(t)
if Mode == 'version_check' then return end
-- ignore events for some time after window in focus (mostly alt-tab)
if Current_time < Last_focus_time + 0.01 then
return
@ -190,6 +214,10 @@ function App.textinput(t)
end
function App.keyreleased(key, scancode)
if Mode == 'version_check' then
Mode = 'run'
return
end
-- ignore events for some time after window in focus (mostly alt-tab)
if Current_time < Last_focus_time + 0.01 then
return