persist window geometry to disk across restart

This commit is contained in:
Kartik K. Agaram 2023-01-01 18:19:08 -08:00
parent b77b8a7b89
commit 998e40894f
1 changed files with 19 additions and 1 deletions

View File

@ -54,11 +54,29 @@ end
function love.quit()
if on.quit then on.quit() end
-- TODO: save settings
love.filesystem.write('config', json.encode(settings()))
end
function settings()
local x, y, displayindex = App.screen.position()
return {
x=x, y=y, displayindex=displayindex,
width=App.screen.width, height=App.screen.height,
}
end
function load_settings()
if love.filesystem.getInfo('config') then
local settings = json.decode(love.filesystem.read('config'))
local width, height, flags = love.window.getMode()
flags.resizable = true
flags.minwidth = math.min(width, 200)
flags.minheight = math.min(height, 200)
App.screen.flags = flags
App.screen.width = settings.width
App.screen.height = settings.height
love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)
love.window.setPosition(settings.x, settings.y, settings.displayindex)
else
local font_height = 20
love.graphics.setFont(love.graphics.newFont(font_height))