Pulls menu focus narration forward from Phase 4: it was a blocker, since the screen name was spoken but not the selected option, so the game could not be started at all. Game-file footprint unchanged: still one line in main.lua. - menus.lua: descriptor driver supporting both D3 backends (upvalue probe and patched-announce), sharing one render per screen. Probe self-test included. - Descriptors for main_menu, settings_menu, load_game, new_game, narration. - testbed.lua: drives the game by code via love.event.push, so input takes the same path as a human keypress. Coroutine-based, and navigates by READING focus rather than counting keypresses, which drifts when options are disabled. Three bugs found by the testbed and fixed: 1. love.keypressed was still bound to the pre-wrapper states.keypressed. states.setup() captures love[callback] by value and runs before us, and main.lua does not define love.keypressed itself, so wrapping the states table field alone had no effect. Now reassigns love.keypressed/textinput. 2. Focus can move with no keypress: main_menu.mousemoved assigns selectedOption from cursor position, silently overriding selection including at startup. Focus is now polled in the update hook instead of announced only on keypress. 3. Probes sometimes need chaining. narration.keypressed only calls continueNarration(), so the text locals are upvalues of that inner function. Verified: main menu -> new game -> name entry -> intro narration -> gameplay, 8/8 checks passing, including console.print capture and its (x2) fold. Known gap: ingame_dialogue announces 'Game' and reads no dialogue text. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
43 lines
1.4 KiB
Lua
43 lines
1.4 KiB
Lua
-- states/narration.lua
|
|
--
|
|
-- The intro and interlude screens. Text is revealed one line at a time: pressing
|
|
-- enter advances `currentLoadedLine` within `displayData[currentPage]`, and rolls
|
|
-- over to the next page at the end.
|
|
--
|
|
-- Not a list menu, so this uses a custom read(). The "focus" is the most recently
|
|
-- revealed line, keyed by page:line so each newly revealed line is announced once.
|
|
|
|
return {
|
|
read = function(stateTable, menus)
|
|
-- Two-level probe. narration.keypressed does not touch these locals
|
|
-- directly -- it just calls continueNarration(), so they are upvalues of
|
|
-- THAT function. We reach continueNarration as an upvalue of keypressed,
|
|
-- then read through it.
|
|
local probeFn = menus.getUpvalue(stateTable.keypressed, "continueNarration")
|
|
|
|
if type(probeFn) ~= "function" then
|
|
return nil, nil
|
|
end
|
|
|
|
local displayData = menus.getUpvalue(probeFn, "displayData")
|
|
local page = menus.getUpvalue(probeFn, "currentPage")
|
|
local line = menus.getUpvalue(probeFn, "currentLoadedLine")
|
|
|
|
if type(displayData) ~= "table" or type(page) ~= "number" or type(line) ~= "number" then
|
|
return nil, nil
|
|
end
|
|
|
|
local pageData = displayData[page]
|
|
if type(pageData) ~= "table" then
|
|
return nil, nil
|
|
end
|
|
|
|
local entry = pageData[line]
|
|
if type(entry) ~= "table" or not entry.text then
|
|
return nil, nil
|
|
end
|
|
|
|
return entry.text, page .. ":" .. line
|
|
end,
|
|
}
|