mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-18 19:54:21 +02:00
@@ -0,0 +1,68 @@
|
||||
-- The museum 1F ticket clerk's take-your-time/not-enough-money/come-again
|
||||
-- lines used to be bare English literals, invisible to game.data.text no
|
||||
-- matter what a translation mod put there. tests/engine/museum_money_box_
|
||||
-- bug1335.lua only ever runs with an empty game.data.text, so it can't
|
||||
-- tell a properly-wired t._Key or "..." fallback apart from a literal that
|
||||
-- never looked at t at all -- every assertion there passes either way.
|
||||
-- This test populates game.data.text with translated values and checks
|
||||
-- they actually reach the pushed TextBox, for all three lines.
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
|
||||
local T = require("tests.harness")
|
||||
|
||||
package.loaded["src.render.TextBox"] = {
|
||||
new = function(_, text, onDone, opts)
|
||||
return { text = text, onDone = onDone, opts = opts }
|
||||
end,
|
||||
}
|
||||
|
||||
local M = assert(loadfile("data/scripts/story2.lua"))()
|
||||
local clerk = M.MUSEUM_1F.talk.TEXT_MUSEUM1F_SCIENTIST1
|
||||
|
||||
local TRANSLATED = {
|
||||
_Museum1FScientist1TakePlentyOfTimeText = "Prends ton temps\net profite bien !",
|
||||
_Museum1FScientist1DontHaveEnoughMoneyText = "Tu n'as pas assez\nd'argent.",
|
||||
_Museum1FScientist1ComeAgainText = "Reviens vite !",
|
||||
}
|
||||
|
||||
local pushed
|
||||
local function mkGame(cash)
|
||||
pushed = {}
|
||||
return {
|
||||
data = { text = TRANSLATED },
|
||||
save = { money = cash, flags = {} },
|
||||
stack = { push = function(_, box) pushed[#pushed + 1] = box end },
|
||||
}
|
||||
end
|
||||
|
||||
-- already ticketed: take-your-time line
|
||||
local g = mkGame(3000)
|
||||
g.save.flags.EVENT_BOUGHT_MUSEUM_TICKET = true
|
||||
clerk(g, nil, nil, function() end)
|
||||
T.eq(pushed[1].text, TRANSLATED._Museum1FScientist1TakePlentyOfTimeText,
|
||||
"an existing ticket holder gets the translated take-your-time line")
|
||||
|
||||
-- YES but short on cash: not-enough-money line
|
||||
g = mkGame(20)
|
||||
clerk(g, nil, nil, function() end)
|
||||
pushed[1].opts.choice(true)
|
||||
T.eq(pushed[2].text, TRANSLATED._Museum1FScientist1DontHaveEnoughMoneyText,
|
||||
"short on cash opens the translated not-enough-money box")
|
||||
|
||||
-- NO: come-again line
|
||||
g = mkGame(3000)
|
||||
clerk(g, nil, nil, function() end)
|
||||
pushed[1].opts.choice(false)
|
||||
T.eq(pushed[2].text, TRANSLATED._Museum1FScientist1ComeAgainText,
|
||||
"declining opens the translated come-again box")
|
||||
|
||||
-- unpopulated game.data.text still falls back to the English literal
|
||||
g = { data = { text = {} }, save = { money = 3000, flags = {} },
|
||||
stack = { push = function(_, box) pushed[#pushed + 1] = box end } }
|
||||
pushed = {}
|
||||
g.save.flags.EVENT_BOUGHT_MUSEUM_TICKET = true
|
||||
clerk(g, nil, nil, function() end)
|
||||
T.check(tostring(pushed[1].text):find("Take your time", 1, true) ~= nil,
|
||||
"an empty catalog still falls back to the English take-your-time line")
|
||||
|
||||
T.finish("museum_1f_clerk_translation_test")
|
||||
@@ -0,0 +1,118 @@
|
||||
-- Skins tab Import button: picker plumbing + path/drop install (SKINIMP-01..05).
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
if not _G.love then _G.love = require("tests.love_stub") end
|
||||
|
||||
local S = require("tests.harness").suite("skin import picker")
|
||||
local eq = S.eq
|
||||
local check = S.check
|
||||
|
||||
local RomImporter = require("src.import.RomImporter")
|
||||
local TouchSkin = require("src.core.TouchSkin")
|
||||
|
||||
love.system = love.system or {}
|
||||
local saved = {
|
||||
pickFile = love.system.pickFile,
|
||||
getPickedFile = love.system.getPickedFile,
|
||||
getPickError = love.system.getPickError,
|
||||
installArchive = TouchSkin.installArchive,
|
||||
}
|
||||
|
||||
local installed
|
||||
TouchSkin.installArchive = function(name, data)
|
||||
installed = { name = name, data = data }
|
||||
if not data or data == "" then return nil, "empty archive" end
|
||||
return (name:match("([^/\\]+)$") or name):gsub("%.[Zz][Ii][Pp]$", "")
|
||||
end
|
||||
|
||||
local function freshImporter(fields)
|
||||
local imp = RomImporter.new(function() end, { launcher = true })
|
||||
imp.tab = "skins"
|
||||
imp._skins = {}
|
||||
imp._ensureSkins = function(self) return self._skins end
|
||||
for k, v in pairs(fields or {}) do imp[k] = v end
|
||||
return imp
|
||||
end
|
||||
|
||||
-- SKINIMP-01: a picker path installs as a skin, not a mod
|
||||
installed = nil
|
||||
local imp = freshImporter()
|
||||
local tmp = os.tmpname() .. ".zip"
|
||||
local f = assert(io.open(tmp, "wb"))
|
||||
f:write("PK\3\4skin-archive")
|
||||
f:close()
|
||||
imp:_installSkinZip(tmp)
|
||||
os.remove(tmp)
|
||||
check(installed ~= nil, "an absolute picker path reaches TouchSkin.installArchive")
|
||||
eq(installed.data, "PK\3\4skin-archive", "the picked file's bytes are installed")
|
||||
check(imp._skinNotice and imp._skinNotice.ok, "a good pick reports success")
|
||||
|
||||
-- SKINIMP-02: a dropped file still installs, and both paths land on the tab
|
||||
installed = nil
|
||||
imp = freshImporter({ tab = "red" })
|
||||
imp:filedropped({
|
||||
getFilename = function() return "/tmp/dropped_skin.zip" end,
|
||||
getSize = function() return 4 end,
|
||||
open = function() return true end,
|
||||
read = function() return "PKZP" end,
|
||||
close = function() return true end,
|
||||
})
|
||||
check(installed == nil, "a zip dropped off the skins tab is still a mod")
|
||||
installed = nil
|
||||
imp = freshImporter()
|
||||
imp:filedropped({
|
||||
getFilename = function() return "/tmp/dropped_skin.zip" end,
|
||||
getSize = function() return 4 end,
|
||||
open = function() return true end,
|
||||
read = function() return "PKZP" end,
|
||||
close = function() return true end,
|
||||
})
|
||||
eq(installed and installed.name, "/tmp/dropped_skin.zip",
|
||||
"a zip dropped on the skins tab installs as a skin")
|
||||
eq(imp.tab, "skins", "the skin install stays on the skins tab")
|
||||
|
||||
-- SKINIMP-03: the mobile bridge borrows the mod picker kind
|
||||
local requestedKind
|
||||
love.system.pickFile = function(kind)
|
||||
requestedKind = kind
|
||||
return true
|
||||
end
|
||||
love.system.getPickedFile = function() return nil end
|
||||
love.system.getPickError = function() return nil end
|
||||
imp = freshImporter({ nativePicker = true })
|
||||
imp:chooseSkin()
|
||||
eq(requestedKind, "mod", "chooseSkin opens the .zip picker")
|
||||
eq(imp.pickerPendingKind, "skin", "the pending pick is routed to the skins tab")
|
||||
|
||||
-- SKINIMP-04: the picked file comes back through update() as a skin
|
||||
installed = nil
|
||||
love.system.getPickedFile = function()
|
||||
love.system.getPickedFile = function() return nil end
|
||||
return "/picked/from_bridge.zip"
|
||||
end
|
||||
imp._installSkinZip = function(self, source)
|
||||
self.installedSource = source
|
||||
self._skinNotice = { ok = true, text = "Imported from_bridge" }
|
||||
end
|
||||
imp:update(0)
|
||||
eq(imp.installedSource, "/picked/from_bridge.zip",
|
||||
"update() hands the picked path to the skin installer")
|
||||
eq(imp.pickerPendingKind, nil, "the pending kind clears once consumed")
|
||||
|
||||
-- SKINIMP-05: a picker error lands on the skins notice, not the mods one
|
||||
love.system.getPickedFile = function() return nil end
|
||||
love.system.getPickError = function()
|
||||
love.system.getPickError = function() return nil end
|
||||
return "picker refused"
|
||||
end
|
||||
imp = freshImporter({ nativePicker = true, pickerPendingKind = "skin" })
|
||||
imp:update(0)
|
||||
check(imp._skinNotice and not imp._skinNotice.ok,
|
||||
"a failed skin pick reports on the skins tab")
|
||||
eq(imp.modNotice, nil, "a failed skin pick leaves the mods notice alone")
|
||||
|
||||
love.system.pickFile = saved.pickFile
|
||||
love.system.getPickedFile = saved.getPickedFile
|
||||
love.system.getPickError = saved.getPickError
|
||||
TouchSkin.installArchive = saved.installArchive
|
||||
|
||||
S.finish()
|
||||
@@ -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