dosember-jam-2025/game/platform/native.lua

50 lines
1.4 KiB
Lua

local platform = { mouse = {} }
local screenWidth = 320
local screenHeight = 200
local screenScale = 2
local canvas
function platform.init()
love.graphics.setDefaultFilter("nearest")
love.graphics.setCanvas() -- Reset the canvas to avoid any bugs
love.window.setMode(screenWidth * screenScale, screenHeight * screenScale, { resizable = false, vsync = true })
canvas = love.graphics.newCanvas(screenWidth, screenHeight)
end
function platform.drawStart()
love.graphics.setCanvas(canvas)
end
function platform.drawEnd()
love.graphics.setCanvas()
love.graphics.draw(canvas, 0, 0, 0, screenScale, screenScale)
end
local mouseGetX = function()
return platform.mouse._ogMouseGetX() / screenScale
end
if mouseGetX ~= love.mouse.getX then
platform.mouse._ogMouseGetX = love.mouse.getX
love.mouse.getX = mouseGetX
end
local mouseGetY = function()
return platform.mouse._ogMouseGetY() / screenScale
end
if mouseGetY ~= love.mouse.getY then
platform.mouse._ogMouseGetY = love.mouse.getY
love.mouse.getY = mouseGetY
end
local mouseGetPosition = function()
local x, y = platform.mouse._ogMouseGetPosition()
return x / screenScale, y / screenScale
end
if mouseGetPosition ~= love.mouse.getPosition then
platform.mouse._ogMouseGetPosition = love.mouse.getPosition
love.mouse.getPosition = mouseGetPosition
end
return platform