Menu narration + code-driven testbed

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>
This commit is contained in:
Accessibility Mod
2026-08-01 20:53:29 +02:00
co-authored by Claude Opus 5
parent fe872be683
commit 9945703fb7
9 changed files with 796 additions and 4 deletions
+44
View File
@@ -0,0 +1,44 @@
-- states/load_game.lua
--
-- Entries are save metadata. The screen draws three columns per row: character
-- name, in-game elapsed time, and the real-world save timestamp. We speak all
-- three, in that order -- the character name is what identifies a save, but the
-- timestamps are how you tell two runs of the same character apart.
local capitalize = require("functions.capitalize")
local turnsToTime = require("functions.turnsToTime")
return {
probe = {
fn = "keypressed",
focus = "selectedOption",
list = "metadataList",
focusMayBeNil = true,
},
render = function(entry, index, total)
local parts = {}
parts[#parts + 1] = entry.characterName or "Unnamed"
if entry.turn then
local ok, turnString = pcall(function()
return capitalize(turnsToTime(entry.turn))
end)
if ok and turnString then
parts[#parts + 1] = turnString
end
end
if entry.lastUpdatedTimestamp then
local ok, dateString = pcall(os.date, "%X %x", entry.lastUpdatedTimestamp)
if ok and dateString then
parts[#parts + 1] = dateString
end
end
parts[#parts + 1] = index .. " of " .. total
return table.concat(parts, ", ")
end,
}
+25
View File
@@ -0,0 +1,25 @@
-- states/main_menu.lua
--
-- Options are static (Continue / New game / Load game / Options / Manual /
-- Credits / Exit game); `isEnabled` is recomputed in open(), so "Continue" and
-- "Load game" are unavailable on a fresh install. Announcing that matters --
-- otherwise pressing enter appears to do nothing.
return {
probe = {
fn = "keypressed",
focus = "selectedOption",
list = "optionsList",
focusMayBeNil = true, -- nil until open() picks the first enabled option
},
render = function(entry, index, total)
local text = entry.title or "?"
if entry.isEnabled == false then
text = text .. ", unavailable"
end
return text .. ", " .. index .. " of " .. total
end,
}
+42
View File
@@ -0,0 +1,42 @@
-- 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,
}
+30
View File
@@ -0,0 +1,30 @@
-- states/new_game.lua
--
-- Not a list — a single text field for the character's name. So this uses a
-- custom read() rather than the focus/list probe.
--
-- `inputText` is an upvalue of keypressed (which handles backspace and tab).
-- Note the game only enables textinput here, so our hotkey layer stays out of
-- this state (see hotkeys.lua textEntryStates) and typed brackets reach the game.
return {
-- Spoken when the screen opens, since the on-screen hint window is the only
-- thing explaining what to do.
onOpen = 'Enter your character name. Tab suggests a name, Enter confirms.',
read = function(stateTable, menus)
local inputText = menus.getUpvalue(stateTable.keypressed, "inputText")
if type(inputText) ~= "string" then
return nil, nil
end
if inputText == "" then
return "Name, blank", "blank"
end
-- Key is the text itself, so the driver re-announces on every change
-- (typing, backspace, tab-suggest) but not on keys that change nothing.
return inputText, inputText
end,
}
+22
View File
@@ -0,0 +1,22 @@
-- states/settings_menu.lua
--
-- Same shape as main_menu: a static optionsList with an isEnabled flag.
return {
probe = {
fn = "keypressed",
focus = "selectedOption",
list = "optionsList",
focusMayBeNil = true,
},
render = function(entry, index, total)
local text = entry.title or "?"
if entry.isEnabled == false then
text = text .. ", unavailable"
end
return text .. ", " .. index .. " of " .. total
end,
}