mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-18 11:44:42 +02:00
updated skin studio
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
-- Driver: the studio's side of the alt-tab crash. Leaving the window mid-drag
|
||||
-- must drop the drag and the queued click and still draw; main.lua's routing of
|
||||
-- love.focus / love.visible / pad events while the studio owns the window is
|
||||
-- pinned by tests/engine/skin_studio_image_import.lua (a driver run boots a
|
||||
-- game, so main.lua's Studio branch is not live here).
|
||||
-- POKEPORT_DRIVER=tests/drivers/skin_studio_focus_test.lua love .
|
||||
return function(game)
|
||||
local U = dofile("tests/drivers/util.lua")
|
||||
local Studio = require("src.ui.SkinStudio")
|
||||
local TouchControls = require("src.core.TouchControls")
|
||||
|
||||
love.window.setMode(1280, 720, { resizable = true, highdpi = true })
|
||||
U.wait(2)
|
||||
|
||||
Studio.load({ version = "red", skinId = "gb_anim", onClose = function() end })
|
||||
U.wait(2)
|
||||
U.log("skin:", Studio.skin and Studio.skin.id)
|
||||
|
||||
Studio.drag = { kind = "control-move", mx = 1, my = 1, bx = 0, by = 0,
|
||||
bw = 10, bh = 10 }
|
||||
Studio.clicked = true
|
||||
local okFocus, errFocus = pcall(Studio.focus, false)
|
||||
U.log("focus lost:", okFocus, errFocus or "")
|
||||
U.log("drag:", tostring(Studio.drag), "click:", tostring(Studio.clicked))
|
||||
local droppedDrag = Studio.drag == nil and Studio.clicked == false
|
||||
|
||||
-- a held test press must not survive the trip out of the window either
|
||||
Studio.testing = true
|
||||
TouchControls:setPreview(false)
|
||||
TouchControls.held = TouchControls.held or {}
|
||||
TouchControls.held.start = true
|
||||
pcall(Studio.focus, false)
|
||||
local held = next(TouchControls.held or {})
|
||||
U.log("held after focus loss:", tostring(held))
|
||||
|
||||
local okVisible = pcall(Studio.visible, false)
|
||||
U.log("minimize:", okVisible)
|
||||
|
||||
local okDraw, errDraw = pcall(Studio.draw)
|
||||
U.log("draw after alt-tab:", okDraw, errDraw or "")
|
||||
|
||||
Studio.unload()
|
||||
|
||||
if droppedDrag and held == nil and okVisible and okDraw then
|
||||
U.log("RESULT pass")
|
||||
else
|
||||
U.log("RESULT FAIL")
|
||||
end
|
||||
love.event.quit()
|
||||
while true do coroutine.yield() end
|
||||
end
|
||||
@@ -0,0 +1,120 @@
|
||||
-- Driver: imports a bezel image into a fresh skin through the studio's Import
|
||||
-- button and shoots the result, with the native dialog stubbed out (the real
|
||||
-- one blocks on osascript / zenity / PowerShell). Also covers button art and
|
||||
-- the drag-and-drop path.
|
||||
-- SHOT_DIR=/tmp/studioimport POKEPORT_DRIVER=tests/drivers/skin_studio_import_shot.lua love .
|
||||
return function(game)
|
||||
local U = dofile("tests/drivers/util.lua")
|
||||
local Studio = require("src.ui.SkinStudio")
|
||||
local FilePicker = require("src.core.FilePicker")
|
||||
local TouchSkin = require("src.core.TouchSkin")
|
||||
|
||||
local dir = os.getenv("SHOT_DIR") or "/tmp/studioimport"
|
||||
os.execute('mkdir -p "' .. dir .. '" 2>/dev/null')
|
||||
love.window.setMode(1440, 900, { resizable = true, highdpi = true })
|
||||
U.wait(2)
|
||||
|
||||
local pending = nil
|
||||
love.draw = function()
|
||||
Studio.draw()
|
||||
if pending then
|
||||
local path = pending
|
||||
pending = nil
|
||||
love.graphics.captureScreenshot(function(imagedata)
|
||||
local f = io.open(path, "wb")
|
||||
if f then f:write(imagedata:encode("png"):getString()) f:close() end
|
||||
end)
|
||||
end
|
||||
end
|
||||
local function shot(name)
|
||||
pending = dir .. "/" .. name
|
||||
for _ = 1, 90 do
|
||||
if not pending then break end
|
||||
coroutine.yield()
|
||||
end
|
||||
U.wait(3)
|
||||
local f = io.open(dir .. "/" .. name, "rb")
|
||||
U.log(f and "shot" or "FAIL shot", name)
|
||||
if f then f:close() end
|
||||
end
|
||||
|
||||
Studio.load({ version = "red", onClose = function() end })
|
||||
U.wait(3)
|
||||
-- start from New so the run does not depend on the saved skin choice
|
||||
Studio.skin = TouchSkin.newSkin("import_probe")
|
||||
Studio.skinIdField = "import_probe"
|
||||
Studio.pageIndex, Studio.selected, Studio.images = 1, nil, {}
|
||||
U.log("skin:", Studio.skin.id, "bezel:", tostring(Studio.page().imagePath))
|
||||
|
||||
-- what the native dialog would hand back
|
||||
local picked = "assets/skins/gb_anim/img/gb_back.png"
|
||||
local realOpen = FilePicker.open
|
||||
FilePicker.open = function(prompt, kind)
|
||||
U.log("picker prompt:", prompt, "exts:", table.concat(kind.exts, "/"))
|
||||
return picked
|
||||
end
|
||||
|
||||
Studio.importImageFile("bezel")
|
||||
U.log("status:", tostring(Studio.status))
|
||||
U.log("bezel now:", tostring(Studio.page().imagePath),
|
||||
"loaded:", tostring(Studio.page().image ~= nil))
|
||||
U.log("skin root:", Studio.skin.root)
|
||||
U.log("file on disk:",
|
||||
tostring(love.filesystem.getInfo(Studio.skin.root .. "/img/gb_back.png") ~= nil))
|
||||
local viewport = Studio.page().viewport
|
||||
U.log("viewport left alone:", viewport and
|
||||
("%.3f %.3f %.3f %.3f"):format(viewport.x, viewport.y, viewport.w, viewport.h)
|
||||
or "none")
|
||||
shot("import_bezel.png")
|
||||
|
||||
-- button art goes onto the selected control, not the page
|
||||
Studio.addControl()
|
||||
FilePicker.open = function() return "assets/skins/gb_anim/img/gbc_a.png" end
|
||||
Studio.importImageFile("idle")
|
||||
local ctl = Studio.selectedControl()
|
||||
U.log("idle art:", tostring(ctl.imagePath),
|
||||
"bezel untouched:", tostring(Studio.page().imagePath))
|
||||
FilePicker.open = function() return "assets/skins/gb_anim/img/gbc_b.png" end
|
||||
Studio.importImageFile("pressed")
|
||||
U.log("pressed art:", tostring(ctl.pressedImagePath))
|
||||
shot("import_button_art.png")
|
||||
|
||||
-- cancelling the dialog changes nothing
|
||||
local before = Studio.page().imagePath
|
||||
FilePicker.open = function() return nil end
|
||||
Studio.importImageFile("bezel")
|
||||
U.log("after cancel:", tostring(Studio.page().imagePath),
|
||||
"unchanged:", tostring(before == Studio.page().imagePath))
|
||||
|
||||
-- the drop path shares the import, and refuses non-art
|
||||
Studio.imageTarget = "bezel"
|
||||
local raw = love.filesystem.read("assets/skins/tv_crt/img/tv-integer.png")
|
||||
Studio.filedropped({
|
||||
getFilename = function() return "/tmp/tv_frame.png" end,
|
||||
open = function() return true end,
|
||||
read = function() return raw end,
|
||||
close = function() return true end,
|
||||
})
|
||||
U.log("dropped bezel:", tostring(Studio.page().imagePath))
|
||||
Studio.filedropped({
|
||||
getFilename = function() return "/tmp/notes.txt" end,
|
||||
open = function() return true end,
|
||||
read = function() return "nope" end,
|
||||
close = function() return true end,
|
||||
})
|
||||
U.log("after dropping a txt:", tostring(Studio.page().imagePath),
|
||||
"status:", tostring(Studio.status))
|
||||
shot("import_dropped.png")
|
||||
|
||||
love.window.setMode(760, 900, { resizable = true, highdpi = true })
|
||||
U.wait(3)
|
||||
shot("import_narrow.png")
|
||||
|
||||
FilePicker.open = realOpen
|
||||
local saved = TouchSkin.find("import_probe")
|
||||
U.log("skin discoverable:", tostring(saved ~= nil))
|
||||
Studio.unload()
|
||||
U.log("done")
|
||||
love.event.quit()
|
||||
while true do coroutine.yield() end
|
||||
end
|
||||
@@ -0,0 +1,137 @@
|
||||
-- Skin Studio art import: the native image picker behind the "Import" buttons
|
||||
-- (bezel / idle / pressed), and the alt-tab crash that took the studio down --
|
||||
-- love.focus fell through to Game:focus with no game booted.
|
||||
-- luajit tests/engine/skin_studio_image_import.lua
|
||||
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
if not _G.love then _G.love = require("tests.love_stub") end
|
||||
|
||||
local T = require("tests.harness")
|
||||
local check, eq = T.check, T.eq
|
||||
|
||||
local FilePicker = require("src.core.FilePicker")
|
||||
local TouchSkin = require("src.core.TouchSkin")
|
||||
local Studio = require("src.ui.SkinStudio")
|
||||
|
||||
local function session()
|
||||
Studio.skin = TouchSkin.newSkin("t")
|
||||
Studio.skinIdField = "t"
|
||||
Studio.pageIndex = 1
|
||||
Studio.selected = nil
|
||||
Studio.canvasIndex = 1
|
||||
Studio.drag = nil
|
||||
Studio.dirty = false
|
||||
Studio.status = nil
|
||||
Studio.testing = false
|
||||
Studio.images = {}
|
||||
Studio.imageTarget = "idle"
|
||||
return Studio.skin
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------ file picker
|
||||
|
||||
check(FilePicker.matches("bezel.png", FilePicker.IMAGE), "png is art")
|
||||
check(FilePicker.matches("BEZEL.PNG", FilePicker.IMAGE), "case does not matter")
|
||||
check(FilePicker.matches("shot.jpg", FilePicker.IMAGE), "jpg is art")
|
||||
check(FilePicker.matches("shot.jpeg", FilePicker.IMAGE), "jpeg is art")
|
||||
check(not FilePicker.matches("skin.zip", FilePicker.IMAGE), "a zip is not art")
|
||||
eq(FilePicker.basename("/home/me/art/bezel.png"), "bezel.png", "posix basename")
|
||||
eq(FilePicker.basename("C:\\Users\\me\\bezel.png"), "bezel.png", "windows basename")
|
||||
eq(FilePicker.basename("bezel.png"), "bezel.png", "a bare name is its own basename")
|
||||
|
||||
-- ----------------------------------------------------------- import target
|
||||
|
||||
session()
|
||||
Studio.addControl()
|
||||
local ctl = Studio.selectedControl()
|
||||
check(Studio.adoptImage("bezel.png", "PNGDATA", "bezel"), "bezel import succeeds")
|
||||
eq(Studio.page().imagePath, "img/bezel.png", "bezel art lands on the page")
|
||||
eq(ctl.imagePath, nil, "and not on the selected control")
|
||||
check(Studio.dirty, "importing marks the skin dirty")
|
||||
check(Studio.status:find("bezel", 1, true) ~= nil, "the status names the target")
|
||||
|
||||
check(Studio.adoptImage("a_button.png", "PNGDATA", "idle"), "idle import succeeds")
|
||||
eq(ctl.imagePath, "img/a_button.png", "idle art lands on the control")
|
||||
eq(Studio.page().imagePath, "img/bezel.png", "and leaves the bezel alone")
|
||||
|
||||
check(Studio.adoptImage("a_down.png", "PNGDATA", "pressed"), "pressed import succeeds")
|
||||
eq(ctl.pressedImagePath, "img/a_down.png", "pressed art lands on the control")
|
||||
eq(ctl.imagePath, "img/a_button.png", "idle art survives")
|
||||
|
||||
check(not Studio.adoptImage("notes.txt", "junk", "bezel"), "non-art is refused")
|
||||
eq(Studio.page().imagePath, "img/bezel.png", "and changes nothing")
|
||||
|
||||
-- the imported files are listed for the cycle buttons
|
||||
local listed = {}
|
||||
for _, rel in ipairs(Studio.images or {}) do listed[rel] = true end
|
||||
check(listed["img/bezel.png"], "the imported bezel joins the image list")
|
||||
|
||||
-- -------------------------------------------------------- picker plumbing
|
||||
|
||||
local realOpen, realRead = FilePicker.open, FilePicker.read
|
||||
local asked
|
||||
FilePicker.open = function(prompt, kind)
|
||||
asked = { prompt = prompt, kind = kind }
|
||||
return "/tmp/some folder/frame.png"
|
||||
end
|
||||
FilePicker.read = function() return "PNGDATA" end
|
||||
|
||||
session()
|
||||
Studio.importImageFile("bezel")
|
||||
check(asked ~= nil, "the bezel button opens a picker")
|
||||
eq(asked.kind, FilePicker.IMAGE, "and asks for images, not archives")
|
||||
check(asked.prompt:lower():find("bezel", 1, true) ~= nil, "with a bezel prompt")
|
||||
eq(Studio.page().imagePath, "img/frame.png", "the pick becomes the bezel")
|
||||
eq(Studio.imageTarget, "bezel", "and the target sticks for the cycle button")
|
||||
|
||||
-- no control selected: an art import says so instead of writing to the page
|
||||
session()
|
||||
asked = nil
|
||||
Studio.importImageFile("idle")
|
||||
check(asked == nil, "no picker opens without a control to paint")
|
||||
eq(Studio.page().imagePath, nil, "and the bezel is not overwritten")
|
||||
check(Studio.status ~= nil, "the studio explains why")
|
||||
|
||||
-- a cancelled dialog leaves the skin exactly as it was
|
||||
session()
|
||||
FilePicker.open = function() return nil end
|
||||
Studio.importImageFile("bezel")
|
||||
eq(Studio.page().imagePath, nil, "cancelling imports nothing")
|
||||
check(not Studio.dirty, "and does not dirty the skin")
|
||||
|
||||
FilePicker.open, FilePicker.read = realOpen, realRead
|
||||
|
||||
-- --------------------------------------------------------- focus / alt-tab
|
||||
|
||||
session()
|
||||
Studio.drag = { kind = "control-move", mx = 1, my = 1, bx = 0, by = 0, bw = 1, bh = 1 }
|
||||
Studio.clicked = true
|
||||
Studio.focus(false)
|
||||
eq(Studio.drag, nil, "losing focus drops the in-flight drag")
|
||||
eq(Studio.clicked, false, "and the queued click")
|
||||
check(pcall(Studio.visible, false), "minimizing is survivable too")
|
||||
|
||||
-- main.lua used to hand focus / visibility / pad events straight to Game while
|
||||
-- the studio owned the window, and the launcher has no Game -- alt-tab took the
|
||||
-- app down with "attempt to index a nil value (global 'Game')".
|
||||
local f = assert(io.open("main.lua", "r"))
|
||||
local src = f:read("*a")
|
||||
f:close()
|
||||
|
||||
local checked = 0
|
||||
for name, body in ("\n" .. src):gmatch("\nfunction love%.([%w_]+)%b()\n(.-)\nend\n") do
|
||||
if body:find("Game:") then
|
||||
checked = checked + 1
|
||||
check(body:find("Studio") ~= nil,
|
||||
"love." .. name .. " checks Studio before dispatching to Game")
|
||||
check(body:find("not Game then") ~= nil
|
||||
or body:find("if Game then") ~= nil
|
||||
or body:find("Game and ") ~= nil,
|
||||
"love." .. name .. " tolerates a nil Game (launcher / studio session)")
|
||||
end
|
||||
end
|
||||
check(checked >= 10, "the handler scan actually found handlers (" .. checked .. ")")
|
||||
check(src:find("Studio.focus", 1, true) ~= nil, "love.focus routes to the studio")
|
||||
check(src:find("Studio.visible", 1, true) ~= nil, "so does love.visible")
|
||||
|
||||
T.finish("skin_studio_image_import")
|
||||
Reference in New Issue
Block a user