Files
gen1recomp/tests/engine/game3_easy_chat_page_test.lua
T
thibautbus 823dd07727 Draw the Easy Chat word page's last two words
The word picker pages eight words at a time and its navigation moves through four rows of two: `row < 3` when moving down, `3 * 2 + col + 1` when stepping up into the previous page. The draw loop rendered three rows, so the seventh and eighth word of every page were selectable -- the cursor sat on them, and pressing A picked them -- while nothing was drawn there. A group's last words could be chosen only blind.

Eight is the cart's own page: easy_chat_2.c scrolls selectWordRowsAbove by four, and easy_chat_3.c's PrintECRowsWin2 prints row * 16 + 96 for each row. The loop now draws four, starting 2 px higher so the fourth row's 14 px of glyphs stop exactly at the bottom of the 78 px frame.

tests/engine/game3_easy_chat_page_test.lua drives the screen with a group larger than one page and checks all eight words reach the font, inside the frame. It reports the two missing words before this change.
2026-09-20 21:22:28 +02:00

70 lines
2.5 KiB
Lua

-- The Easy Chat word picker pages eight words at a time, the way the cart
-- does (easy_chat_2.c scrolls selectWordRowsAbove by 4, two words per row),
-- and its own navigation moves through four rows. The draw loop used to
-- render three, so the last two words of every page were selectable -- the
-- cursor could sit on them -- but never drawn, and a group's 7th and 8th
-- words could not be read at all.
package.path = "./?.lua;./?/init.lua;" .. package.path
local T = require("tests.harness")
local check = T.check
love = require("tests.love_stub")
-- Record what reaches the font instead of drawing it, the same technique
-- tests/engine/gen2_options_menu_translation_test.lua uses.
local drawn = {}
local realFont = require("src.ui.game3.frlg_font")
local stub = setmetatable({}, { __index = realFont })
stub.draw = function(text, x, y) drawn[#drawn + 1] = { text = text, x = x, y = y } end
package.loaded["src.ui.game3.frlg_font"] = stub
local EasyChat = require("src.ui.game3.easy_chat")
local EasyChatData = require("src.core.game3.easy_chat_data")
-- A group with more than eight words, so a full page is drawn.
local group
for _, candidate in pairs(EasyChatData.GROUPS) do
if candidate.words and #candidate.words > 8 then group = candidate break end
end
check(group ~= nil, "the extracted data has a group with more than one page")
EasyChat.open({ type = 0, words = {} })
local st = EasyChat._state
check(st ~= nil, "the screen is open")
st.mode = "WORD"
st.groups = { group }
st.groupCursor = 1
st.wordPage = 0
drawn = {}
EasyChat.draw()
local shown = {}
for _, row in ipairs(drawn) do shown[row.text] = row.y end
local missing = {}
for index = 1, 8 do
local word = group.words[index]
if word and not shown[word.text] then missing[#missing + 1] = word.text end
end
check(#missing == 0, "every word of the page is drawn, got " .. #missing .. " missing")
-- The rows have to stay inside the 78 px frame the screen draws them in.
local frameTop, frameBottom = 76, 76 + 78
local lowest = 0
for index = 1, 8 do
local word = group.words[index]
local y = word and shown[word.text]
if y then
check(y >= frameTop, "row " .. index .. " starts below the frame top")
if y > lowest then lowest = y end
end
end
check(lowest + realFont.GLYPH_HEIGHT <= frameBottom,
"the last row's glyphs stay inside the frame (" .. lowest + realFont.GLYPH_HEIGHT .. " <= " .. frameBottom .. ")")
EasyChat.close(false)
package.loaded["src.ui.game3.frlg_font"] = realFont
T.finish("game3_easy_chat_page_test")