2024-09-01 07:44:07 +01:00
local edit = require ' edit '
2022-05-02 16:20:30 +01:00
2024-09-01 07:44:07 +01:00
local Margin_top = 15
local Margin_left = 25
local Margin_right = 25
2022-07-12 21:45:38 +01:00
2024-09-01 07:44:07 +01:00
local Editor -- most data will be here
2022-09-05 19:28:03 +01:00
2024-06-20 05:39:47 +01:00
function love . load ( arg )
2024-09-01 07:44:07 +01:00
if not edit.is_this_love_version_supported ( ) then
local major_version , minor_version = love.getVersion ( )
error (
( " This app hasn't been tested with LÖVE version %d.%d. Please add %d.%d to `is_this_love_version_supported` in edit.lua to try it out, and switch to version %s if you run into issues. " ) : format ( major_version , minor_version , major_version , minor_version , edit.preferred_love_version ( ) ) )
2022-06-07 21:35:56 +01:00
end
2022-07-01 06:46:45 +01:00
2023-01-16 17:48:06 +00:00
love.keyboard . setKeyRepeat ( true )
love.graphics . setBackgroundColor ( 1 , 1 , 1 )
2024-09-01 07:44:07 +01:00
edit.load ( )
2024-06-23 00:21:03 +01:00
2024-09-01 07:44:07 +01:00
-- editor remembers settings across restarts
local settings = edit.load_settings ( )
if settings == nil then
2024-09-17 00:03:19 +01:00
local screen_width , screen_height = love.window . getMode ( )
2024-09-01 07:44:07 +01:00
Editor = edit.new_from_defaults ( Margin_top , Margin_left , screen_width - Margin_right , screen_height - Margin_top )
if # arg > 0 then
edit.load_file ( Editor , arg [ 1 ] )
end
2024-07-21 20:06:21 +01:00
else
2024-09-17 00:03:19 +01:00
Editor = edit.new_from_settings ( settings , Margin_top , Margin_left , settings.width - Margin_right , settings.height - Margin_top )
2024-09-01 07:44:07 +01:00
if # arg > 0 and Editor.filename ~= edit.absolutize ( arg [ 1 ] ) then
edit.load_file ( Editor , arg [ 1 ] )
end
2024-07-21 20:06:21 +01:00
end
2024-06-22 19:00:32 +01:00
2024-06-23 01:09:15 +01:00
if # arg > 1 then
print ( ' ignoring commandline args after ' .. arg [ 1 ] )
2024-06-22 19:00:32 +01:00
end
2024-09-09 05:39:00 +01:00
love.window . setTitle ( ' text2.love - ' .. Editor.filename )
2024-06-22 17:43:02 +01:00
end
2023-12-07 05:32:10 +00:00
2024-09-01 07:44:07 +01:00
function love . filedropped ( file )
-- first make sure to autosave edits on any existing file
edit.final_save ( Editor )
2024-06-23 00:21:03 +01:00
2024-09-01 07:44:07 +01:00
-- clear the slate for the new file
edit.load_file ( Editor , file : getFilename ( ) )
2024-06-23 00:21:03 +01:00
2024-09-20 06:05:57 +01:00
love.window . setTitle ( ' text2.love - ' .. Editor.filename )
2024-06-23 00:21:03 +01:00
end
2024-06-20 05:39:47 +01:00
function love . resize ( w , h )
2024-09-01 08:14:53 +01:00
edit.resize ( Editor , w , h , w - Margin_right , h - Margin_top )
2022-05-16 23:26:22 +01:00
end
2024-06-20 05:39:47 +01:00
function love . draw ( )
2024-09-01 07:44:07 +01:00
love.graphics . setFont ( Editor.font )
2024-07-20 08:24:12 +01:00
edit.draw ( Editor )
2022-05-02 05:55:57 +01:00
end
2024-09-01 07:44:07 +01:00
function love . mousepressed ( x , y , mouse_button )
2024-09-11 05:28:16 +01:00
love.keyboard . setTextInput ( true ) -- bring up keyboard on touch screen
2024-09-01 07:44:07 +01:00
edit.on_mouse_pressed ( Editor , x , y , mouse_button )
2022-07-25 23:33:06 +01:00
end
2024-09-01 07:44:07 +01:00
function love . mousereleased ( x , y , mouse_button )
edit.on_mouse_released ( Editor , x , y , mouse_button )
2022-05-21 22:03:06 +01:00
end
2024-09-01 07:44:07 +01:00
function love . wheelmoved ( dx , dy )
edit.on_mouse_wheel_moved ( Editor , dx , dy )
2022-05-12 06:29:21 +01:00
end
2024-09-01 07:44:07 +01:00
function love . keypressed ( key , scancode , isrepeat )
edit.on_key_pressed ( Editor , key , scancode , isrepeat )
2022-09-03 22:13:22 +01:00
end
2024-09-01 07:44:07 +01:00
function love . textinput ( t )
edit.on_text_input ( Editor , t )
2022-05-02 16:20:30 +01:00
end
2022-08-24 21:27:04 +01:00
2024-09-01 07:44:07 +01:00
function love . keyreleased ( key , scancode )
edit.on_key_released ( Editor , key , scancode )
2024-05-20 06:40:27 +01:00
end
2024-09-01 07:44:07 +01:00
function love . update ( dt )
edit.maybe_autosave ( Editor , dt )
2023-03-24 04:00:09 +00:00
end
2024-09-01 07:44:07 +01:00
function love . quit ( )
edit.save_settings ( Editor )
edit.final_save ( Editor )
2024-05-20 06:41:52 +01:00
end
2024-09-01 07:44:07 +01:00
function love . focus ( in_focus )
edit.on_focus ( in_focus )
2023-12-07 09:08:09 +00:00
end