2022-09-03 22:13:22 +01:00
|
|
|
-- love.run: main entrypoint function for LÖVE
|
2022-05-23 02:27:48 +01:00
|
|
|
--
|
2023-01-21 05:07:59 +00:00
|
|
|
-- Most apps can just use the default shown in https://love2d.org/wiki/love.run,
|
2023-08-26 23:04:45 +01:00
|
|
|
-- but we need to override it to:
|
2023-09-04 08:33:27 +01:00
|
|
|
-- * recover from errors (by switching to the source editor)
|
2023-08-26 23:04:45 +01:00
|
|
|
-- * 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
|
|
|
|
-- control.
|
2022-05-22 16:54:33 +01:00
|
|
|
function love.run()
|
2022-09-03 22:13:22 +01:00
|
|
|
App.snapshot_love()
|
2022-05-23 02:27:48 +01:00
|
|
|
-- Tests always run at the start.
|
2022-09-03 22:13:22 +01:00
|
|
|
App.run_tests_and_initialize()
|
2022-05-25 21:35:32 +01:00
|
|
|
--? print('==')
|
2022-05-22 16:54:33 +01:00
|
|
|
|
2022-08-06 17:35:42 +01:00
|
|
|
love.timer.step()
|
2022-05-22 16:54:33 +01:00
|
|
|
local dt = 0
|
|
|
|
|
|
|
|
return function()
|
|
|
|
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
|
2023-09-04 08:33:27 +01:00
|
|
|
xpcall(function() love.handlers[name](a,b,c,d,e,f) end, handle_error)
|
2022-05-22 16:54:33 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-27 21:10:23 +00:00
|
|
|
dt = love.timer.step()
|
2023-09-04 08:33:27 +01:00
|
|
|
xpcall(function() App.update(dt) end, handle_error)
|
2022-11-27 21:10:23 +00:00
|
|
|
|
2022-08-06 17:35:42 +01:00
|
|
|
love.graphics.origin()
|
|
|
|
love.graphics.clear(love.graphics.getBackgroundColor())
|
2023-09-04 08:33:27 +01:00
|
|
|
xpcall(App.draw, handle_error)
|
2022-08-06 17:35:42 +01:00
|
|
|
love.graphics.present()
|
2022-05-22 16:54:33 +01:00
|
|
|
|
2022-08-06 17:35:42 +01:00
|
|
|
love.timer.sleep(0.001)
|
2022-05-22 16:54:33 +01:00
|
|
|
end
|
|
|
|
end
|
2022-05-23 02:27:48 +01:00
|
|
|
|
2023-09-04 08:33:27 +01:00
|
|
|
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
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
-- 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.
|
2022-05-23 02:27:48 +01:00
|
|
|
--
|
2023-08-26 23:04:45 +01:00
|
|
|
-- Not everything is so wrapped yet. Sometimes you still have to use love.*
|
|
|
|
-- primitives directly.
|
2022-05-23 02:27:48 +01:00
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
App = {}
|
2022-05-23 02:27:48 +01:00
|
|
|
|
2022-09-03 22:13:22 +01:00
|
|
|
-- save/restore various framework globals we care about -- only on very first load
|
|
|
|
function App.snapshot_love()
|
|
|
|
if Love_snapshot then return end
|
|
|
|
Love_snapshot = {}
|
|
|
|
-- save the entire initial font; it doesn't seem reliably recreated using newFont
|
|
|
|
Love_snapshot.initial_font = love.graphics.getFont()
|
|
|
|
end
|
|
|
|
|
|
|
|
function App.undo_initialize()
|
|
|
|
love.graphics.setFont(Love_snapshot.initial_font)
|
|
|
|
end
|
|
|
|
|
|
|
|
function App.run_tests_and_initialize()
|
|
|
|
App.load()
|
2023-01-21 05:42:52 +00:00
|
|
|
Test_errors = {}
|
2022-09-03 22:13:22 +01:00
|
|
|
App.run_tests()
|
2023-01-21 05:42:52 +00:00
|
|
|
if #Test_errors > 0 then
|
2023-04-02 02:13:44 +01:00
|
|
|
error(('There were %d test failures:\n\n%s'):format(#Test_errors, table.concat(Test_errors)))
|
2023-01-21 05:42:52 +00:00
|
|
|
end
|
2022-09-03 22:13:22 +01:00
|
|
|
App.disable_tests()
|
|
|
|
App.initialize_globals()
|
|
|
|
App.initialize(love.arg.parseGameArguments(arg), arg)
|
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
function App.run_tests()
|
|
|
|
local sorted_names = {}
|
|
|
|
for name,binding in pairs(_G) do
|
|
|
|
if name:find('test_') == 1 then
|
|
|
|
table.insert(sorted_names, name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(sorted_names)
|
|
|
|
for _,name in ipairs(sorted_names) do
|
|
|
|
App.initialize_for_test()
|
|
|
|
--? print('=== '..name)
|
|
|
|
--? _G[name]()
|
|
|
|
xpcall(_G[name], function(err) prepend_debug_info_to_test_failure(name, err) end)
|
|
|
|
end
|
|
|
|
-- clean up all test methods
|
|
|
|
for _,name in ipairs(sorted_names) do
|
|
|
|
_G[name] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-23 02:27:48 +01:00
|
|
|
function App.initialize_for_test()
|
2023-04-12 05:33:33 +01:00
|
|
|
App.screen.init{width=100, height=50}
|
2022-05-23 02:27:48 +01:00
|
|
|
App.screen.contents = {} -- clear screen
|
2022-05-25 20:59:12 +01:00
|
|
|
App.filesystem = {}
|
2023-08-31 03:04:06 +01:00
|
|
|
App.source_dir = ''
|
|
|
|
App.current_dir = ''
|
|
|
|
App.save_dir = ''
|
2022-12-24 01:16:19 +00:00
|
|
|
App.fake_keys_pressed = {}
|
2022-06-12 16:26:37 +01:00
|
|
|
App.fake_mouse_state = {x=-1, y=-1}
|
2023-01-23 06:12:58 +00:00
|
|
|
App.initialize_globals()
|
2022-05-23 02:27:48 +01:00
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
-- App.screen.resize and App.screen.move seem like better names than
|
|
|
|
-- love.window.setMode and love.window.setPosition respectively. They'll
|
|
|
|
-- be side-effect-free during tests, and they'll save their results in
|
|
|
|
-- attributes of App.screen for easy access.
|
|
|
|
|
|
|
|
App.screen={}
|
|
|
|
|
|
|
|
-- Use App.screen.init in tests to initialize the fake screen.
|
2022-05-23 02:27:48 +01:00
|
|
|
function App.screen.init(dims)
|
|
|
|
App.screen.width = dims.width
|
|
|
|
App.screen.height = dims.height
|
|
|
|
end
|
|
|
|
|
2022-09-17 18:47:47 +01:00
|
|
|
function App.screen.resize(width, height, flags)
|
|
|
|
App.screen.width = width
|
|
|
|
App.screen.height = height
|
|
|
|
App.screen.flags = flags
|
|
|
|
end
|
|
|
|
|
|
|
|
function App.screen.size()
|
|
|
|
return App.screen.width, App.screen.height, App.screen.flags
|
|
|
|
end
|
|
|
|
|
|
|
|
function App.screen.move(x,y, displayindex)
|
|
|
|
App.screen.x = x
|
|
|
|
App.screen.y = y
|
|
|
|
App.screen.displayindex = displayindex
|
|
|
|
end
|
|
|
|
|
|
|
|
function App.screen.position()
|
|
|
|
return App.screen.x, App.screen.y, App.screen.displayindex
|
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
-- If you use App.screen.print instead of love.graphics.print,
|
|
|
|
-- tests will be able to check what was printed using App.screen.check below.
|
|
|
|
--
|
|
|
|
-- One drawback of this approach: the y coordinate used depends on font size,
|
|
|
|
-- which feels brittle.
|
|
|
|
|
2022-05-23 02:27:48 +01:00
|
|
|
function App.screen.print(msg, x,y)
|
|
|
|
local screen_row = 'y'..tostring(y)
|
2022-05-23 23:38:42 +01:00
|
|
|
--? print('drawing "'..msg..'" at y '..tostring(y))
|
2022-05-23 02:27:48 +01:00
|
|
|
local screen = App.screen
|
|
|
|
if screen.contents[screen_row] == nil then
|
|
|
|
screen.contents[screen_row] = {}
|
|
|
|
for i=0,screen.width-1 do
|
|
|
|
screen.contents[screen_row][i] = ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if x < screen.width then
|
|
|
|
screen.contents[screen_row][x] = msg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
function App.screen.check(y, expected_contents, msg)
|
|
|
|
--? print('checking for "'..expected_contents..'" at y '..tostring(y))
|
|
|
|
local screen_row = 'y'..tostring(y)
|
|
|
|
local contents = ''
|
|
|
|
if App.screen.contents[screen_row] == nil then
|
|
|
|
error('no text at y '..tostring(y))
|
|
|
|
end
|
|
|
|
for i,s in ipairs(App.screen.contents[screen_row]) do
|
|
|
|
contents = contents..s
|
|
|
|
end
|
|
|
|
check_eq(contents, expected_contents, msg)
|
2022-07-12 07:03:27 +01:00
|
|
|
end
|
|
|
|
|
2023-08-30 14:43:01 +01:00
|
|
|
-- If you access the time using App.get_time instead of love.timer.getTime,
|
2023-08-26 23:04:45 +01:00
|
|
|
-- tests will be able to move the time back and forwards as needed using
|
|
|
|
-- App.wait_fake_time below.
|
2022-09-18 09:26:20 +01:00
|
|
|
|
2022-06-17 23:42:53 +01:00
|
|
|
App.time = 1
|
2023-08-30 14:43:01 +01:00
|
|
|
function App.get_time()
|
2022-06-17 23:42:53 +01:00
|
|
|
return App.time
|
|
|
|
end
|
|
|
|
function App.wait_fake_time(t)
|
|
|
|
App.time = App.time + t
|
|
|
|
end
|
|
|
|
|
2022-05-30 00:37:31 +01:00
|
|
|
function App.width(text)
|
2023-04-02 00:29:17 +01:00
|
|
|
return love.graphics.getFont():getWidth(text)
|
2022-05-30 00:37:31 +01:00
|
|
|
end
|
|
|
|
|
2023-08-30 14:43:01 +01:00
|
|
|
-- If you access the clipboard using App.get_clipboard and App.set_clipboard
|
|
|
|
-- instead of love.system.getClipboardText and love.system.setClipboardText
|
|
|
|
-- respectively, tests will be able to manipulate the clipboard by
|
|
|
|
-- reading/writing App.clipboard.
|
2023-08-26 23:04:45 +01:00
|
|
|
|
2022-06-03 02:52:49 +01:00
|
|
|
App.clipboard = ''
|
2023-08-30 14:43:01 +01:00
|
|
|
function App.get_clipboard()
|
2022-06-03 02:52:49 +01:00
|
|
|
return App.clipboard
|
|
|
|
end
|
2023-08-30 14:43:01 +01:00
|
|
|
function App.set_clipboard(s)
|
2022-06-03 02:52:49 +01:00
|
|
|
App.clipboard = s
|
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
-- In tests I mostly send chords all at once to the keyboard handlers.
|
|
|
|
-- However, you'll occasionally need to check if a key is down outside a handler.
|
|
|
|
-- If you use App.key_down instead of love.keyboard.isDown, tests will be able to
|
|
|
|
-- simulate keypresses using App.fake_key_press and App.fake_key_release
|
|
|
|
-- below. This isn't very realistic, though, and it's up to tests to
|
|
|
|
-- orchestrate key presses that correspond to the handlers they invoke.
|
|
|
|
|
2022-12-24 01:16:19 +00:00
|
|
|
App.fake_keys_pressed = {}
|
2023-08-26 23:04:45 +01:00
|
|
|
function App.key_down(key)
|
|
|
|
return App.fake_keys_pressed[key]
|
|
|
|
end
|
|
|
|
|
2022-06-12 16:26:37 +01:00
|
|
|
function App.fake_key_press(key)
|
2022-12-24 01:16:19 +00:00
|
|
|
App.fake_keys_pressed[key] = true
|
2022-06-04 22:14:26 +01:00
|
|
|
end
|
2022-06-12 16:26:37 +01:00
|
|
|
function App.fake_key_release(key)
|
2022-12-24 01:16:19 +00:00
|
|
|
App.fake_keys_pressed[key] = nil
|
2022-06-04 22:14:26 +01:00
|
|
|
end
|
2023-08-26 23:04:45 +01:00
|
|
|
|
|
|
|
-- Tests mostly will invoke mouse handlers directly. However, you'll
|
|
|
|
-- occasionally need to check if a mouse button is down outside a handler.
|
|
|
|
-- If you use App.mouse_down instead of love.mouse.isDown, tests will be able to
|
|
|
|
-- simulate mouse clicks using App.fake_mouse_press and App.fake_mouse_release
|
|
|
|
-- below. This isn't very realistic, though, and it's up to tests to
|
|
|
|
-- orchestrate presses that correspond to the handlers they invoke.
|
2022-06-12 16:26:37 +01:00
|
|
|
|
|
|
|
App.fake_mouse_state = {x=-1, y=-1} -- x,y always set
|
2023-08-26 23:04:45 +01:00
|
|
|
|
2022-06-12 16:26:37 +01:00
|
|
|
function App.mouse_move(x,y)
|
|
|
|
App.fake_mouse_state.x = x
|
|
|
|
App.fake_mouse_state.y = y
|
|
|
|
end
|
2022-08-23 17:36:08 +01:00
|
|
|
function App.mouse_down(mouse_button)
|
|
|
|
return App.fake_mouse_state[mouse_button]
|
2022-06-12 16:26:37 +01:00
|
|
|
end
|
|
|
|
function App.mouse_x()
|
|
|
|
return App.fake_mouse_state.x
|
|
|
|
end
|
|
|
|
function App.mouse_y()
|
|
|
|
return App.fake_mouse_state.y
|
2022-06-04 22:14:26 +01:00
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
function App.fake_mouse_press(x,y, mouse_button)
|
|
|
|
App.fake_mouse_state.x = x
|
|
|
|
App.fake_mouse_state.y = y
|
|
|
|
App.fake_mouse_state[mouse_button] = true
|
|
|
|
end
|
|
|
|
function App.fake_mouse_release(x,y, mouse_button)
|
|
|
|
App.fake_mouse_state.x = x
|
|
|
|
App.fake_mouse_state.y = y
|
|
|
|
App.fake_mouse_state[mouse_button] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- If you use App.open_for_reading and App.open_for_writing instead of other
|
|
|
|
-- various Lua and LÖVE helpers, tests will be able to check the results of
|
|
|
|
-- file operations inside the App.filesystem table.
|
|
|
|
|
|
|
|
function App.open_for_reading(filename)
|
|
|
|
if App.filesystem[filename] then
|
|
|
|
return {
|
|
|
|
lines = function(self)
|
|
|
|
return App.filesystem[filename]:gmatch('[^\n]+')
|
|
|
|
end,
|
2023-09-08 22:03:40 +01:00
|
|
|
read = function(self)
|
|
|
|
return App.filesystem[filename]
|
|
|
|
end,
|
2023-08-26 23:04:45 +01:00
|
|
|
close = function(self)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-09-09 16:56:21 +01:00
|
|
|
function App.read_file(filename)
|
|
|
|
return App.filesystem[filename]
|
|
|
|
end
|
|
|
|
|
2023-09-09 16:27:27 +01:00
|
|
|
function App.open_for_writing(filename)
|
|
|
|
App.filesystem[filename] = ''
|
|
|
|
return {
|
|
|
|
write = function(self, s)
|
|
|
|
App.filesystem[filename] = App.filesystem[filename]..s
|
|
|
|
end,
|
|
|
|
close = function(self)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-09-09 16:56:21 +01:00
|
|
|
function App.write_file(filename, contents)
|
|
|
|
App.filesystem[filename] = contents
|
|
|
|
return --[[status]] true
|
|
|
|
end
|
|
|
|
|
2023-09-08 22:03:40 +01:00
|
|
|
function App.mkdir(dirname)
|
|
|
|
-- nothing in test mode
|
|
|
|
end
|
|
|
|
|
|
|
|
function App.remove(filename)
|
|
|
|
App.filesystem[filename] = nil
|
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
-- Some helpers to trigger an event and then refresh the screen. Akin to one
|
|
|
|
-- iteration of the event loop.
|
|
|
|
|
2022-06-20 18:48:35 +01:00
|
|
|
-- all textinput events are also keypresses
|
2022-07-13 06:13:06 +01:00
|
|
|
-- TODO: handle chords of multiple keys
|
2022-05-23 02:27:48 +01:00
|
|
|
function App.run_after_textinput(t)
|
2022-06-20 18:48:35 +01:00
|
|
|
App.keypressed(t)
|
2022-05-23 02:27:48 +01:00
|
|
|
App.textinput(t)
|
2022-06-20 18:48:35 +01:00
|
|
|
App.keyreleased(t)
|
2022-05-23 02:27:48 +01:00
|
|
|
App.screen.contents = {}
|
|
|
|
App.draw()
|
|
|
|
end
|
|
|
|
|
2022-06-20 18:48:35 +01:00
|
|
|
-- not all keys are textinput
|
2022-07-13 06:13:06 +01:00
|
|
|
-- TODO: handle chords of multiple keys
|
2022-06-20 18:48:35 +01:00
|
|
|
function App.run_after_keychord(chord)
|
2022-12-24 01:16:19 +00:00
|
|
|
App.keychord_press(chord)
|
2022-06-20 18:48:35 +01:00
|
|
|
App.keyreleased(chord)
|
2022-05-23 16:13:58 +01:00
|
|
|
App.screen.contents = {}
|
|
|
|
App.draw()
|
|
|
|
end
|
|
|
|
|
2022-08-23 17:36:08 +01:00
|
|
|
function App.run_after_mouse_click(x,y, mouse_button)
|
|
|
|
App.fake_mouse_press(x,y, mouse_button)
|
|
|
|
App.mousepressed(x,y, mouse_button)
|
|
|
|
App.fake_mouse_release(x,y, mouse_button)
|
|
|
|
App.mousereleased(x,y, mouse_button)
|
2022-06-12 18:46:25 +01:00
|
|
|
App.screen.contents = {}
|
|
|
|
App.draw()
|
|
|
|
end
|
|
|
|
|
2022-08-23 17:36:08 +01:00
|
|
|
function App.run_after_mouse_press(x,y, mouse_button)
|
|
|
|
App.fake_mouse_press(x,y, mouse_button)
|
|
|
|
App.mousepressed(x,y, mouse_button)
|
2022-05-25 21:38:33 +01:00
|
|
|
App.screen.contents = {}
|
|
|
|
App.draw()
|
|
|
|
end
|
|
|
|
|
2022-08-23 17:36:08 +01:00
|
|
|
function App.run_after_mouse_release(x,y, mouse_button)
|
|
|
|
App.fake_mouse_release(x,y, mouse_button)
|
|
|
|
App.mousereleased(x,y, mouse_button)
|
2022-06-03 16:11:18 +01:00
|
|
|
App.screen.contents = {}
|
|
|
|
App.draw()
|
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
-- miscellaneous internal helpers
|
2022-05-23 02:27:48 +01:00
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
function App.color(color)
|
|
|
|
love.graphics.setColor(color.r, color.g, color.b, color.a)
|
2022-05-25 20:59:12 +01:00
|
|
|
end
|
|
|
|
|
2023-08-26 23:04:45 +01:00
|
|
|
function colortable(app_color)
|
|
|
|
return {app_color.r, app_color.g, app_color.b, app_color.a}
|
2022-05-23 02:27:48 +01:00
|
|
|
end
|
|
|
|
|
2023-01-21 05:42:52 +00:00
|
|
|
-- prepend file/line/test
|
|
|
|
function prepend_debug_info_to_test_failure(test_name, err)
|
|
|
|
local err_without_line_number = err:gsub('^[^:]*:[^:]*: ', '')
|
2023-04-02 04:03:43 +01:00
|
|
|
local stack_trace = debug.traceback('', --[[stack frame]]5)
|
2023-01-21 05:42:52 +00:00
|
|
|
local file_and_line_number = stack_trace:gsub('stack traceback:\n', ''):gsub(': .*', '')
|
|
|
|
local full_error = file_and_line_number..':'..test_name..' -- '..err_without_line_number
|
2023-03-26 17:36:41 +01:00
|
|
|
--? local full_error = file_and_line_number..':'..test_name..' -- '..err_without_line_number..'\t\t'..stack_trace:gsub('\n', '\n\t\t')
|
2023-01-21 05:42:52 +00:00
|
|
|
table.insert(Test_errors, full_error)
|
|
|
|
end
|
|
|
|
|
2023-08-31 03:04:06 +01:00
|
|
|
nativefs = require 'nativefs'
|
|
|
|
|
2023-09-04 08:22:31 +01:00
|
|
|
local Keys_down = {}
|
|
|
|
|
2022-05-23 02:27:48 +01:00
|
|
|
-- 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
|
2023-09-04 08:22:31 +01:00
|
|
|
-- 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
|
2022-05-23 02:27:48 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- test methods are disallowed outside tests
|
2022-08-19 18:29:48 +01:00
|
|
|
App.run_tests = nil
|
|
|
|
App.disable_tests = nil
|
2022-05-23 02:27:48 +01:00
|
|
|
App.screen.init = nil
|
2022-05-25 20:59:12 +01:00
|
|
|
App.filesystem = nil
|
2022-06-17 23:42:53 +01:00
|
|
|
App.time = nil
|
2022-05-23 02:27:48 +01:00
|
|
|
App.run_after_textinput = nil
|
2022-05-25 20:59:12 +01:00
|
|
|
App.run_after_keychord = nil
|
2022-06-04 22:14:26 +01:00
|
|
|
App.keypress = nil
|
|
|
|
App.keyrelease = nil
|
2022-06-17 23:42:53 +01:00
|
|
|
App.run_after_mouse_click = nil
|
|
|
|
App.run_after_mouse_press = nil
|
|
|
|
App.run_after_mouse_release = nil
|
2022-12-24 01:16:19 +00:00
|
|
|
App.fake_keys_pressed = nil
|
2022-06-12 16:26:37 +01:00
|
|
|
App.fake_key_press = nil
|
|
|
|
App.fake_key_release = nil
|
|
|
|
App.fake_mouse_state = nil
|
|
|
|
App.fake_mouse_press = nil
|
|
|
|
App.fake_mouse_release = nil
|
2022-05-23 02:27:48 +01:00
|
|
|
-- other methods dispatch to real hardware
|
2022-09-17 18:47:47 +01:00
|
|
|
App.screen.resize = love.window.setMode
|
|
|
|
App.screen.size = love.window.getMode
|
|
|
|
App.screen.move = love.window.setPosition
|
|
|
|
App.screen.position = love.window.getPosition
|
2022-05-23 02:27:48 +01:00
|
|
|
App.screen.print = love.graphics.print
|
2023-08-31 03:04:06 +01:00
|
|
|
App.open_for_reading =
|
|
|
|
function(filename)
|
|
|
|
local result = nativefs.newFile(filename)
|
|
|
|
local ok, err = result:open('r')
|
|
|
|
if ok then
|
|
|
|
return result
|
|
|
|
else
|
|
|
|
return ok, err
|
2022-09-05 20:39:28 +01:00
|
|
|
end
|
2023-08-31 03:04:06 +01:00
|
|
|
end
|
2023-09-09 17:09:14 +01:00
|
|
|
App.read_file =
|
2023-09-09 16:56:21 +01:00
|
|
|
function(path)
|
|
|
|
if not is_absolute_path(path) then
|
|
|
|
return --[[status]] false, 'Please use an unambiguous absolute path.'
|
|
|
|
end
|
|
|
|
local f, err = App.open_for_reading(path)
|
|
|
|
if err then
|
|
|
|
return --[[status]] false, err
|
|
|
|
end
|
|
|
|
local contents = f:read()
|
|
|
|
f:close()
|
|
|
|
return contents
|
|
|
|
end
|
2023-08-31 03:04:06 +01:00
|
|
|
App.open_for_writing =
|
|
|
|
function(filename)
|
|
|
|
local result = nativefs.newFile(filename)
|
|
|
|
local ok, err = result:open('w')
|
|
|
|
if ok then
|
|
|
|
return result
|
|
|
|
else
|
|
|
|
return ok, err
|
2022-09-05 20:39:28 +01:00
|
|
|
end
|
2023-08-31 03:04:06 +01:00
|
|
|
end
|
2023-09-09 17:09:14 +01:00
|
|
|
App.write_file =
|
2023-09-09 17:27:56 +01:00
|
|
|
function(path, contents)
|
2023-09-09 16:56:21 +01:00
|
|
|
if not is_absolute_path(path) then
|
|
|
|
return --[[status]] false, 'Please use an unambiguous absolute path.'
|
|
|
|
end
|
2023-09-09 17:27:56 +01:00
|
|
|
local f, err = App.open_for_writing(path)
|
2023-09-09 16:56:21 +01:00
|
|
|
if err then
|
|
|
|
return --[[status]] false, err
|
|
|
|
end
|
|
|
|
f:write(contents)
|
|
|
|
f:close()
|
2023-09-09 17:09:14 +01:00
|
|
|
return --[[status]] true
|
2023-09-09 16:56:21 +01:00
|
|
|
end
|
2023-08-31 03:04:06 +01:00
|
|
|
App.files = nativefs.getDirectoryItems
|
2023-09-08 22:03:40 +01:00
|
|
|
App.mkdir = nativefs.createDirectory
|
|
|
|
App.remove = nativefs.remove
|
2023-08-31 03:04:06 +01:00
|
|
|
App.source_dir = love.filesystem.getSource()..'/'
|
|
|
|
App.current_dir = nativefs.getWorkingDirectory()..'/'
|
|
|
|
App.save_dir = love.filesystem.getSaveDirectory()..'/'
|
2023-08-30 14:43:01 +01:00
|
|
|
App.get_time = love.timer.getTime
|
|
|
|
App.get_clipboard = love.system.getClipboardText
|
|
|
|
App.set_clipboard = love.system.setClipboardText
|
2023-09-04 08:22:31 +01:00
|
|
|
App.key_down = function(key) return Keys_down[key] end
|
2022-06-12 16:26:37 +01:00
|
|
|
App.mouse_move = love.mouse.setPosition
|
|
|
|
App.mouse_down = love.mouse.isDown
|
|
|
|
App.mouse_x = love.mouse.getX
|
|
|
|
App.mouse_y = love.mouse.getY
|
2022-05-23 02:27:48 +01:00
|
|
|
end
|