persist window geometry to disk across restart
This commit is contained in:
parent
b77b8a7b89
commit
998e40894f
20
main.lua
20
main.lua
|
@ -54,11 +54,29 @@ end
|
||||||
|
|
||||||
function love.quit()
|
function love.quit()
|
||||||
if on.quit then on.quit() end
|
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
|
end
|
||||||
|
|
||||||
function load_settings()
|
function load_settings()
|
||||||
if love.filesystem.getInfo('config') then
|
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
|
else
|
||||||
local font_height = 20
|
local font_height = 20
|
||||||
love.graphics.setFont(love.graphics.newFont(font_height))
|
love.graphics.setFont(love.graphics.newFont(font_height))
|
||||||
|
|
Loading…
Reference in New Issue