Files
gen1recomp/tests/game3_save_frames_test.lua
T
bryanthaboi 605654a086 CLOSES #2310
2026-09-20 13:21:16 -04:00

72 lines
2.4 KiB
Lua

#!/usr/bin/env luajit
-- pokefirered/src/start_menu.c:971, :628, src/new_menu_helpers.c:648
package.path = "./?.lua;./?/init.lua;" .. package.path
love = require("tests.love_stub")
local failed = 0
local function check(cond, msg)
if cond then
print("[ok] " .. msg)
else
failed = failed + 1
print("[FAIL] " .. msg)
end
end
local Chrome = require("src.ui.game3.chrome")
local FrlgFont = require("src.ui.game3.frlg_font")
local Window = require("src.ui.game3.window")
local SaveMenu = require("src.ui.game3.save_menu")
local calls = {}
local function record(kind)
return function(tx, ty, tw, th)
calls[#calls + 1] = { kind = kind, tx = tx, ty = ty, tw = tw, th = th }
end
end
Chrome.stdFrame = record("user")
Chrome.fixedStdFrame = record("std")
Chrome.dialogueFrame = record("dialogue")
Chrome.userFrame = function(frameType, tx, ty, tw, th)
calls[#calls + 1] = { kind = "user", tx = tx, ty = ty, tw = tw, th = th }
end
FrlgFont.draw = function() end
FrlgFont.measure = function(text) return #tostring(text) * 6 end
Window.cursorPx = function() end
SaveMenu._session = { name = "RED", mapName = "PALLET TOWN" }
SaveMenu.open = true
SaveMenu._phase = "confirm"
SaveMenu.cursor = 1
SaveMenu.draw()
check(#calls == 3, "the save dialog draws three frames (" .. #calls .. ")")
local stats, dialogue, yesno = calls[1], calls[2], calls[3]
check(stats and stats.kind == "std",
"save stats window uses the fixed std frame, not the user frame ("
.. tostring(stats and stats.kind) .. ")")
check(stats and stats.tx == 1 and stats.ty == 1 and stats.tw == 14 and stats.th == 9,
"save stats window sits at sSaveStatsWindowTemplate (1,1,14,9)")
check(dialogue and dialogue.kind == "dialogue",
"save message box uses the dialogue frame (" .. tostring(dialogue and dialogue.kind) .. ")")
check(yesno and yesno.kind == "user",
"YES/NO uses the user-selected std frame (" .. tostring(yesno and yesno.kind) .. ")")
check(yesno and yesno.tx == 21 and yesno.ty == 9 and yesno.tw == 6 and yesno.th == 4,
"YES/NO sits at sYesNo_WindowTemplate (21,9,6,4)")
calls = {}
SaveMenu._phase = "saving"
SaveMenu.draw()
check(#calls == 2 and calls[1].kind == "std" and calls[2].kind == "dialogue",
"the saving phase drops YES/NO and keeps the other two frames")
SaveMenu.open = false
print(("game3_save_frames_test: %s (%d failed)"):format(failed == 0 and "PASS" or "FAIL", failed))
if failed > 0 then os.exit(1) end