diff --git a/main.lua b/main.lua index d9d17d9..db959cf 100644 --- a/main.lua +++ b/main.lua @@ -1,3 +1,11 @@ +if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE")=="1" then + lldebugger=require('lldebugger') + lldebugger.start() + REQUEST_BREAK=lldebugger.requestBreak +else + REQUEST_BREAK=function()end +end + require 'funcs' DEBUG_showKey=true @@ -25,8 +33,8 @@ function love.load() love.mouse.setVisible(false) love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true}); - -- used for screenshots - GLOBAL_CANVAS = love.graphics.newCanvas() + GLOBAL_TRANSFORM = love.math.newTransform() + love.resize(love.graphics.getWidth(), love.graphics.getHeight()) -- init config initConfig() @@ -35,20 +43,22 @@ function love.load() end +function love.resize(w, h) + local scale_factor = math.min(w / 640, h / 480) + GLOBAL_TRANSFORM:setTransformation( + (w - scale_factor * 640) / 2, -- x + (h - scale_factor * 480) / 2, -- y + 0, -- orientation + scale_factor + ) +end + function love.draw() - love.graphics.setCanvas(GLOBAL_CANVAS) + love.graphics.replaceTransform(GLOBAL_TRANSFORM) love.graphics.clear() love.graphics.push() -- get offset matrix - local width = love.graphics.getWidth() - local height = love.graphics.getHeight() - local scale_factor = math.min(width / 640, height / 480) - love.graphics.translate( - (width - scale_factor * 640) / 2, - (height - scale_factor * 480) / 2 - ) - love.graphics.scale(scale_factor) scene:render() love.graphics.pop() @@ -56,10 +66,6 @@ function love.draw() if DEBUG_showKey then drawText("Pressed: "..(LastPressedKey or '[NONE]').." | Released: "..(LastReleasedKey or '[NONE]'),0,0,1000,"left") end - - love.graphics.setCanvas() - love.graphics.setColor(1,1,1,1) - love.graphics.draw(GLOBAL_CANVAS) end function love.keypressed(key, scancode) @@ -76,7 +82,7 @@ function love.keypressed(key, scancode) elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f[1-9][0-9]+$") then return -- escape is reserved for menu_back - elseif scancode == "escape" then + elseif scancode == "escape" or scancode == "acback" then scene:onInputPress({input="menu_back", type="key", key=key, scancode=scancode}) -- pass any other key to the scene, with its configured mapping else @@ -93,7 +99,7 @@ function love.keyreleased(key, scancode) local input_released = nil -- escape is reserved for menu_back - if scancode == "escape" or scancode=='acback' then + if scancode == "escape" or scancode == 'acback' then scene:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode}) -- function keys are reserved elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f[1-9][0-9]+$") then @@ -238,11 +244,6 @@ function love.focus(f) return end -function love.resize(w, h) - GLOBAL_CANVAS:release() - GLOBAL_CANVAS = love.graphics.newCanvas(w, h) -end - local TARGET_FPS = 60 function love.run()