mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-23 05:58:26 +02:00
skin studio updates, save sync CLOSES #1533
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
local GameViewport = require("src.render.GameViewport")
|
||||
local TouchSkin = require("src.core.TouchSkin")
|
||||
|
||||
local Playfield = {}
|
||||
|
||||
Playfield.WIDTH, Playfield.HEIGHT = 160, 144
|
||||
|
||||
Playfield.entered = false
|
||||
Playfield.box = nil
|
||||
|
||||
local function clampRect(x, y, w, h, sw, sh)
|
||||
if type(w) ~= "number" or type(h) ~= "number" then return nil end
|
||||
if w ~= w or h ~= h then return nil end
|
||||
x = math.floor(tonumber(x) or 0)
|
||||
y = math.floor(tonumber(y) or 0)
|
||||
w, h = math.floor(w), math.floor(h)
|
||||
if x < 0 then w, x = w + x, 0 end
|
||||
if y < 0 then h, y = h + y, 0 end
|
||||
if x + w > sw then w = sw - x end
|
||||
if y + h > sh then h = sh - y end
|
||||
if w < 1 or h < 1 then return nil end
|
||||
return x, y, w, h
|
||||
end
|
||||
|
||||
function Playfield.cutout(sw, sh)
|
||||
if Playfield.entered then return nil end
|
||||
if type(sw) ~= "number" or type(sh) ~= "number" then return nil end
|
||||
if sw < 1 or sh < 1 then return nil end
|
||||
if type(TouchSkin.viewport) ~= "function" then return nil end
|
||||
local ok, x, y, w, h, fill, expand = pcall(TouchSkin.viewport, sw, sh)
|
||||
if not ok then return nil end
|
||||
local cx, cy, cw, ch = clampRect(x, y, w, h, sw, sh)
|
||||
if not cx then return nil end
|
||||
return cx, cy, cw, ch, fill == true, expand == true
|
||||
end
|
||||
|
||||
function Playfield.rect(sw, sh)
|
||||
local x, y, w, h, _, expand = Playfield.cutout(sw, sh)
|
||||
if not x then return 0, 0, sw or 0, sh or 0, false end
|
||||
if expand then return x, y, w, h, true end
|
||||
local s = math.max(1, math.floor(math.min(w / Playfield.WIDTH,
|
||||
h / Playfield.HEIGHT)))
|
||||
local pw = math.min(w, Playfield.WIDTH * s)
|
||||
local ph = math.min(h, Playfield.HEIGHT * s)
|
||||
return x + math.floor((w - pw) / 2), y + math.floor((h - ph) / 2), pw, ph, true
|
||||
end
|
||||
|
||||
function Playfield.enter(x, y, w, h)
|
||||
Playfield.entered = true
|
||||
Playfield.box = { x = x, y = y, w = w, h = h }
|
||||
end
|
||||
|
||||
function Playfield.leave()
|
||||
Playfield.entered = false
|
||||
Playfield.box = nil
|
||||
end
|
||||
|
||||
function Playfield.dimensions()
|
||||
if Playfield.entered and Playfield.box then
|
||||
return Playfield.box.w, Playfield.box.h
|
||||
end
|
||||
return GameViewport.dimensions()
|
||||
end
|
||||
|
||||
function Playfield.push(sw, sh)
|
||||
local x, y, w, h, active = Playfield.rect(sw, sh)
|
||||
local G = love.graphics
|
||||
G.push("all")
|
||||
if active then G.setScissor(x, y, w, h) end
|
||||
G.translate(x, y)
|
||||
Playfield.enter(x, y, w, h)
|
||||
return w, h, x, y, active
|
||||
end
|
||||
|
||||
function Playfield.pop()
|
||||
Playfield.leave()
|
||||
love.graphics.setScissor()
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
return Playfield
|
||||
Reference in New Issue
Block a user