Merge pensieve.love
This commit is contained in:
commit
0bfcfd0f7d
41
app.lua
41
app.lua
|
@ -2,6 +2,7 @@
|
|||
--
|
||||
-- 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 switching to the source editor)
|
||||
-- * 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
|
||||
|
@ -24,22 +25,36 @@ function love.run()
|
|||
return a or 0
|
||||
end
|
||||
end
|
||||
love.handlers[name](a,b,c,d,e,f)
|
||||
xpcall(function() love.handlers[name](a,b,c,d,e,f) end, handle_error)
|
||||
end
|
||||
end
|
||||
|
||||
dt = love.timer.step()
|
||||
App.update(dt)
|
||||
xpcall(function() App.update(dt) end, handle_error)
|
||||
|
||||
love.graphics.origin()
|
||||
love.graphics.clear(love.graphics.getBackgroundColor())
|
||||
App.draw()
|
||||
xpcall(App.draw, handle_error)
|
||||
love.graphics.present()
|
||||
|
||||
love.timer.sleep(0.001)
|
||||
end
|
||||
end
|
||||
|
||||
function handle_error(err)
|
||||
Error_message = debug.traceback('Error: ' .. tostring(err), --[[stack frame]]2):gsub('\n[^\n]+$', '')
|
||||
print(Error_message)
|
||||
if Current_app == 'run' then
|
||||
Settings.current_app = 'source'
|
||||
love.filesystem.write('config', json.encode(Settings))
|
||||
load_file_from_source_or_save_directory('main.lua')
|
||||
App.undo_initialize()
|
||||
App.run_tests_and_initialize()
|
||||
else
|
||||
love.event.quit()
|
||||
end
|
||||
end
|
||||
|
||||
-- The rest of this file wraps around various LÖVE primitives to support
|
||||
-- automated tests. Often tests will run with a fake version of a primitive
|
||||
-- that redirects to the real love.* version once we're done with tests.
|
||||
|
@ -349,13 +364,29 @@ end
|
|||
|
||||
nativefs = require 'nativefs'
|
||||
|
||||
local Keys_down = {}
|
||||
|
||||
-- call this once all tests are run
|
||||
-- can't run any tests after this
|
||||
function App.disable_tests()
|
||||
-- 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
|
||||
|
||||
|
@ -411,7 +442,7 @@ function App.disable_tests()
|
|||
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
|
||||
|
|
2
run.lua
2
run.lua
|
@ -842,7 +842,7 @@ function run.keychord_press(chord, key)
|
|||
local old_top = {line=pane.screen_top1.line, pos=pane.screen_top1.pos}
|
||||
edit.keychord_press(pane, chord, key)
|
||||
--? print_and_log(('run.keychord_press A %s %d,%d'):format(chord, Display_settings.x, Display_settings.y))
|
||||
if chord == 'pagedown' then
|
||||
if chord == 'pagedown' or chord == 'S-pagedown' then
|
||||
pan_surface_to_screen_top_of_cursor_pane()
|
||||
elseif chord == 'backspace' or chord == 'up' or chord == 'left' or chord == 'pageup' then
|
||||
bring_cursor_of_cursor_pane_in_view('up')
|
||||
|
|
Loading…
Reference in New Issue
Block a user