skins and skin studio

This commit is contained in:
bryanthaboi
2026-08-17 06:47:33 -04:00
parent a5b674f9da
commit 3cca70608f
45 changed files with 4194 additions and 64 deletions
+100
View File
@@ -0,0 +1,100 @@
-- Driver: renders the launcher's SKINS tab, exercises Use / import, and
-- shoots it. Stands in for main.lua's Importer branch so the panel can be
-- eyeballed without clicking through the real launcher.
-- SHOT_DIR=/tmp/skinstab POKEPORT_DRIVER=tests/drivers/launcher_skins_tab_shot.lua love .
return function(game)
local U = dofile("tests/drivers/util.lua")
local RomImporter = require("src.import.RomImporter")
local TouchSkin = require("src.core.TouchSkin")
local dir = os.getenv("SHOT_DIR") or "/tmp/skinstab"
os.execute('mkdir -p "' .. dir .. '" 2>/dev/null')
love.window.setMode(1024, 768, { resizable = true, highdpi = true })
U.wait(2)
local studioOpenedWith = nil
local imp = RomImporter.new(function() end, {
launcher = true,
onOpenSkinStudio = function(v) studioOpenedWith = v end,
})
local pending = nil
love.draw = function()
imp: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
imp:update(1 / 60)
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
imp:_switchTab("skins")
U.wait(3)
U.log("tab:", imp.tab)
local skins = imp:_ensureSkins()
U.log("skins listed:", #skins)
for _, e in ipairs(skins) do
U.log((" %s source=%s pages=%d buttons=%d screen=%s ok=%s"):format(
e.id, e.source, e.pages, e.controls, tostring(e.screen), tostring(e.ok)))
end
U.log("active skin:", tostring(imp:_activeSkin()))
shot("skins_tab.png")
imp._gamePopup = true
U.wait(2)
shot("game_dropdown.png")
imp._gamePopup = nil
U.wait(2)
-- pick one, the way clicking its row does
imp:_useSkin("tv_crt")
U.wait(2)
U.log("after use:", tostring(imp:_activeSkin()), "notice:", imp._skinNotice.text)
shot("skins_tab_selected.png")
-- studio hook carries a real cartridge, not the "skins" tab id
imp.modScope = "red"
if imp.onOpenSkinStudio then imp.onOpenSkinStudio(imp.modScope or "red") end
U.log("studio opened with version:", tostring(studioOpenedWith))
-- import: a dropped zip on this tab is a skin, not a mod
local exported = TouchSkin.export(
assert(TouchSkin.load("assets/skins/gb_anim", "gb_anim")),
"skins/dropped_probe.zip")
U.log("staged archive:", tostring(exported))
local raw = love.filesystem.read("skins/dropped_probe.zip")
love.filesystem.remove("skins/dropped_probe.zip")
-- same shape LOVE's DroppedFile presents to readDroppedFile
local dropped = {
getFilename = function() return "/tmp/my_cool_skin.zip" end,
getSize = function() return #raw end,
open = function() return true end,
read = function() return raw end,
close = function() return true end,
}
imp:filedropped(dropped)
U.log("import notice:", imp._skinNotice.text)
U.log("skins after import:", #imp:_ensureSkins())
U.log("my_cool_skin found:", tostring(TouchSkin.find("my_cool_skin") ~= nil))
imp:_useSkin(nil)
shot("skins_tab_imported.png")
U.log("done")
love.event.quit()
while true do coroutine.yield() end
end
+116
View File
@@ -0,0 +1,116 @@
-- Driver: authors a CRT bezel skin from nothing using only Skin Studio
-- actions -- New, drop the art on the window, Detect screen, Save -- then
-- loads the saved folder back and renders the game through it. Answers
-- "could the studio have made tv_crt?" by doing it.
-- SHOT_DIR=/tmp/author POKEPORT_DRIVER=tests/drivers/skin_studio_author_tv.lua love .
return function(game)
local U = dofile("tests/drivers/util.lua")
local Studio = require("src.ui.SkinStudio")
local TouchSkin = require("src.core.TouchSkin")
local dir = os.getenv("SHOT_DIR") or "/tmp/author"
os.execute('mkdir -p "' .. dir .. '" 2>/dev/null')
love.window.setMode(1280, 720, { resizable = true, highdpi = true })
U.wait(2)
local baseDraw = love.draw
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)
end
-- a stand-in for LOVE's DroppedFile, same three calls Studio.filedropped uses
local function droppedFile(realPath)
local handle
return {
getFilename = function() return realPath end,
open = function() handle = assert(io.open(realPath, "rb")) end,
read = function() return handle:read("*a") end,
close = function() if handle then handle:close() handle = nil end end,
}
end
Studio.load({ onClose = function() end })
U.wait(3)
-- 1. New skin, named
Studio.skin = TouchSkin.newSkin("my_tv")
Studio.skinIdField = "my_tv"
Studio.pageIndex, Studio.selected = 1, nil
Studio.images = {}
TouchSkin.setActive(Studio.skin)
U.log("1. new skin:", Studio.skin.id, "controls:", #Studio.page().controls)
-- 2. Desktop canvas preset
for i, c in ipairs(Studio.CANVASES) do
if c.id == "desktop_1080" then Studio.setCanvas(i) end
end
U.log("2. canvas:", Studio.canvas().label, Studio.canvas().w .. "x" .. Studio.canvas().h)
-- 3. Drop the bezel art on the window
Studio.filedropped(droppedFile("assets/skins/tv_crt/img/tv-integer.png"))
U.log("3. drop:", Studio.status)
U.log(" bezel:", tostring(Studio.page().imagePath), "root:", Studio.skin.root)
-- 4. Detect the screen hole from the art's alpha
Studio.detectViewport()
local v = Studio.page().viewport
U.log("4. detect:", Studio.status)
U.log((" viewport %.4f %.4f %.4f %.4f"):format(v.x, v.y, v.w, v.h))
shot("author_studio.png")
-- 5. Save
Studio.save()
U.log("5. save:", Studio.status)
-- what landed on disk
local root = "skins/my_tv"
for _, name in ipairs(love.filesystem.getDirectoryItems(root)) do
local info = love.filesystem.getInfo(root .. "/" .. name)
U.log(" file:", name, info and info.type)
end
local src = love.filesystem.read(root .. "/skin.lua")
U.log(" skin.lua bytes:", src and #src)
U.log(" skin.lua:", (src or ""):gsub("%s+", " "):sub(1, 260))
-- 6. Load the saved folder back as a normal skin and play through it
Studio.unload()
local reloaded, err = TouchSkin.load(root, "my_tv")
U.log("6. reload:", reloaded and "ok" or tostring(err),
"format:", reloaded and reloaded.format,
"controls:", reloaded and #reloaded.pages[1].controls)
game.save.options.touchControls = { enabled = true, skin = "my_tv" }
game.save.options.tilt = 0
game.save.options.zoom = 0
game.save.options.pipelines = {}
game:applyOptions()
local TouchControls = require("src.core.TouchControls")
U.log(" active:", tostring(TouchControls.skinId), "err:", tostring(TouchControls.skinError))
U.log(" decorativeOnly:", TouchSkin.decorativeOnly(), "drawable:", TouchSkin.drawable())
love.draw = baseDraw
U.teleport(game, "PALLET_TOWN", 10, 8, "down")
U.wait(12)
U.shot(game, dir .. "/author_result.png")
U.log("done")
love.event.quit()
while true do coroutine.yield() end
end
+57
View File
@@ -0,0 +1,57 @@
-- Driver: presses Play in the Skin Studio the way the button does, then keeps
-- drawing and pumping update so the deferred handoff runs. Regression cover
-- for the crash where Play unloaded the studio inside its own draw pass.
-- POKEPORT_DRIVER=tests/drivers/skin_studio_play_test.lua love .
return function(game)
local U = dofile("tests/drivers/util.lua")
local Studio = require("src.ui.SkinStudio")
love.window.setMode(1280, 720, { resizable = true, highdpi = true })
U.wait(2)
local booted, bootVersion = false, nil
Studio.load({
version = "red",
onClose = function() end,
onPlay = function(v)
-- what main.lua's handler does: unload, then boot
Studio.unload()
booted, bootVersion = true, v
end,
})
U.wait(3)
U.log("loaded skin:", Studio.skin and Studio.skin.id)
Studio.skinIdField = "play_probe"
-- press Play exactly as the inspector button does
Studio.play()
U.log("after play(): pendingPlay =", tostring(Studio.pendingPlay),
"skin alive =", tostring(Studio.skin ~= nil), "booted =", tostring(booted))
U.log("status:", tostring(Studio.status))
-- the frame that queued the handoff must still draw
local okDraw, errDraw = pcall(Studio.draw)
U.log("draw on the click frame:", okDraw, errDraw or "")
-- now the deferred handoff
local okUp, errUp = pcall(Studio.update, 1 / 60)
U.log("update handoff:", okUp, errUp or "")
U.log("booted =", tostring(booted), "version =", tostring(bootVersion),
"skin =", tostring(Studio.skin))
-- and a draw after teardown, which is what actually crashed before
local okAfter, errAfter = pcall(Studio.draw)
U.log("draw after teardown:", okAfter, errAfter or "")
local okUp2 = pcall(Studio.update, 1 / 60)
U.log("second update:", okUp2, "booted still once =", tostring(booted))
if okDraw and okUp and okAfter and booted then
U.log("RESULT pass")
else
U.log("RESULT FAIL")
end
love.event.quit()
while true do coroutine.yield() end
end
+107
View File
@@ -0,0 +1,107 @@
-- Driver: shoots the desktop Skin Studio (#1386) across its canvas presets
-- and in Test mode. The studio is a top-level love.draw branch in main.lua,
-- so this stands in for that branch and captures the frames itself.
-- SHOT_DIR=/tmp/studio POKEPORT_DRIVER=tests/drivers/skin_studio_shot.lua love .
return function(game)
local U = dofile("tests/drivers/util.lua")
local Studio = require("src.ui.SkinStudio")
local TouchControls = require("src.core.TouchControls")
local dir = os.getenv("SHOT_DIR") or "/tmp/studio"
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")
if f then f:close() U.log("shot", name) else U.log("FAIL shot", name) end
end
Studio.load({ skinId = "gb_anim", onClose = function() end })
U.wait(5)
U.log("skin:", Studio.skin and Studio.skin.id, "pages:", #(Studio.skin.pages or {}))
U.log("controls:", #Studio.page().controls, "images:", #(Studio.images or {}))
shot("studio_open.png")
Studio.selected = 9
U.wait(3)
local ctl = Studio.selectedControl()
U.log("selected:", ctl and ctl.spec, "x", ctl and ctl.x, "y", ctl and ctl.y)
shot("studio_selected.png")
-- drag the selected control and confirm the model moved
local r = Studio.lastCanvas
if r and ctl then
local before = ctl.x
Studio.beginCanvasDrag(r.x + ctl.x * r.w, r.y + ctl.y * r.h, r)
Studio.updateDrag(r.x + ctl.x * r.w - 60, r.y + ctl.y * r.h, r)
Studio.drag = nil
U.log("drag moved x:", before, "->", ctl.x)
end
U.wait(3)
shot("studio_dragged.png")
-- numeric entry: type an exact pixel X
if ctl then
Studio.commitField("numX", "100")
U.log("after numX=100 px, x fraction:", ctl.x, "rangeX:", ctl.rangeX)
end
Studio.testing = true
TouchControls:setPreview(false)
U.wait(3)
if r then
local page = Studio.page()
local TouchSkin = require("src.core.TouchSkin")
TouchSkin.setSurface(r.x, r.y, r.w, r.h)
local cx, cy = TouchSkin.controlGeometry(page, page.controls[13], r.w, r.h, r.x, r.y)
Studio.mousepressed(cx, cy, 1)
TouchSkin.setSurface(nil)
local held = {}
for btn in pairs(TouchControls.held or {}) do held[#held + 1] = btn end
U.log("test press held:", table.concat(held, ","))
end
U.wait(3)
shot("studio_test.png")
Studio.mousereleased(0, 0, 1)
Studio.testing = false
TouchControls:setPreview(true)
-- Super Game Boy border preset: viewport locks to the 160x144 window
for i, c in ipairs(Studio.CANVASES) do
if c.id == "sgb_border" then Studio.setCanvas(i) end
end
U.wait(3)
local vp = Studio.page().viewport
U.log("sgb viewport:", vp.x, vp.y, vp.w, vp.h)
shot("studio_sgb.png")
for i, c in ipairs(Studio.CANVASES) do
if c.id == "ultrawide" then Studio.setCanvas(i) end
end
U.wait(3)
shot("studio_ultrawide.png")
U.log("done")
love.event.quit()
while true do coroutine.yield() end
end
+59
View File
@@ -0,0 +1,59 @@
-- Driver: shoots the launcher's Touch Controls editor with the built-in pad
-- and with the bundled skin picked, so the Skin row (#1386) can be eyeballed.
-- The editor is a top-level love.draw branch in main.lua, not a stack state,
-- so this stands in for that branch and captures the frame itself.
-- SHOT_DIR=/tmp/skin POKEPORT_DRIVER=tests/drivers/touch_skin_editor_shot.lua love .
return function(game)
local U = dofile("tests/drivers/util.lua")
local Editor = require("src.ui.TouchControlsEditor")
local TouchControls = require("src.core.TouchControls")
local dir = os.getenv("SHOT_DIR") or "/tmp/skin"
os.execute('mkdir -p "' .. dir .. '" 2>/dev/null')
love.window.setMode(432, 768, { resizable = true, highdpi = true })
U.wait(2)
local pending = nil
love.draw = function()
Editor.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, 60 do
if not pending then break end
coroutine.yield()
end
U.wait(3)
local f = io.open(dir .. "/" .. name, "rb")
if f then f:close() U.log("shot", name) else U.log("FAIL shot", name) end
end
Editor.load({ onClose = function() end })
U.wait(5)
U.log("skins:", #Editor.skins, "label:", Editor.skinLabel())
shot("editor_pad.png")
Editor.cycleSkin(1)
U.wait(5)
U.log("picked:", tostring(TouchControls.skinId), Editor.skinLabel())
shot("editor_skin.png")
Editor.exportSkin()
U.wait(5)
U.log("export:", tostring(Editor.exportMsg))
U.log("skins after export:", #Editor.skins)
shot("editor_export.png")
U.log("done")
love.event.quit()
while true do coroutine.yield() end
end
+71
View File
@@ -0,0 +1,71 @@
-- Driver: shoots the bundled RetroArch-format touch skin (assets/skins/gb_anim)
-- over a live overworld in a portrait window, idle and with A/DOWN held.
-- SHOT_DIR=/tmp/skin POKEPORT_TOUCH=1 POKEPORT_DRIVER=tests/drivers/touch_skin_shot.lua love .
return function(game)
local U = dofile("tests/drivers/util.lua")
local TouchControls = require("src.core.TouchControls")
local TouchSkin = require("src.core.TouchSkin")
local Pokemon = require("src.pokemon.Pokemon")
local dir = os.getenv("SHOT_DIR") or "/tmp/skin"
local skinId = os.getenv("SKIN") or "gb_anim"
love.window.setMode(432, 768, { resizable = true, highdpi = true })
U.wait(2)
game.save.party = { Pokemon.new(game.data, "CHARIZARD", 50) }
game.save.player.name = "bryan"
if os.getenv("SKIN") == "none" then skinId = nil end
game.save.options.touchControls = { enabled = true, skin = skinId }
game.save.options.tilt = 0
game.save.options.zoom = 0
game.save.options.pipelines = {}
game:applyOptions()
U.log("skins on disk:")
for _, entry in ipairs(TouchSkin.list()) do
U.log(" ", entry.id, entry.source, entry.root)
end
U.log("active:", tostring(TouchControls.skinId), "err:", tostring(TouchControls.skinError))
local page = TouchSkin.page()
U.log("page:", page and page.name, "controls:", page and #page.controls)
U.teleport(game, "PALLET_TOWN", 10, 8, "down")
U.wait(10)
local R = game.renderer
local pw, ph = love.graphics.getPixelDimensions()
U.log("pixel dims:", pw, ph)
U.log("skin viewport:", TouchSkin.viewport(pw, ph))
U.log("hasViewport:", TouchSkin.hasViewport(), "fitScale:", R:fitScale())
U.log("worldViewSize:", R:worldViewSize())
U.log("worldOverride:", tostring(R.worldOverride), "worldActive:", tostring(R.worldActive))
U.shot(game, dir .. "/skin_idle.png")
local ww, wh = love.graphics.getDimensions()
local function at(nx, ny) return nx * ww, ny * wh end
TouchControls:touchpressed("t1", at(0.87407, 0.72417))
TouchControls:touchpressed("t2", at(0.24074, 0.79771))
U.wait(4)
U.log("held:", (function()
local out = {}
for btn in pairs(TouchControls.held or {}) do out[#out + 1] = btn end
table.sort(out)
return table.concat(out, ",")
end)())
U.shot(game, dir .. "/skin_pressed.png")
TouchControls:touchreleased("t1", at(0.87407, 0.72417))
TouchControls:touchreleased("t2", at(0.24074, 0.79771))
U.wait(4)
TouchControls:touchpressed("t3", at(0.95, 0.528))
TouchControls:touchreleased("t3", at(0.95, 0.528))
U.wait(6)
U.log("page after overlay_next:", TouchSkin.page() and TouchSkin.page().name)
U.shot(game, dir .. "/skin_page2.png")
U.log("done")
love.event.quit()
while true do coroutine.yield() end
end
+53
View File
@@ -0,0 +1,53 @@
-- Driver: shoots the bundled desktop CRT bezel (assets/skins/tv_crt) over a
-- live overworld in a 16:9 window, and checks the alpha-based screen detector
-- against the viewport the .cfg declares.
-- SHOT_DIR=/tmp/tv POKEPORT_DRIVER=tests/drivers/tv_skin_shot.lua love .
return function(game)
local U = dofile("tests/drivers/util.lua")
local TouchControls = require("src.core.TouchControls")
local TouchSkin = require("src.core.TouchSkin")
local Pokemon = require("src.pokemon.Pokemon")
local dir = os.getenv("SHOT_DIR") or "/tmp/tv"
local skinId = os.getenv("SKIN") or "tv_crt"
love.window.setMode(1280, 720, { resizable = true, highdpi = true })
U.wait(2)
game.save.party = { Pokemon.new(game.data, "CHARIZARD", 50) }
game.save.player.name = "bryan"
game.save.options.touchControls = { enabled = true, skin = skinId }
game.save.options.tilt = 0
game.save.options.zoom = 0
game.save.options.pipelines = {}
game:applyOptions()
U.log("active:", tostring(TouchControls.skinId), "err:", tostring(TouchControls.skinError))
local page = TouchSkin.page()
U.log("page:", page and page.name, "controls:", page and #page.controls)
local v = page and page.viewport
U.log("declared viewport:", v and v.x, v and v.y, v and v.w, v and v.h)
local detected = TouchSkin.detectViewport(TouchSkin.active.root, page.imagePath)
if detected then
U.log(("detected hole: %.4f %.4f %.4f %.4f"):format(
detected.x, detected.y, detected.w, detected.h))
U.log(("delta vs declared: %.4f %.4f %.4f %.4f"):format(
detected.x - v.x, detected.y - v.y, detected.w - v.w, detected.h - v.h))
else
U.log("FAIL no hole detected")
end
local pw, ph = love.graphics.getPixelDimensions()
U.log("pixel dims:", pw, ph)
U.log("engine viewport px:", TouchSkin.viewport(pw, ph))
U.log("fitScale:", game.renderer:fitScale())
U.teleport(game, "PALLET_TOWN", 10, 8, "down")
U.wait(12)
U.shot(game, dir .. "/tv_overworld.png")
U.log("done")
love.event.quit()
while true do coroutine.yield() end
end