From 998e40894f167c340b74e686225bcb3f659e7add Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 1 Jan 2023 18:19:08 -0800 Subject: [PATCH] persist window geometry to disk across restart --- main.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 8403ed0..e4f266a 100644 --- a/main.lua +++ b/main.lua @@ -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))